Git Product home page Git Product logo

logger's People

Contributors

kettanaito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

logger's Issues

Support `LOG_LEVEL` expression

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.

Allow to perform operation depending on the log level

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.

Accept subscriptions

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.