diff --git a/src/logger.ts b/src/logger.ts index f57bc70..971513e 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -4,6 +4,7 @@ import {get_color} from './color' export const writers = new Map export let options: Options = { format: "[$time] $level $namespace :", + pad_level: true, verbose: true, } @@ -51,8 +52,12 @@ function log(message: any[], level: Level, namespace: string) : void { const head = options.format .replace("$time", new Date().toISOString()) .replace("$namespace", namespace) - const head_bw = head.replace('$level', level_to_string(level, false)) - const head_color = head.replace("$level", level_to_string(level, true)) + + let lvl = get_string(level) + if (options.pad_level) lvl = pad(lvl) + + const head_color = head.replace('$level', get_color(level)(lvl)) + const head_bw = head.replace('$level', lvl) for (const [name, writer] of writers.entries()) { const options = writer.options @@ -64,13 +69,8 @@ function log(message: any[], level: Level, namespace: string) : void { } } -function level_to_string(level: Level, with_color: boolean) : string { - const str = get_string(level) - - if (!with_color) return str - - const color = get_color(level) - return color(str) +function pad(str: string) : string { + return str + " ".repeat("WARNING".length - str.length) } function get_string(level: Level) : string { @@ -81,4 +81,4 @@ function get_string(level: Level) : string { case Level.WARNING: return "WARNING" case Level.ERROR: return "ERROR " } -} \ No newline at end of file +} diff --git a/src/types.ts b/src/types.ts index 7279fc1..9f0d52a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,6 @@ export type Options = { format: string, + pad_level: boolean, verbose: boolean, }