Coder Social home page Coder Social logo

rapidfacture / rf-log Goto Github PK

View Code? Open in Web Editor NEW
0.0 5.0 0.0 110 KB

Simple NodeJS logging lib - no dependencys. Colored console.log or log to files. Default logging functions: info, success, waring, error. Custom functions can be added. Display prefix and time for the logs.

JavaScript 100.00%

rf-log's Introduction

rf-log

Simple and Ready logging lib - no dependencys.

npm install rf-log

Example 1

log-simple example

let log = require("rf-log").start("[SYSTEM-XY]");

log.success("Use the default functions here.");
log.info("The mainPrefix before is usefull - tells who loggs");
log.warning("Optionals use 'time' option");
log.error("short logs are nice - icons are shorter than words like 'error'");
log.critical("same as 'error', but also throws an Error and stops your app");

Example 2

log-simple example

var log = require("rf-log");

log.info('simple log');
log.withTime.success('log with time');
log.options.mainPrefix = '[SYSTEM-XY]';
log.success('log with prefix, several args', {'hello': 'world'});

Second prefix for libs

This helps to find the origin of a message faster

log-simple example

// NOTE: we assume this is a lib, and rf-log was already started in another file with the mainPrefix '[yourProcess]'


// start the logger and tell it the name of your lib
var log = require('rf-log').prefix('[DB-module]')


// no need mention `DB Module` again
log.success('connected')
log.info('receiving data')
log.error('connection refusing')

Log to a file

var log = require(rf-log);

log.options.logFilePath = __dirname +  "/log.txt";
log.success("this works", {"hello": "world"});

Options

var options = require(rf-log).options;
// the object is in every `require(rf-log)` present and looks like:
{
   mainPrefix: '',
   time: false,
   timeLocale: 'en-US',
   timeOptions: { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric' },
   logFilePath: '',
   carriageReturn: true
}

Docs of time options

The lib uses Date.toLocaleString to create a time log. https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date

Docs of color options

http://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color

How the lib works - creation of the strings

Each string is built in the following pattern:

prefix + mainPrefix + secondPrefix + time + argumentsToLog

Development and Testing

npm install

To be able to run grunt-eslint. Run a test script and eslint with:

npm test

Legal Issues

  • Licenese: MIT
  • Author: Felix Furtmayr

rf-log's People

Contributors

felixfurtmayr avatar rf-alex avatar

Watchers

Uli Köhler avatar James Cloos avatar Marc Itzenthaler avatar Regina Galambos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.