@ayana/logger
Useful and great looking logging made easy
What's this?
This is a logging library inspired by the easy use of slf4j
How exactly does this help me?
Besides coloring your output, this logger makes it easy to log where you are logging from. This is done by checking the __dirname
value that you pass. By that we can find out the module name and the path of your file in the module. This also works for modules in the node_modules
folder. In addition the config is global, which makes it easy to control which modules and even single classes are allowed to log at which levels.
What are the limitations?
- There is currently no way to change the logging levels or the logging output format (This can be changed if needed)
- There is currently no way of putting the output to something else besides the stdout (This can also be changed if needed)
- You have to name your folder with your executed code in a specific way (Details are below)
Installing
With NPM
npm i @ayana/logger
With Yarn
yarn add @ayana/logger
How to configure
IMPORTANT: All projects that use this module MUST HAVE the code that is executed in one of the following folders (checked in the order listed): build
, src
, lib
. If this is ignored the output might get messed up or the entire logger might stop working entirely.
Logger.setConfig({
level: 'INFO',
loggers: [{
name: 'helloworld:hello.Hello',
level: 'DEBUG',
}],
});
How to use
Let's say your module is called helloworld
and your JavaScript file is located in the folder src/hello
. The filename doesn't matter.
const Logger = require('@ayana/logger');
const log = Logger.get('Hello', __dirname);
class Hello {
constructor() {
log.info('Hello World!');
}
}
const logOfClass = Logger.get(Hello, __dirname);
Links
GitLab repository
NPM package
License
Refer to the LICENSE file.