@tekbox/global-logger
GlobalLogger provides an easy interface to manage multiple loggers with different loglevels. Its based on [LogLevel](https://github.com/pimterry/loglevel).
Last updated 2 years ago by r1co .
MIT · Original npm · Tarball · package.json
$ cnpm install @tekbox/global-logger 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 0.1.13                                ...           latest (2 years ago)

6 Versions

  • 0.1.13                                ...           2 years ago
  • 0.1.12                                ...           2 years ago
  • 0.1.11                                ...           2 years ago
  • 0.1.9                                ...           2 years ago
  • 0.1.8                                ...           3 years ago
  • 0.1.7                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 5
Dependencies (3)
Dev Dependencies (10)

Copyright 2014 - 2016 © taobao.org |