1.2.1 • Published 10 years ago

tvc.logger v1.2.1

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

tvc.logger

Logging utility for the MEAN stack, logs out to console, file or MongoDB using mongoose.

What is this repository for?

  • Logging of any event through simple methods
  • Current Version : 1.2.0

Installation

$ npm install tvc.logger

Usage

// Require the module
var log = require("tvc.logger");

Update v1.2.0

Added OOP method

var logger = require("tvc.logger/oop");
var log = new logger();
var log2 = new logger();

// Gets independent configuration options
log.config({"tsFormat": "HH:mm:ss.SSS"});
log2.config({"tsFormat": "MM-DD HH:mm:ss"});

Logging Methods

/**
 * Standard log message
 * @param _message {string|object} - Log message (will stringify objects)
 * @param _function {string=} - Function name (can be used for passing any string for logging purposes)
 * @param _console {boolean=} [_console=true] - Output to console
 * @param _status {number=} - HTTP status code
 */
log.info(_message, _function, _console, _status);

/**
 * Custom log message
 * @param _type {string} - Type of log entry
 * @param _message {string|object} - Log message (will stringify objects)
 * @param _function {string=} - Function name (can be used for passing any string for logging purposes)
 * @param _console {boolean=} [_console=true] - Output to console
 * @param _status {number=} - HTTP status code
 */
log.custom(_type, _message, _function, _console, _status);

File Logging

File logging will attempt to create a directory to contain log files and will name files using MomentJS notation.

// Basic
log.config({"toFile": true});
// CSV
log.config({"toFile": true, "logFormat": "csv"});
// TSV
log.config({"toFile": true, "logFormat": "csv", "extension": "tsv", "logSeparator": "\t"});
// JSON
log.config({"toFile": true, "logFormat": "json"});

DB Logging

// Default model name of 'tvc.logs.prime'
log.config({"toMongo": true});
// Change the model name to anything you'd like
log.config({"toMongo": true, "logModel": "my.log"});

Configuration

General & Console

ParameterData TypeDefaultDescriptionValid Parameters
consolebooleantrueOutput log entries to consoletrue : false
logSeparatorstring" - "Parameter separator for file / console logging:any
paddingnumber8Used to make log types even for readability:any
tsFormatstringtimestampMomentJS timestamp:any

File Logging

ParameterData TypeDefaultDescriptionValid Parameters
toFilebooleanfalseTo write log entries to a filetrue : false
extensionstring"txt"File extension to use when creating file:any
logFormatstring"text"Logfile formattext : json : csv
logSeparatorstring","logFormat "csv" and not specifiying a character:any
tsFormatstringtimestampWhen using logFormat "csv":any
customPathstring"logs"Define custom log path relative to application path:any
filenameFormatstring"YYYY-MM-DD"MomentJS full date:any

Database Logging

To use database logging, an active mongoose connection must be established

ParameterData TypeDefaultDescriptionValid Parameters
toMongobooleanfalseTo write log entries to databasetrue : false
logModelstring"tvc.logs.prime"Collection name:any

Examples

log.debug('Debug message');
// 2015-07-19 15:07:14.569 - DEBUG    - Debug Message
log.info("Info message");
// 2015-07-19 15:07:14.567 - INFO     - Info Message
log.warning('Warning message');
// 2015-07-19 15:07:14.570 - WARNING  - Warning message
log.error('Error message');
// 2015-07-19 15:07:14.570 - ERROR    - Error message
log.critical('Critical message');
// 2015-07-19 15:07:14.570 - CRITICAL - Critical message
log.fatal('Fatal message');
// 2015-07-19 15:07:14.571 - FATAL    - Fatal message
log.custom('custom', 'Custom message');
// 2015-07-19 15:07:14.571 - CUSTOM   - Custom message
1.2.1

10 years ago

1.2.0

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago