Add convenience method for parsing LogLevel values form string.

This commit is contained in:
Jonathan Bernard 2021-07-22 23:58:34 -05:00
parent e42549773d
commit 6562948acb
2 changed files with 13 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@jdbernard/logging",
"version": "1.0.0",
"version": "1.1.0",
"description": "Simple Javascript logging service.",
"main": "src/index.ts",
"module": "dist/index.js",
@ -9,7 +9,7 @@
},
"repository": {
"type": "git",
"url": "https://git.jdb-labs.com/jdb/js-logging.git"
"url": "https://git.jdb-software.com/jdb/js-logging.git"
},
"keywords": [
"log",

View File

@ -9,6 +9,17 @@ export enum LogLevel {
FATAL
}
const kv = 'WARN';
const TEST = LogLevel[kv];
export function parseLogLevel(str: string, defaultLevel = LogLevel.INFO): LogLevel {
if (Object.prototype.hasOwnProperty.call(LogLevel, str)) {
return LogLevel[<any>str] as unknown as LogLevel;
} else {
return defaultLevel;
}
}
export interface LogMessage {
scope: string;
level: LogLevel;