open-draft / logger Goto Github PK
View Code? Open in Web Editor NEWEnvironment-agnostic, ESM-friendly logger for simple needs.
Home Page: https://npm.im/@open-draft/logger
License: MIT License
Environment-agnostic, ESM-friendly logger for simple needs.
Home Page: https://npm.im/@open-draft/logger
License: MIT License
Right now if you set LOG_LEVEL=debug
you will only see debug statements.
Changes are, if you are debugging, you are also interested in errors, even warning, maybe info ? You get the gist.
I expected that setting the log level to info
would also display all messages "above" info. Changing the current behaviour would be a breaking change, so what about expressions ?
# Ideas of syntaxes
LOG_LEVEL=info+ node ./app.js # info and anything above
LOG_LEVEL=debug:warning node ./app.js # anything between debug and warning, both included
# More verbose syntaxes but don't rely on a hierarchy
LOG_LEVEL="debug|info|warning|error" node ./app.js . # The pipe is a bash operator so we have to use quotes. But the pipe is a common operation for "or".
LOG_LEVEL=debug,info,warning,error node ./app.js # Doesn't need quotes, maybe less readable ?
If we allow to set multiple levels, we can actually allow any character that is not a letter as a separator.
I'm willing to submit a PR for this.
Logger.only()
is dedicated to trigger additional operation, only if needed.
It seems natural to me to be able to gather those information only at some level of logging.
Typically one wants to display errors without triggering potentially costly operations to collect debug information. This could be done later, on the developer's machine.
logger.debug.only(async (level) => {
const debugInfo = await collectDebugInformation();
return `An error occured, diagnostic : ${debugInfo.reason}`
});
The other solution would be to expose the current log level, so it can be checked inside Logger.only()
.
EDIT: I'm willing to submit a PR for this.
This lib is great for other libs because it is minimal, there is nothing to learn.
I maintain a few packages, some with IO, like database IO.
I use @open-draft/logger
and I would like the consumer of my lib to be able to receive its logs, like database query.
But you don't want to handle every logging logic, there are great libs out there for that.
If one could just subscribe(fn)
, it would allow consumers to plugin in their own solution, without us, maintainers having to manage anything.
// lib.ts
const logger = new Logger('someLib');
export const onSomeLibLog = logger.subscribe;
// app.ts
import { onSomeLibLog } from 'someLib';
onSomeLibLog(log => {
appLogSolution.write(log);
})
I'm willing to submit a PR for that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.