summaryrefslogtreecommitdiff
path: root/log/mod.ts
diff options
context:
space:
mode:
authorJames Garbutt <43081j@users.noreply.github.com>2019-01-27 15:21:00 +0000
committerRyan Dahl <ry@tinyclouds.org>2019-01-27 10:21:00 -0500
commitb79d2a9d41963b3c7cfa382d842a86c68b940666 (patch)
tree6dbbfd04979c1ef1c6466223b06363b7f03991f0 /log/mod.ts
parent75dab82adbf64cb021b0133771a782c285991a4b (diff)
log: add tests (denoland/deno_std#136)
Original: https://github.com/denoland/deno_std/commit/4b054d69ad3e63e0a07d0df77a973b0ae5e0892d
Diffstat (limited to 'log/mod.ts')
-rw-r--r--log/mod.ts33
1 files changed, 16 insertions, 17 deletions
diff --git a/log/mod.ts b/log/mod.ts
index f332711b3..596b72a37 100644
--- a/log/mod.ts
+++ b/log/mod.ts
@@ -21,24 +21,20 @@ export interface LogConfig {
}
const DEFAULT_LEVEL = "INFO";
-const DEFAULT_NAME = "";
const DEFAULT_CONFIG: LogConfig = {
- handlers: {},
+ handlers: {
+ "default": new ConsoleHandler(DEFAULT_LEVEL)
+ },
loggers: {
- "": {
- level: "INFO",
- handlers: [""]
+ "default": {
+ level: DEFAULT_LEVEL,
+ handlers: ["default"]
}
}
};
-const defaultHandler = new ConsoleHandler("INFO");
-const defaultLogger = new Logger("INFO", [defaultHandler]);
-
const state = {
- defaultHandler,
- defaultLogger,
handlers: new Map(),
loggers: new Map(),
config: DEFAULT_CONFIG
@@ -52,19 +48,19 @@ export const handlers = {
};
export const debug = (msg: string, ...args: any[]) =>
- defaultLogger.debug(msg, ...args);
+ getLogger('default').debug(msg, ...args);
export const info = (msg: string, ...args: any[]) =>
- defaultLogger.info(msg, ...args);
+ getLogger('default').info(msg, ...args);
export const warning = (msg: string, ...args: any[]) =>
- defaultLogger.warning(msg, ...args);
+ getLogger('default').warning(msg, ...args);
export const error = (msg: string, ...args: any[]) =>
- defaultLogger.error(msg, ...args);
+ getLogger('default').error(msg, ...args);
export const critical = (msg: string, ...args: any[]) =>
- defaultLogger.critical(msg, ...args);
+ getLogger('default').critical(msg, ...args);
export function getLogger(name?: string) {
if (!name) {
- return defaultLogger;
+ return state.loggers.get('default');
}
if (!state.loggers.has(name)) {
@@ -81,7 +77,10 @@ export function getHandler(name: string) {
}
export async function setup(config: LogConfig) {
- state.config = config;
+ state.config = {
+ handlers: {...DEFAULT_CONFIG.handlers, ...config.handlers},
+ loggers: {...DEFAULT_CONFIG.loggers, ...config.loggers}
+ };
// tear down existing handlers
state.handlers.forEach(handler => {