Merge pull request #3338 from armorik83/log4js

add log4js-node
This commit is contained in:
Masahiro Wakame
2014-12-24 02:28:50 +09:00
2 changed files with 84 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
/// <reference path="./log4js.d.ts" />
import log4js = require('log4js');
log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese');
var logger = log4js.getLogger('cheese');
logger.setLevel('ERROR');
logger.trace('Entering cheese testing');
logger.debug('Got cheese.');
logger.info('Cheese is Gouda.');
logger.warn('Cheese is quite smelly.');
logger.error('Cheese is too ripe!');
logger.fatal('Cheese was breeding ground for listeria.');
var cb = () => {};
log4js.shutdown(cb);
log4js.configure({
appenders: [
{ type: 'console' },
{ type: 'file', filename: 'logs/cheese.log', category: 'cheese' }
]
});
var defaultLogger = log4js.getDefaultLogger();
defaultLogger.debug('Got cheese.');
+57
View File
@@ -0,0 +1,57 @@
// Type definitions for log4js
// Project: https://github.com/nomiddlename/log4js-node
// Definitions by: Kentaro Okuno <http://github.com/armorik83>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "log4js" {
/**
* Get a logger instance. Instance is cached on categoryName level.
*
* @param {String} [categoryName] name of category to log to.
* @returns {Logger} instance of logger for the category
* @static
*/
export function getLogger(categoryName?: string): Logger;
/**
* Get the default logger instance.
* @returns {Logger} instance of default logger
* @static
*/
export function getDefaultLogger(): Logger;
/**
* args are appender, then zero or more categories
*
* @param {*[]} appenders
* @returns {void}
* @static
*/
export function addAppender(...appenders: any[]): void;
/**
* Shutdown all log appenders. This will first disable all writing to appenders
* and then call the shutdown function each appender.
*
* @params {Function} cb - The callback to be invoked once all appenders have
* shutdown. If an error occurs, the callback will be given the error object
* as the first argument.
* @returns {void}
*/
export function shutdown(cb: Function): void;
export function configure(config: any, options?: any): void;
export var appenders: any;
export interface Logger {
setLevel(level: string): void;
trace(message: string): void;
debug(message: string): void;
info(message: string): void;
warn(message: string): void;
error(message: string): void;
fatal(message: string): void;
}
}