This package has been deprecated

Author message:

Outdated and no longer maintained

schlog
TypeScript icon, indicating that this package has built-in type declarations

0.4.2 • Public • Published

Schlog

Simple Node.js logger

GitHub npm Travis (.com)

Installation

Install using yarn:

yarn add schlog

Or npm:

npm install schlog

Basic usage

const logger = require("schlog").Logger
 
logger.setLogLevel(logger.getLogLevelByName("warn"))
// or set LOG_LEVEL environment variable to any of the default levels
// (by name or number)
// defaults to info (2)
 
logger.warn("Test")
// [21:52:58] WARN Test
 
logger.info("Test")
// nothing (since level is set to warn)

Default log levels: error, warn, info, debug or 0-4

error and warn will output to stderr while info and debug will output to stdout.

Log functions return the same thing they output to the console. Either the log line or nothing if the log level is set higher than the level called.

Example customization

const chalk = require("chalk")
const schlog = require("schlog")
 
const logger = schlog.Logger
const LogLevel = schlog.LogLevel
const LogScope = schlog.LogScope
 
const logLevel = new LogLevel("fancy", chalk.magenta.underline, 4, LogScope.STDOUT)
logger.setLogLevel(logLevel)
// will only output with levels priorities 4 or lower
 
logger.setTimeFormat("MMMM Do YYYY, h:mm:ss a")
logger.log(logLevel, "Test")
// [March 21st 2019, 11:53:11 pm] FANCY Test
 
logger.setPrintTimestamps(false)
logger.log(logLevel, "Test")
// FANCY Test
 
logger.setPrintJson(true)
logger.log(logLevel, "Test")
// {"level":{"name":"fancy","priority":4,"scope":"stdout"},"message":"Test"}

Readme

Keywords

none

Package Sidebar

Install

npm i schlog

Weekly Downloads

1

Version

0.4.2

License

MIT

Unpacked Size

231 kB

Total Files

13

Last publish

Collaborators

  • sweepyoface