Gathering detailed insights and metrics for loglevel-plugin-prefix
Gathering detailed insights and metrics for loglevel-plugin-prefix
Gathering detailed insights and metrics for loglevel-plugin-prefix
Gathering detailed insights and metrics for loglevel-plugin-prefix
loglevel-colored-level-prefix
loglevel plugin that adds colored level prefix (node only)
loglevel-message-prefix
Plugin for loglevel which allows defining prefixes for log messages
loglevel-prefix
Plugin for loglevel message prefixing
loglevel-prefix-persist
Plugin for loglevel with message prefix and persistence
npm install loglevel-plugin-prefix
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
64 Stars
31 Commits
12 Forks
1 Watchers
8 Branches
2 Contributors
Updated on Jan 19, 2025
Latest Version
0.8.4
Package Id
loglevel-plugin-prefix@0.8.4
Size
45.76 kB
NPM Version
6.1.0
Node Version
8.9.1
Published on
Jun 18, 2018
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Plugin for loglevel message prefixing.
1npm install loglevel-plugin-prefix
This plugin is under active development and should be considered as an unstable. No guarantees regarding API stability are made. Backward compatibility is guaranteed only by path releases.
reg(loglevel)
This method registers plugin for loglevel. This method must be called at least once before any call to the apply method. Repeated calls to this method are ignored.
loglevel
- the root logger, imported from loglevel module
apply(logger, options)
This method applies the plugin to the logger. Before using this method, the reg
method must be called, otherwise a warning will be logged. From the next release, the call apply before reg will throw an error.
logger
- any logger of loglevel
options
- an optional configuration object
1var defaults = { 2 template: '[%t] %l:', 3 levelFormatter: function (level) { 4 return level.toUpperCase(); 5 }, 6 nameFormatter: function (name) { 7 return name || 'root'; 8 }, 9 timestampFormatter: function (date) { 10 return date.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1'); 11 }, 12 format: undefined 13};
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:
%l
- level of message%n
- name of logger%t
- timestamp of messageThe levelFormatter
, nameFormatter
and timestampFormatter
is a functions for formatting corresponding values.
Alternatively, you can use format
option. This is a function that receives formatted values (level, name, timestamp) and should returns a prefix string.
If both format
and template
are present in the configuration, the template
parameter is ignored. When both these parameters are missing in the configuration, the inherited behavior is used.
1<script src="https://unpkg.com/loglevel/dist/loglevel.min.js"></script> 2<script src="https://unpkg.com/loglevel-plugin-prefix@^0.8/dist/loglevel-plugin-prefix.min.js"></script> 3 4<script> 5 var logger = log.noConflict(); 6 var prefixer = prefix.noConflict(); 7 prefixer.reg(logger); 8 prefixer.apply(logger); 9 logger.warn('prefixed message'); 10</script>
Output
[16:53:46] WARN: prefixed message
1const chalk = require('chalk'); 2const log = require('loglevel'); 3const prefix = require('loglevel-plugin-prefix'); 4 5const colors = { 6 TRACE: chalk.magenta, 7 DEBUG: chalk.cyan, 8 INFO: chalk.blue, 9 WARN: chalk.yellow, 10 ERROR: chalk.red, 11}; 12 13prefix.reg(log); 14log.enableAll(); 15 16prefix.apply(log, { 17 format(level, name, timestamp) { 18 return `${chalk.gray(`[${timestamp}]`)} ${colors[level.toUpperCase()](level)} ${chalk.green(`${name}:`)}`; 19 }, 20}); 21 22prefix.apply(log.getLogger('critical'), { 23 format(level, name, timestamp) { 24 return chalk.red.bold(`[${timestamp}] ${level} ${name}:`); 25 }, 26}); 27 28log.trace('trace'); 29log.debug('debug'); 30log.getLogger('critical').info('Something significant happened'); 31log.log('log'); 32log.info('info'); 33log.warn('warn'); 34log.error('error');
Output
1const log = require('loglevel'); 2const prefix = require('loglevel-plugin-prefix'); 3 4prefix.reg(log); 5log.enableAll(); 6 7prefix.apply(log, { 8 template: '[%t] %l (%n) static text:', 9 levelFormatter(level) { 10 return level.toUpperCase(); 11 }, 12 nameFormatter(name) { 13 return name || 'global'; 14 }, 15 timestampFormatter(date) { 16 return date.toISOString(); 17 }, 18}); 19 20log.info('%s prefix', 'template'); 21 22const fn = (level, name, timestamp) => `[${timestamp}] ${level} (${name}) static text:`; 23 24prefix.apply(log, { format: fn }); 25 26log.info('%s prefix', 'functional'); 27 28prefix.apply(log, { template: '[%t] %l (%n) static text:' }); 29 30log.info('again %s prefix', 'template');
Output
[2017-05-29T12:53:46.000Z] INFO (global) static text: template prefix
[2017-05-29T12:53:46.000Z] INFO (global) static text: functional prefix
[2017-05-29T12:53:46.000Z] INFO (global) static text: again template prefix
1const log = require('loglevel'); 2const prefix = require('loglevel-plugin-prefix'); 3 4prefix.reg(log); 5log.enableAll(); 6 7log.info('root'); 8 9const chicken = log.getLogger('chicken'); 10chicken.info('chicken'); 11 12prefix.apply(chicken, { template: '%l (%n):' }); 13chicken.info('chicken'); 14 15prefix.apply(log); 16log.info('root'); 17 18const egg = log.getLogger('egg'); 19egg.info('egg'); 20 21const fn = (level, name) => `${level} (${name}):`; 22 23prefix.apply(egg, { format: fn }); 24egg.info('egg'); 25 26prefix.apply(egg, { 27 levelFormatter(level) { 28 return level.toLowerCase(); 29 }, 30}); 31egg.info('egg'); 32 33chicken.info('chicken'); 34log.info('root');
Output
root
chicken
INFO (chicken): chicken
[16:53:46] INFO: root
[16:53:46] INFO: egg
INFO (egg): egg
info (egg): egg
INFO (chicken): chicken
[16:53:46] INFO: root
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
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
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
31 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
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