Installations
npm install log
Developer Guide
Typescript
No
Module System
N/A
Min. Node Version
>=0.12
Node Version
20.17.0
NPM Version
10.8.2
Score
89.6
Supply Chain
98.1
Quality
76.3
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
medikoo
Download Statistics
Total Downloads
220,059,982
Last Day
142,261
Last Week
1,013,374
Last Month
4,561,653
Last Year
57,251,877
GitHub Statistics
43 Stars
291 Commits
1 Forks
4 Watching
2 Branches
4 Contributors
Package Meta Information
Latest Version
6.3.2
Package Id
log@6.3.2
Unpacked Size
36.66 kB
Size
12.31 kB
File Count
24
NPM Version
10.8.2
Node Version
20.17.0
Publised On
24 Sept 2024
Total Downloads
Cumulative downloads
Total Downloads
220,059,982
Last day
-30.8%
142,261
Compared to previous day
Last week
-8.4%
1,013,374
Compared to previous week
Last month
-6.7%
4,561,653
Compared to previous month
Last year
3.9%
57,251,877
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
log
Universal logging utility
Configurable, environment and presentation agnostic, with log levels and namespacing (debug style) support
Usage
1. Write application/library logs
1// Default logger (writes at 'info' level) 2const log = require("log"); 3 4// Log 'info' level message: 5log.info("some info message %s", "injected string"); 6 7// Get namespaced logger (debug lib style) 8const myLibLog = log.get("my-lib"); 9 10// Log 'info' level message in context of 'my-lib' namespace: 11myLibLog.info("some info message in 'my-lib' namespace context"); 12 13// Namespaces can be further nested 14const myLibFuncLog = log.get("func"); 15 16// Log 'info' level message in context of 'my-lib:func' namespace: 17myLibFuncLog.info("some info message in 'my-lib:func' namespace context"); 18 19// Log 'error' level message in context of 'my-lib:func' namespace: 20myLibFuncLog.error("some error message"); 21 22// log output can be dynamically enabled/disabled during runtime 23const { restore } = myLibFuncLog.error.disable(); 24myLibFuncLog.error("error message not really logged"); 25// Restore previous logs visibiity state 26restore(); 27myLibFuncLog.error("error message to be logged");
2. Initialize log writer in main (starting) process module
e.g. if target is Node.js, then install log-node
, and at the top of main module initialize it
1require("log-node")();
Available log levels
Mirror of applicable syslog levels (in severity order):
debug
- debugging information (hidden by default)info
- a purely informational message (hidden by default)notice
- condition normal, but significantwarning
(also aliased aswarn
) - condition warningerror
- condition error - to notify of errors accompanied with recovery mechanism (hence reported as log and not as uncaught exception)
Note: critical
, alert
, emergency
are not exposed as seem to not serve a use case in context of JS applications,
such errors should be exposed as typical exceptions
Output message formatting
log
doesn't force any specific arguments handling. Still it is recommended to assume printf-like message
format, as all currently available writers are setup to support it. Placeholders support reflects one implemented in Node.js format util
Excerpt from Node.js documentation:
The first argument is a string containing zero or more placeholder tokens. Each placeholder token is replaced with the converted value from the corresponding argument. Supported placeholders are:
%s
- String.%d
- Number (integer or floating point value).%i
- Integer.%f
- Floating point value.%j
- JSON. Replaced with the string '[Circular]' if the argument contains circular references.%o
- Object. A string representation of an object with generic JavaScript object formatting. Similar to util.inspect() with options { showHidden: true, depth: 4, showProxy: true }. This will show the full object including non-enumerable symbols and properties.%O
- Object. A string representation of an object with generic JavaScript object formatting. Similar to util.inspect() without options. This will show the full object not including non-enumerable symbols and properties.%%
- single percent sign ('%'). This does not consume an argument.
Note to log writer configuration developers: For cross-env compatibility it is advised to base implementation on sprintf-kit
Enabling log writing
log
on its own doesn't write anything to the console or any other means (it just emits events to be consumed by preloaded log writers).
To have logs written, the pre-chosen log writer needs to be initialized in the main (starting) module of a process.
List of available log writers
log-node
- For typical Node.js processeslog-aws-lambda
- For AWS lambda environment
Note: if some writer is missing, propose a PR
Logs Visibility
Default visibility depends on the enviroment (see chosen log writer for more information), and in most cases is setup through the following environment variables:
LOG_LEVEL
(defaults to notice
) Lowest log level from which (upwards) all logs will be exposed.
LOG_DEBUG
Eventual list of namespaces to expose at levels below LOG_LEVEL
threshold
List is comma separated as e.g. foo,-foo:bar
(expose all foo
but not foo:bar
).
It follows convention configured within debug. To ease eventual migration from debug, configuration fallbacks to DEBUG
env var if LOG_DEBUG
is not present.
Timestamps logging
When following env var is set writers are recommended to expose timestamps aside each log message
LOG_TIME
rel
(default) - Logs time elapsed since logger initializationabs
- Logs absolute time in ISO 8601 format
Tests
$ npm test
Project cross-browser compatibility supported by:
Security contact information
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
17 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: ISC License: LICENSE:0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/integrate.yml:1
- Warn: no topLevel permission defined: .github/workflows/publish.yml:1
- Warn: no topLevel permission defined: .github/workflows/validate.yml:1
- Info: no jobLevel write permissions found
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
5.2
/10
Last Scanned on 2024-12-16
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