npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tvc.logger

v1.2.1

Published

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

Downloads

7

Readme

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

| Parameter | Data Type | Default | Description | Valid Parameters | | :-------- | :-------- | :------ | :---------- | :--------------- | | console | boolean | true | Output log entries to console | true : false | | logSeparator | string | " - " | Parameter separator for file / console logging | :any | | padding | number | 8 | Used to make log types even for readability | :any | | tsFormat | string | timestamp | MomentJS timestamp | :any |

File Logging

| Parameter | Data Type | Default | Description | Valid Parameters | | :-------- | :-------- | :------ | :---------- | :--------------- | | toFile | boolean | false | To write log entries to a file | true : false | | extension | string | "txt" | File extension to use when creating file | :any | | logFormat | string | "text" | Logfile format | text : json : csv | | logSeparator | string | "," | logFormat "csv" and not specifiying a character | :any | | tsFormat | string | timestamp | When using logFormat "csv" | :any | | customPath | string | "logs" | Define custom log path relative to application path | :any | | filenameFormat | string | "YYYY-MM-DD" | MomentJS full date | :any |

Database Logging

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

| Parameter | Data Type | Default | Description | Valid Parameters | | :-------- | :-------- | :------ | :---------- | :--------------- | | toMongo | boolean | false | To write log entries to database | true : false | | logModel | string | "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