Gathering detailed insights and metrics for @teamteanpm2024/ea-fugiat-corporis
Gathering detailed insights and metrics for @teamteanpm2024/ea-fugiat-corporis
npm install @teamteanpm2024/ea-fugiat-corporis
Typescript
Module System
Node Version
NPM Version
50.8
Supply Chain
93.5
Quality
79.8
Maintenance
100
Vulnerability
100
License
Cumulative downloads
Total Downloads
Last day
0%
0
Compared to previous day
Last week
0%
0
Compared to previous week
Last month
0%
0
Compared to previous month
Last year
0%
0
Compared to previous year
37
Node.js native logger
@teamteanpm2024/ea-fugiat-corporis
created?Because I just need a very simple logger to view log messages in terminal.
I have used many loggers and they are all good, but their great features I almost never use.
In addition, I don't like the complexity of the concepts formatter
, transport
, etc.
console.log
and console.error
with very little tweakingNode.js
1pnpm i nanolog
1import { logger, debug, info, error, trace } from '@teamteanpm2024/ea-fugiat-corporis' 2 3// regular usage 4debug('This is debug message') 5// --> {PID} | {TIME} | DEBUG | This is debug message 6debug('This is info message') 7// --> {PID} | {TIME} | INFO | This is info message 8error('This is error message') 9// --> {PID} | {TIME} | ERROR | This is error message 10trace('This is trace message') 11// --> {PID} | {TIME} | TRACE | This is error message 12// tracing data 13 14// create logger instance for service `dataminer` 15const dataminerLog = logger('dataminer') 16dataminerLog.debug('Connecting to Postgres Database') 17// --> {PID} | {TIME} | dataminer | DEBUG | Connecting to Postgres Database 18dataminerLog.error('Could not connect to Postgres Database') 19// --> {PID} | {TIME} | dataminer | ERROR | Could not connect to Postgres Database 20 21// create logger instance for module `normalizer` in service `dataminer` 22const normalizerLog = dataminerLog.branch('normalizer') 23normalizerLog.debug('Fill the missing values') 24// --> {PID} | {TIME} | dataminer / normalizer | DEBUG | Fill the missing values 25normalizerLog.debug('Resolve inconsistent data') 26// --> {PID} | {TIME} | dataminer / normalizer | DEBUG | Resolve inconsistent data
logger(String namespace, Object options)
namespace
: optional, e.g "servicename", "service:module", "node1:serviceX:module8", etcoptions
: optional
enable
: Boolean, enable logger or not (default: true
)print
: Boolean, print out log or not (default: true
)event
: Boolean, trigger events or not (default: false
)separator
: String, to display the namespace by level (default: /
)Returns a logger instance, with the following methods:
debug()
: print out debug loginfo()
: print out info logerror()
: print out error logtrace()
: print out trace log and tracing databrance()
: create logger instance at sub level of current instanceNote:
logger('service:module:component')
and logger('service').branch('module').branch('component')
are similardebug(argurments)
Print out debug message.
1import { debug } from '@teamteanpm2024/ea-fugiat-corporis' 2 3debug('This is debug message') 4// --> 201374 | 2022-07-27T13:02:13.240Z | DEBUG | This is debug message 5 6debug('Welcome message', { name: 'Alice' }, [1, 2, 3, 4, 5]) 7// --> 201374 | 2022-07-27T13:02:13.243Z | DEBUG | Welcome message { name: 'Alice' } [ 1, 2, 3, 4, 5 ]
error(argurments)
Print out error message.
1import { error } from '@teamteanpm2024/ea-fugiat-corporis' 2 3error('Error occurred while sending email', { subject: 'Hello', body: 'hi Bob, Long time no see' }) 4// --> 204753 | 2022-07-27T13:05:53.395Z | ERROR | Error occurred while sending email { subject: 'Hello', body: 'hi Bob, Long time no see' }
trace(argurments)
Print out tracing log and data.
1import { trace } from '@teamteanpm2024/ea-fugiat-corporis' 2 3trace(new Error('Something went wrong'))
Event listener allows to add more actions on the logs when they are printed out, such as write to file, insert into database or send to somewhere.
This simple approach frees the lazy developers like me from the unnecessary confusions.
Events will be applied to all existing logger instances, which have event
option enabled.
onDebug(Function callback)
1import { logger, onDebug } from '@teamteanpm2024/ea-fugiat-corporis' 2 3const appLog = logger('myapp', { event: true }) 4 5onDebug((entry) => { 6 // do everything with log data entry 7 const { 8 namespace, 9 level, 10 ts, 11 args, 12 message, 13 } = entry 14}) 15 16appLog.debug('Load user data from backup file')
onInfo(Function callback)
Same as onDebug()
, but triggered with info
log.
onError(Function callback)
Same as onDebug()
, but triggered with error
log.
onTrace(Function callback)
Same as onDebug()
, but triggered with trace
log.
1git clone https://github.com/teamteanpm2024/ea-fugiat-corporis.git 2cd @teamteanpm2024/ea-fugiat-corporis 3pnpm i 4pnpm test 5 6# evaluation 7pnpm eval
The MIT License (MIT)
No vulnerabilities found.
No security vulnerabilities found.