1.0.14 • Published 8 years ago

log-me v1.0.14

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

log-me

Codeship Status for Maumasi/log-me log-me is a simple logging tool you can use to log events to a console. You can think of this as a more powerful console.log() which gives more robust information about the events happening in the core functionality.

Important:

This package was written in node v6.7.0

Notes:

When reviewing this package documentation we're going to stage a couple basic outlines:


Install

To install as a dependency:

$ cd ROOT/
$ npm i --save log-me

Usage

Code examples

At the top of a file you are going to use an instance of log-me set to a const:

const log = require('log-me');

When using your new tool, log.print, there are a few parameters to play with: Parameter position: 1. error | required: Capture an error stack trace commonly represented as err in node.

  1. filePath | optional: While this is an optional parameter you should always set this to __filename whenever you call a log-me instance or else it will default to log-me's module file path.

  2. customMessage | optional: This is a string value that will be used as the log message header.

  3. customDescription | optional: This is a string value. The description should be used if the purpose for the log is more complex then can be described in a few words using the customMessage parameter.

  4. reportLevel | optional: This takes a numeric value of 0, 1, or 2.

    • This is used against an array, ['Info', 'Warning', 'Error'].
    • By default this is set to index 0'Info', but if an error is passed in at parameter 1 and the error has a stack trace then this will automatically be change to index 2'Error'.
    • Index 1'Warning' will only be used if entered as so.
// extend the `log-me` module to this file
const log = require('log-me');


// parameters
log.print(err, filePath = __filename, customMessage = 'none', customDescription = 'none', reportLevel = 0);


// only log the stack trace
danceMonkeyDance(err, dance) {
  // ... some code ...
  if (err) {
    log.print(err, __filename);
  }
}


// if there's no error to pass in but you want to log an event just set the first parameter to `null`
log.print(null, __filename,
  'Header for custom log message',
  'A more descriptive explanation for the reason I put a log here.');


// change the reportLevel to index of 'Warning'
log.print(null, __filename,
  'An unexpected event that could be a problem later',
  'A well deserved explanation as to what you suspect triggered this `Warning` log.',
  1 // <-------- index of `Warning` status
);

DEBUG mode

The best way to do this is to set DEBUG=true in the terminal. If you have a server script that runs your App at the ROOT/ directory level then you call just past in the following commands, assuming that you server script is called server.js.

$ cd ROOT/
$ DEBUG=true node server.js

Then of course, to exit DEBUG mode you'll have to stop the server.

$ cd ROOT/
$ ^C

Note: To enter ^C you just to press control and c at the same time.

Example output

An example log output to the terminal would look like this:

Log Report: Info
created at: Wed Oct 12 2016 21:42:28 GMT-0400 (EDT)
report type: Info
custom message: Server Active
custom description: Server running on port 3000
file path: ROOT/server.js
stack trace: null

The only exception to this example out put is that it would actually be colored text for better contrast

Version bumper

This utility tool also features the version bumper, that will output to console the new version depending on 2 parameters: version and type. version is just a number (ex. 10.3.105), and type may be one of three: major, minor, or patch. If you are unfamiliar with semantic versioning, take a look at this site. You will still need to have this piece of code in your file:

const log = require('log-me');

You will be able to use version bumper like so:

log.bump('10.5.13', 'minor');

Having these parameters, console will print out this:

New version number is: 10.6.0
1.0.14

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago