deno.land / x / ultra@v2.3.8 / lib / logger.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { crayon, log as logging, sprintf } from "./deps.ts";
function gradient(string: string) { const chars: string[] = string.split("");
for (const [index, char] of chars.entries()) { chars[index] = crayon.hsl(305 - (7 * index), 100, 70)(char); }
return chars.join("");}
function formatLevel(level: logging.LevelName) { switch (level) { case "INFO": return crayon.bold.blue(level);
case "DEBUG": return crayon.bold.magenta(level);
case "WARNING": return crayon.bold.yellow(level);
case "ERROR": return crayon.bold.red(level);
case "CRITICAL": return crayon.bgRed.black.bold(level);
default: return level; }}
export class Logger extends logging.Logger { /** * @param levelName */ constructor(levelName: logging.LevelName) { const name = "ultra"; const loggerName = gradient(`[ultra]`);
super(name, levelName, { handlers: [ new logging.handlers.ConsoleHandler("DEBUG", { formatter(record) { const level = formatLevel(record.levelName as logging.LevelName); return sprintf( "%s - %s %s", loggerName, level, record.msg, ); }, }), ], }); }
success(message: string) { return this.info(crayon.green(`${message}`)); }}
export const log = new Logger( (Deno.env.get("ULTRA_LOG_LEVEL") as logging.LevelName) || "INFO",);
ultra

Version Info

Tagged at
8 months ago