@zapperadmin/node-log

2.1.0 • Public • Published

node-log

A simple logger for node, that logs to the console, with the purpose of being consumed by the Docker logging driver

Usage

Set log level

Logging level can be set globally:

import Logger from '@zapperadmin/node-log'

Logger.logLevel('error')

Logger.info('this wont show')
Logger.fatal('this will show')

Logging functions that are available are:
trace
debug
info
warn
error
fatal
ok

Each function takes a parameter of type string or ILogMessage:

Property Type Required
message string yes
data any no
error Error no
import Logger from '@zapperadmin/node-log'

const logger = new Logger()

const myFunction = () => {
	try {
		const x = 10
		x = 20
	} catch (e) {
		logger.error({
			message: 'An error occurred',
			error: e,
			data: {
				foo: 'bar'
			}
		})
	}
}

myFunction()

Output

Logs are formatted according to Zapper's single line format in order to accommodate current reporting tools:

[Timestamp][LogLevel][LogProvider][MachineName][ProcessName][AssemblyName][MethodName][LineNumber][Message][References][EscapedException]

Example

With stacktrace

$ [2018-09-07T11:01:07.917Z][error][zappernodelogger][Keiran-pc][node][][myFunction][12][An error occurred][{"foo":"bar"}][TypeError: Assignment to constant variable.      at myFunction (D:\Zapper\Source\node-log\tests\LoggerTests.ts:9:15)      at Object.<anonymous>.test (D:\Zapper\Source\node-log\tests\LoggerTests.ts:21:5)      at Object.asyncJestTest (D:\Zapper\Source\node-log\node_modules\jest-jasmine2\build\jasmine_async.js:108:37)      at resolve (D:\Zapper\Source\node-log\node_modules\jest-jasmine2\build\queue_runner.js:56:12)      at new Promise (<anonymous>)      at mapper (D:\Zapper\Source\node-log\node_modules\jest-jasmine2\build\queue_runner.js:43:19)      at promise.then (D:\Zapper\Source\node-log\node_modules\jest-jasmine2\build\queue_runner.js:87:41)
  at <anonymous>      at process._tickCallback (internal/process/next_tick.js:188:7)]

Plain message

[2018-09-10T07:25:18.697Z][info][zappernodelogger][Keiran-pc][node][][myFunction][8][starting tests][][]

Readme

Keywords

none

Package Sidebar

Install

npm i @zapperadmin/node-log

Weekly Downloads

0

Version

2.1.0

License

MIT

Unpacked Size

31.4 kB

Total Files

43

Last publish

Collaborators

  • zapperadmin