File size: 2,489 Bytes
9ada4bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
type ColorFunction = (text: string) => void;
declare function yellow(text: string): string;
declare function blue(text: string): string;
declare function gray(text: string): string;
declare function red(text: string): string;
declare function green(text: string): string;

type colors_ColorFunction = ColorFunction;
declare const colors_blue: typeof blue;
declare const colors_gray: typeof gray;
declare const colors_green: typeof green;
declare const colors_red: typeof red;
declare const colors_yellow: typeof yellow;
declare namespace colors {
  export {
    colors_ColorFunction as ColorFunction,
    colors_blue as blue,
    colors_gray as gray,
    colors_green as green,
    colors_red as red,
    colors_yellow as yellow,
  };
}

type LogLevel = 'debug' | 'info' | 'success' | 'warning' | 'error';
type LogColors = keyof typeof colors;
interface LogEntry {
    timestamp: Date;
    level: LogLevel;
    message: any;
}
declare class Logger {
    private readonly name;
    private prefix;
    constructor(name: string);
    extend(domain: string): Logger;
    /**
     * Print a debug message.
     * @example
     * logger.debug('no duplicates found, creating a document...')
     */
    debug(message: any, ...positionals: Array<unknown>): void;
    /**
     * Print an info message.
     * @example
     * logger.info('start parsing...')
     */
    info(message: any, ...positionals: Array<unknown>): (message: any, ...positionals: Array<unknown>) => void;
    /**
     * Print a success message.
     * @example
     * logger.success('successfully created document')
     */
    success(message: any, ...positionals: Array<unknown>): void;
    /**
     * Print a warning.
     * @example
     * logger.warning('found legacy document format')
     */
    warning(message: any, ...positionals: Array<unknown>): void;
    /**
     * Print an error message.
     * @example
     * logger.error('something went wrong')
     */
    error(message: any, ...positionals: Array<unknown>): void;
    /**
     * Execute the given callback only when the logging is enabled.
     * This is skipped in its entirety and has no runtime cost otherwise.
     * This executes regardless of the log level.
     * @example
     * logger.only(() => {
     *   logger.info('additional info')
     * })
     */
    only(callback: () => void): void;
    private createEntry;
    private logEntry;
    private formatTimestamp;
    private getWriter;
}

export { LogColors, LogEntry, LogLevel, Logger };