-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from saskodh/FR#40_logging
Fr#40 logging
- Loading branch information
Showing
19 changed files
with
237 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { loggers, transports, LoggerInstance, LoggerOptions, LogCallback } from "winston"; | ||
|
||
export interface LoggerMethod { | ||
(msg: string, callback: LogCallback): Logger; | ||
(msg: string, meta: any, callback: LogCallback): Logger; | ||
(msg: string, ... meta: any[]): Logger; | ||
} | ||
|
||
export interface Logger { | ||
debug: LoggerMethod; | ||
verbose: LoggerMethod; | ||
info: LoggerMethod; | ||
warn: LoggerMethod; | ||
error: LoggerMethod; | ||
} | ||
|
||
// FIXME winston issue [#814]: log statements are not in the correct order | ||
export class LoggerFactory { | ||
|
||
public static FRAMEWORK_LOGGER_NAME = 'framework-logger'; | ||
private static logger: LoggerInstance; | ||
|
||
static getInstance(): Logger { | ||
if (!this.logger) { | ||
this.logger = this.createFrameworkLogger(); | ||
} | ||
return <any> this.logger; | ||
} | ||
|
||
private static createFrameworkLogger(): LoggerInstance { | ||
return loggers.add(this.FRAMEWORK_LOGGER_NAME, this.getFrameworkLoggerOptions()); | ||
} | ||
|
||
private static getFrameworkLoggerOptions(): LoggerOptions { | ||
return { | ||
transports: [ | ||
new transports.Console({ | ||
handleExceptions: false, | ||
level: process.env.LOG_LEVEL || 'debug', | ||
timestamp: function () { return new Date().toISOString(); }, | ||
formatter: function (options) { | ||
return `${options.timestamp()} | ${options.level.toUpperCase()}\t| ${options.message}`; | ||
} | ||
}) | ||
] | ||
}; | ||
} | ||
} | ||
|
Oops, something went wrong.