slf4ts-api
Simple Logging Facade for NodeJS
Inspired by the popular Java lib SLF4J
This project is used to abstract logging
to develop reusable libraries and not force the usage
of a certain logging framework.
It's meant to be used with nodejs
.
LogLevel
- TRACE (numeric value:
4
) - DEBUG (numeric value:
3
) - INFO (numeric value:
2
) - WARN (numeric value:
1
) - ERROR (numeric value:
0
)
Logger Implementations
slf4ts doesn't work without a logging-framework binding.
Bindings exist for a couple of logging-frameworks:
Write a binding
A binding for a logging-framework needs to implement the LoggerBinding
interface and
the actual logger interface LoggerImplementation
.
Also a file named .slf4ts-binding
needs to be present in the package folder (can be empty).
A node package for a binding should export a single function that is used during binding discovery.
Interfaces to implement:
;
Sample implementation in typescript (index.ts):
;
An example implementation can be found in the example-node-modules
folder of this project.
Usage
; // gets the root logger (group "" and name ""); // sets the log level of all loggersLoggerConfiguration.setLogLevelLogLevel.INFO; // sets the log level of all loggers within group "my-lib"LoggerConfiguration.setLogLevelLogLevel.WARN, "my-lib"; // sets the log level of the logger with group "my-lib" and name "X"LoggerConfiguration.setLogLevelLogLevel.ERROR, "my-lib", "X"; ; // sets the config of all loggersLoggerConfiguration.setConfigconfig; // sets the config of all loggers within group "my-lib"LoggerConfiguration.setConfigconfig, "my-lib"; // sets the config of the logger with group "my-lib" and name "X"LoggerConfiguration.setConfigconfig, "my-lib", "X";