diff --git a/log4js/log4js-tests.ts b/log4js/log4js-tests.ts new file mode 100644 index 0000000000..e18ad78622 --- /dev/null +++ b/log4js/log4js-tests.ts @@ -0,0 +1,27 @@ +/// +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.'); diff --git a/log4js/log4js.d.ts b/log4js/log4js.d.ts new file mode 100644 index 0000000000..869a10c58d --- /dev/null +++ b/log4js/log4js.d.ts @@ -0,0 +1,57 @@ +// Type definitions for log4js +// Project: https://github.com/nomiddlename/log4js-node +// Definitions by: Kentaro Okuno +// 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; + } +}