From 3a95396b773c3bfb5f8a407e256f98d926297002 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Tue, 10 Apr 2018 18:18:12 +0100 Subject: WIP: Add support for raw and meta views --- src/logger.ts | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 154 insertions(+), 13 deletions(-) (limited to 'src/logger.ts') diff --git a/src/logger.ts b/src/logger.ts index bbb0a73..069cdf5 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -5,26 +5,105 @@ import * as winston from 'winston'; import { files } from './files'; -type LogLevel = 'critical' | 'error' | 'warning' | 'security' | 'info'; +type Colour = (s: string) => string; + +type LogLevel = + | '7' + | 'debug' + | 'minor' + | 'silly' + | 'testing' + | 'verbose' + | '6' + | 'information' + | 'inform' + | 'info' + | '5' + | 'note' + | 'notice' + | 'notify' + | 'success' + | 'security' + | '4' + | 'warn' + | 'warning' + | '3' + | 'err' + | 'failure' + | 'fail' + | 'error' + | '2' + | 'crit' + | 'severe' + | 'critical' + | '1' + | 'alert' + | 'breach' + | '0' + | 'fatal' + | 'emerg' + | 'emergency' + | 'shutdown'; const LOG_LEVELS: winston.LoggerOptions = { - info: 4, - security: 3, - warning: 2, - error: 1, - critical: 0 + 7: 7, + debug: 7, + minor: 7, + silly: 7, + testing: 7, + verbose: 7, + 6: 6, + information: 6, + inform: 6, + info: 6, + 5: 5, + note: 5, + notice: 5, + notify: 5, + success: 5, + security: 5, + 4: 4, + warn: 4, + warning: 4, + 3: 3, + err: 3, + failure: 3, + fail: 3, + error: 3, + 2: 2, + crit: 2, + severe: 2, + critical: 2, + 1: 1, + alert: 1, + breach: 1, + 0: 0, + fatal: 0, + emerg: 0, + emergency: 0, + shutdown: 0 }; -const LOG_LEVEL_COLOURS: { - [key: string]: (s: string) => string; +const LEVEL_COLOURS: { + [key: number]: Colour; } = { - info: colors.cyan, - security: colors.blue, - warning: colors.yellow, - error: colors.red, - critical: colors.red + 7: colors.cyan, + 6: colors.blue, + 5: colors.green, + 4: colors.yellow, + 3: colors.red, + 2: colors.magenta, + 1: colors.black, + 0: colors.white }; +const LOG_LEVEL_COLOURS: { + [key: string]: Colour; +} = {}; +Object.keys(LOG_LEVELS).forEach((k: string): void => { + LOG_LEVEL_COLOURS[k] = LEVEL_COLOURS[LOG_LEVELS[k]]; +}); + interface LoggingMetadata { component?: string; user?: string; @@ -217,20 +296,82 @@ const fetchLogs: (level: LogLevel, params?: FetchParams) => LogItem[] = ( }; export const logger: { + 7: LogFunction; + debug: LogFunction; + minor: LogFunction; + silly: LogFunction; + testing: LogFunction; + verbose: LogFunction; + 6: LogFunction; + information: LogFunction; + inform: LogFunction; info: LogFunction; + 5: LogFunction; + note: LogFunction; + notice: LogFunction; + notify: LogFunction; + success: LogFunction; security: LogFunction; + 4: LogFunction; + warn: LogFunction; warning: LogFunction; + 3: LogFunction; + err: LogFunction; + failure: LogFunction; + fail: LogFunction; error: LogFunction; + 2: LogFunction; + crit: LogFunction; + severe: LogFunction; critical: LogFunction; + 1: LogFunction; + alert: LogFunction; + breach: LogFunction; + 0: LogFunction; + fatal: LogFunction; + emerg: LogFunction; + emergency: LogFunction; + shutdown: LogFunction; isEnabled: () => boolean; forward: (level: LogLevel, message: string, meta: LoggingMetadata) => void; fetch: (level: LogLevel, params?: FetchParams) => LogItem[]; } = { + 7: makeLogFunction('7'), + debug: makeLogFunction('debug'), + minor: makeLogFunction('minor'), + silly: makeLogFunction('silly'), + testing: makeLogFunction('testing'), + verbose: makeLogFunction('verbose'), + 6: makeLogFunction('6'), + information: makeLogFunction('information'), + inform: makeLogFunction('inform'), info: makeLogFunction('info'), + 5: makeLogFunction('5'), + note: makeLogFunction('note'), + notice: makeLogFunction('notice'), + notify: makeLogFunction('notify'), + success: makeLogFunction('success'), security: makeLogFunction('security'), + 4: makeLogFunction('4'), + warn: makeLogFunction('warn'), warning: makeLogFunction('warning'), + 3: makeLogFunction('3'), + err: makeLogFunction('err'), + failure: makeLogFunction('failure'), + fail: makeLogFunction('fail'), error: makeLogFunction('error'), + 2: makeLogFunction('2'), + crit: makeLogFunction('crit'), + severe: makeLogFunction('severe'), critical: makeLogFunction('critical'), + 1: makeLogFunction('1'), + alert: makeLogFunction('alert'), + breach: makeLogFunction('breach'), + 0: makeLogFunction('0'), + fatal: makeLogFunction('fatal'), + emerg: makeLogFunction('emerg'), + emergency: makeLogFunction('emergency'), + shutdown: makeLogFunction('shutdown'), isEnabled: (): boolean => !basicFileTransport.silent, forward: basicLogger.log, fetch: fetchLogs -- cgit v1.2.1