Installations
npm install loglevel-prefix
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
6.10.0
NPM Version
5.0.1
Score
68.9
Supply Chain
98.7
Quality
75.7
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
kutuluk
Download Statistics
Total Downloads
10,718
Last Day
1
Last Week
20
Last Month
64
Last Year
404
GitHub Statistics
64 Stars
31 Commits
12 Forks
1 Watching
8 Branches
2 Contributors
Bundle Size
1.30 kB
Minified
676.00 B
Minified + Gzipped
Package Meta Information
Latest Version
0.3.1
Package Id
loglevel-prefix@0.3.1
Size
4.20 kB
NPM Version
5.0.1
Node Version
6.10.0
Total Downloads
Cumulative downloads
Total Downloads
10,718
Last day
-80%
1
Compared to previous day
Last week
66.7%
20
Compared to previous week
Last month
3,100%
64
Compared to previous month
Last year
-24.3%
404
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
loglevel-prefix
Minimal lightweight (0.9KB minified and gzipped) plugin for loglevel message prefixing
Installation
1npm install loglevel-prefix --save
API
1prefix(log[, options]);
log - root logger, imported from loglevel package
options - configuration object
1default_options = { 2 template: '[%t] %l:', 3 timestampFormatter: date => date.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1'), 4 levelFormatter: level => level.toUpperCase(), 5 nameFormatter: name => name || 'root' 6}
Plugin formats the prefix using template option as a printf-like format.
The template is a string containing zero or more placeholder tokens. Each placeholder token is replaced with the value from loglevel messages parameters. Supported placeholders are:
%t - Timestamp of message.
%l - Level of message.
%n - Name of logger.
The timestampFormatter, levelFormatter and nameFormatter is a functions for formatting corresponding values
Base usage
Browser directly
Download production version and copy to your project folder
1<script src="loglevel.min.js"></script> 2<script src="loglevel-prefix.min.js"></script> 3 4<script> 5 prefix(log); 6 log.warn('prefixed message'); 7</script>
Output
[12:53:46] WARN: prefixed message
ES6
1 2import log from 'loglevel'; 3import prefix from 'loglevel-prefix'; 4 5prefix(log); 6log.warn('prefixed message');
CommonJS
1 2var log = require('loglevel'); 3var prefix = require('loglevel-prefix'); 4prefix(log); 5 6// or 7// var log = require('loglevel-prefix')(require('loglevel')); 8 9log.warn('prefixed message');
AMD
1define(['loglevel', 'loglevel-prefix'], function(log, prefix) { 2 prefix(log); 3 log.warn('prefixed message'); 4});
Custom options
1import log from 'loglevel'; 2import prefix from 'loglevel-prefix'; 3 4prefix(log, { 5 template: '[%t] %l (%n) static text:', 6 timestampFormatter: date => date.toISOString(), 7 levelFormatter: level => level.charAt(0).toUpperCase() + level.substr(1), 8 nameFormatter: name => name || 'global' 9}); 10 11log.warn('prefixed message');
Output
[2017-05-29T16:53:46.000Z] Warn (global) static text: prefixed message
Example
1// moduleA.js 2import log from 'loglevel'; 3 4export default function () { 5 log.warn('message from moduleA'); 6}
1// moduleB.js 2import log from 'loglevel'; 3 4const logger = log.getLogger('moduleB'); 5 6export default function () { 7 logger.warn('message from moduleB'); 8}
1// moduleC.js 2import log from 'loglevel'; 3 4export default function () { 5 const logger = log.getLogger('moduleC'); 6 logger.warn('message from moduleC'); 7}
1// main.js 2import log from 'loglevel'; 3import prefix from 'loglevel-prefix'; 4 5import a from './moduleA'; 6import b from './moduleB'; 7import c from './moduleC'; 8 9log.warn('message from root %s prefixing', 'before'); 10 11prefix(log, { 12 template: '[%t] %l (%n):', 13}); 14 15log.warn('message from root %s prefixing', 'after'); 16 17a(); 18b(); 19c();
Output
message from root before prefixing
[16:53:46] WARN (root): message from root after prefixing
[16:53:46] WARN (root): message from moduleA
message from moduleB
[16:53:46] WARN (moduleC): message from moduleC
Errors
1// main.js 2import log from 'loglevel'; 3import prefix from 'loglevel-prefix'; 4 5log.setLevel('info'); 6prefix(log); 7 8log.info('message from root after prefixing'); 9 10try { 11 prefix(log, { 12 timestampFormatter: date => date.toISOString() 13 }); 14} catch(e) { 15 log.error(e); 16}; 17 18log.info('message from root after pre-prefixing'); 19 20const logger = log.getLogger('main'); 21 22try { 23 prefix(logger, { 24 template: '[%t] %l (%n):' 25 }); 26} catch(e) { 27 logger.error(e); 28}; 29 30logger.info('message from child logger');
Output
[16:53:46] INFO: message from root after prefixing
[16:53:46] ERROR: TypeError: You can assign a prefix only one time
[16:53:46] INFO: message from root after pre-prefixing
[16:53:46] ERROR: TypeError: Argument is not a root loglevel object
[16:53:46] INFO: message from child logger
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 1/29 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
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
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
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Reason
30 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-4hpf-3wq7-5rpr
- Warn: Project is vulnerable to: GHSA-f522-ffg8-j8r6
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-282f-qqgm-c34q
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-g6ww-v8xp-vmwg
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
Score
1.7
/10
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 MoreOther packages similar to loglevel-prefix
loglevel-plugin-prefix
Plugin for loglevel message prefixing
loglevel-colored-level-prefix
loglevel plugin that adds colored level prefix (node only)
loglevelnext
A modern logging library for Node.js and modern browsers that provides log level mapping to the console
loglevel-message-prefix
Plugin for loglevel which allows defining prefixes for log messages