@tekbox/global-logger
v0.1.13
Published
GlobalLogger provides an easy interface to manage multiple loggers with different loglevels. Its based on [LogLevel](https://github.com/pimterry/loglevel).
Downloads
11
Readme
GlobalLogger
GlobalLogger provides an easy interface to manage multiple loggers with different loglevels. Its based on LogLevel.
Usage:
package.json of your library:
{
[...]
"loggerConfig": {
"loggerName": "GlobalLogger"
}
[...]
}
Import Logger:
import {GetLogger} from "@tekbox/global-logger";
const loggerFactory = GetLogger();
DefaultLogger:
const logger1 = loggerFactory.getDefaultLogger("DefaultLogger");
logger1.info("Hello World");
[INFO][2018-1-14 13:19:51][DefaultLogger] Hello World
FilenameLogger:
src/mylib/MyLib.ts
const logger2 = loggerFactory.getFilenameLogger(__filename);
logger2.info("Hello World");
[INFO][2018-1-14 13:19:51][GlobalLogger.src.mylib.MyLib] Hello World
NamedFilenameLogger:
src/mylib/MyLib.ts
const logger3 = loggerFactory.getNamedFilenameLogger("loggerName", "src/mylib/MyLib.ts")
logger3.info("Hello World");
[INFO][2018-1-14 13:19:51][GlobalLogger.src.mylib.LoggerName] Hello World
GlobalLogger:
src/mylib/MyLib.ts
const logger4 = loggerFactory.getGlobalLogger("globalLogger", "src/mylib/MyLib.ts")
logger4.info("Hello World");
[INFO][2018-1-14 13:19:51][GlobalLogger.GlobalLogger] Hello World
Configure:
Loglevels:
{
TRACE = 0,
DEBUG = 1,
INFO = 2,
WARN = 3,
ERROR = 4,
SILENT = 5
}
{
[...]
"loggerConfig": {
"loggerName": "GlobalLogger", // override name. default: <package.json>.name
"levels": {
"GlobalLogger.dummy.Index": 5 // set log level for GlobalLogger.dummy.Index to SILENT
},
"replaceConfig": { // override path segements in logger name.
"build": "", // default
"dist": "", // default
"test": "", // default
"dummy": "replaced" // GlobalLogger.dummy.Index => GlobalLogger.replaced.Index
}
}
[...]
}
You can override log levels from libraries using GlobalLogger by adding a level definition to your package.json.