Gathering detailed insights and metrics for loggis
Gathering detailed insights and metrics for loggis
Gathering detailed insights and metrics for loggis
Gathering detailed insights and metrics for loggis
npm install loggis
Typescript
Module System
Min. Node Version
Node Version
NPM Version
73.9
Supply Chain
99.4
Quality
76.1
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
31,094
Last Day
30
Last Week
159
Last Month
611
Last Year
5,016
4 Stars
79 Commits
2 Forks
2 Watching
7 Branches
2 Contributors
Minified
Minified + Gzipped
Latest Version
3.0.1
Package Id
loggis@3.0.1
Unpacked Size
83.86 kB
Size
20.54 kB
File Count
45
NPM Version
8.15.0
Node Version
16.17.0
Cumulative downloads
Total Downloads
Last day
11.1%
30
Compared to previous day
Last week
-4.2%
159
Compared to previous week
Last month
107.8%
611
Compared to previous month
Last year
36.7%
5,016
Compared to previous year
A simple, lightweight, console logger for Node.JS.
A perfect choice for Kubernetes, Docker, and other systems that collect logs directly from stdout.
1$ npm install loggis
The logger can be used right out of the box, i.e. it does not require any configuration by default. The default settings are:
1// /app/test_log.js 2const logger = require('loggis'); 3 4const logFn = () => { 5 logger.info('its simple'); 6 logger.error('this', ['will', 'be'], { serialized: { into: 'a string' } }); 7 8 // won't be printed since the default loglevel is info 9 logger.trace('trace info'); 10}; 11 12logFn(); 13// [2022-09-03T08:17:26.549Z] [INFO] [123] [default] [/app/test_log.js||logFn:4] its simple 14// [2022-09-03T08:17:26.554Z] [ERROR] [123] [default] [/app/test_log.js||logFn:5] this ["will","be"] {"serialized":{"into":"a string"}} 15
The default configuration can be set either through the configure
method or the environment variables.
Each logger instance can be configured individually by setting an instance properties like level
, colorize
, etc.
The default configuration can be set through the environment variables.
Name | Type | Default value | Description |
---|---|---|---|
LOG_LEVEL | String | info | The default logging level |
LOG_JSON | Boolean | false | Turns on/off JSON output |
LOG_COLORS | Boolean | false | Turns on/off the colorized output |
The default configuration can be passed to the configure
method.
It accepts the following parameters:
error
, warn
, info
, debug
, and trace
The same parameters can be used for an individual configuration of a logger.
It's safe to pass any kind of arguments to the log functions, including Express requests, Sequelize models, etc. The logger automatically detects circular structures and replaces them by string references. The reference is a path within an object.
1const logger = require('loggis'); 2 3const a = { a: 1 }; 4a.b = a; // circular reference 5a.c = [1, { d: 2, e: { f: 'abc' } }] 6a.g = a.c[1].e; // circular reference 7 8logger.info(a); 9// ...{"a":1,"b":"[REF => .]","c":[1,{"d":2,"e":{"f":"abc"}}],"g":"[REF => c[1].e]"}
The formatter function accepts an object with the following properties:
It might be convenient to set the default message format for a particular application.
For example, if you want to:
You can do it like this:
1// ./src/logger/index.js 2const loggis = require('loggis'); 3 4const customFormatter = ({ args, level, logger }) => JSON.stringify({ 5 date: new Date(), 6 module: module.parent.filename.replace(process.cwd(), ''), 7 category: logger.category, 8 level, 9 data: args, // be careful, it might crash if data is not compatible with JSON.stringify 10}); 11 12loggis.configure({ format: customFormatter }); 13 14module.exports = loggis; 15 16// ./src/app.js 17const logger = require('./logger'); 18 19const log = logger.getLogger('MY_APP'); 20 21log.info('the configuration is =>', { 22 level: logger.loglevel, 23 color: logger.colorize, 24 json: logger.json, 25}); 26 27// ./index.js 28require('./src/app'); 29 30// {"date":"2022-09-03T08:17:26.549Z","module":"/app.js","category":"MY_APP","level":"info","data":["the configuration is =>",{"level":"info","color":false,"json":false}]}
1const logger = require('loggis') 2 3const log = logger.configure({ loglevel: 'debug' }).getLogger('MY_APP'); 4 5log.error('easy to log error') 6log.debug('easy to log debug'); 7log.trace('will not be printed, since the log level is DEBUG'); 8// [2022-09-03T08:17:26.549Z] [ERROR] [123] [MY_APP] [/app/test_log.js||-:5] easy to log error 9// [2022-09-03T08:17:26.554Z] [DEBUG] [123] [MY_APP] [/app/test_log.js||-:6] easy to log debug 10
1const logger = require('loggis'); 2 3logger.configure({ json: true }); 4 5logger.info('user info =>', { id: 1, name: 'John', email: 'mail@g.co' }); 6 7// {"date":"2022-09-03T08:17:26.549Z","level":"info","pid":123,"category":"json","filename":"/app/test_log.js","function":"-","line":5,"data":["user info =>",{"id":1,"name":"John","email":"mail@g.co"}]} 8
1const logger = require('loggis'); 2 3logger.configure({ loglevel: 'warn', colorize: true }); 4 5const logLine = logger.getLogger('line'); // the default configuration will be applied 6const logJson = logger.getLogger('json'); 7 8// configure an instance 9logJson.loglevel = 'trace'; 10logJson.json = true; 11logJson.colorize = false; 12 13logLine.info('the configuration is =>', { 14 level: logLine.loglevel, 15 color: logLine.colorize, 16 json: logLine.json, 17}); 18 19logJson.trace('the configuration is =>', { 20 level: logJson.loglevel, 21 color: logJson.colorize, 22 json: logJson.json, 23}); 24 25 26// [2022-09-03T08:17:26.549Z] [WARN] [123] [line] [/app/test_log.js||-:13] the configuration is => {"level":"warn","color":true,"json":false} 27// {"date":"2022-09-03T08:17:26.554Z","level":"trace","pid":123,"category":"json","filename":"/app/test_log.js","function":"-","line":19,"data":["the configuration is =>",{"level":"trace","color":false,"json":true}]}
1import logger from 'loggis'; 2 3const log = logger.getLogger('MY_APP');
1import { getLogger } from 'loggis'; 2 3const log = getLogger('MY_APP')
Data processing includes two stages:
The parsing of each argument looks like this:
This way it's possible to format any element at any level of nesting.
An element for which one or more formatting rules are specified is called a primitive
.
The formatting rules for primitives are set by an instance of the Primitives
class, the add
method.
This method takes two arguments:
The add
method returns the instance itself, so the method can be chained.
The Primitives
class is available in the formatters
property of the logger.
An instance of the Primitives
class can be passed to the configure
method of the logger as the primitives
parameter.
Example:
1const logger = require('loggis'); 2 3const primitives = new logger.formatters.Primitives() 4 .add( 5 (item) => typeof item === 'number', // for any number 6 (item) => item.toFixed(2), // apply this function 7 ); 8 9logger.configure({ primitives }); 10 11logger.info(10.987654, '123.1589', { float: 1.5499, int: 1, str: '9.98765' }); 12// ... 10.99 123.1589 {"float":"1.55","int":"1.00","str":"9.98765"}
For convenience, the Primitives
class has two static methods - typeof
and instanceof
with the following definitions:
1 interface Cls<T, A extends any[] = any[]> extends Function { new(...args: A): T; } 2 3 static typeof<T = any>(type: string): ((data: T) => boolean); 4 static instanceof<T, V = any>(cls: Cls<T>): ((data: V) => boolean);
1primitives 2 .add(Primitives.typeof('function'), (data) => `<Function ${data.name || 'anonymous'}>`) 3 .add(Primitives.instanceof(Date), (date) => date.toISOString()) 4 .add(Primitives.instanceof(Buffer), (data) => data.toString()) 5 .add(Primitives.instanceof(Promise), () => '<Promise>') 6 .add(Primitives.instanceof(Error), (error) => Object 7 .getOwnPropertyNames(error) 8 .reduce((acc, prop) => `${acc}\n${prop}: ${error[prop]}`, '')); 9
1const logger = require('loggis'); 2const { Primitives } = logger.formatters; 3 4const isObject = (obj) => typeof obj === 'object' && obj !== null && !Array.isArray(obj); 5const hide = (obj, prop) => (Object.hasOwn(obj, prop) ? ({ ...obj, [prop]: '***' }) : obj); 6 7const primitives = new Primitives() 8 .add(isObject, (obj) => hide(obj, 'password')) 9 .add(isObject, (obj) => hide(obj, 'card_number')) 10 .add(isObject, (obj) => hide(obj, 'card_cvv')); 11 12logger.configure({ primitives }); 13 14logger.info({ user: { id: 1, name: 'John', password: 'secret', card: { card_cvv: 321, card_number: 4111111111111111 } } }); 15// ... {"user":{"id":1,"name":"John","password":"***","card":{"card_cvv":"***","card_number":"***"}}}
1const { Model } = require('sequelize'); 2const logger = require('loggis'); 3 4const primitives = new logger.formatters.Primitives() 5 .add(Primitives.instanceof(Model), (model) => model.toJSON())
The elements to be printed are specified by calling the add
method of an instance of the Logline
class.
The add
method accepts a Message
instance and returns any type of data.
The Message
instance has the following properties:
json
option of the loggerThe Logline
class is available in the formatters
property of the logger.
The join
method of the logline instance defines a separator that is used while joining all the logline elements. It does not work for JSON format.
1const logger = require('loggis'); 2const { Logline } = logger.formatters; 3 4// --- Simplest format --- 5const logline = new Logline().add(message => message.text); 6logger.configure({ logline }).info(1, [2, 3], { 4: 5 }); // 1 [2,3] {"4":5} 7 8// --- Static text --- 9const logline = new Logline() 10 .add(() => '[static_text]') 11 .add(message => `[${message.text}]`); 12logger.configure({ logline }).info('log message'); // [static_text] [log message] 13 14// --- JOIN --- 15const logline = new Logline() 16 .add(message => message.date.valueOf()) 17 .add(message => message.level.toUpperCase()) 18 .add(message => message.pid) 19 .add(message => message.text) 20 .join(' | '); 21logger.configure({ logline }).info('log message'); // 1662193046549 | INFO | 123 | log message 22 23// --- JSON format --- 24const logline = new Logline() 25 .add(message => ({ date: message.date })) 26 .add(message => ({ message: message.text })); 27logger.configure({ json: true, logline }).info('user =>', { id: 1, name: 'John' }); // {"date":"2022-09-03T08:17:26.549Z","message":["user =>",{"id":1,"name":"John"}]}
1const wrap = data => `[${data}]`; 2 3logline 4 .add(message => wrap(message.date.toISOString())) 5 .add(message => wrap(message.level.toUpperCase())) 6 .add(message => wrap(message.pid)) 7 .add(message => wrap(message.category)) 8 .add(message => wrap(`${message.fileName}||${message.functionName || '-'}:${message.lineNumber || -1}`)) 9 .add(message => message.text); 10
1loglineJson 2 .add(message => ({ date: message.date.toISOString() })) 3 .add(message => ({ level: message.level })) 4 .add(message => ({ pid: message.pid })) 5 .add(message => ({ category: message.category })) 6 .add(message => ({ filename: message.fileName })) 7 .add(message => ({ function: message.functionName || '-' })) 8 .add(message => ({ line: message.lineNumber || -1 })) 9 .add(message => ({ data: message.text }));
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/5 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More@loggists/logger
The best solution for logging in React applications.
loggish
Universal logger is a library designed for collect and process logs in apps
@loggists/event-tracker
The best solution for event tracking in React applications.
loggisch
Tiny JS logging library for NodeJS and the browser (ES6/UMD).