common-logging v0.0.3-alpha
common-logging
common-logging is a NodeJS module written in TypeScript that provides a simple abstraction to allow you to select and to change logging implementation at runtime.
This module is inspired by net-commons/common.logging https://github.com/net-commons/common-logging.
With no dependency, common-logging provides also a way to reduce coupling between your code and a specific logger implementation.
common-logging provides a console logger by default but it can easily be used with winston, bunyan or any other standard logging framework.
logManager is the shared entry point of common-logging. logManager is the only reference you need to access loggers in your different modules. If you want to change the underlying logging system, you simply have to change the factory used by common-logging by typing a single line of code anywhere you want and that's it ! All your code will continue to work seamlessly using the new logger implementation.
Getting Started
git clone https://github.com/julienhoarau/common-logging.git
cd common-logging
Installing
Simply install common-logging using the npm command.
npm install --save common-logging
Simple usage
Javascript
var logManager = require('common-logging').logManager;
var logger = logManager.getLogger();
logger.info('Hello World !');
Typescript
import { ILog, logManager } from "common-logging";
const logger: ILog = logManager.getLogger();
logger.info("Hello World !");
Advanced usage
Javascript usage with winston
var winstonLogger = require('winston');
var createDefaultILogFactory = require('common-logging').createDefaultILogFactory;
var logManager = require('common-logging').logManager;
logManager.factory = createDefaultILogFactory(winstonLogger);
// Anywhere in your code ...
var logger = logManager.getLogger();
// Log will be written to winston.
logger.info('Hello World !');
Typescript usage with winston
import { createDefaultILogFactory, ILog, logManager } from "common-logging";
import winstonLogger from "winston";
logManager.factory = createDefaultILogFactory(winstonLogger);
// Anywhere in your code ...
const logger: ILog = logManager.getLogger();
// Log will be written to winston.
logger.info("Hello World !");
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Julien Hoarau - Initial work - julienhoarau
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details