Skip to content

Commit

Permalink
feat(logger): add level
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Aug 12, 2023
1 parent e7a7119 commit 49fbc4c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/logger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export * from './logger';
export const Logger = (options: Partial<LoggerOptions> = {}) => {
return new BreadcLogger({
reporter: [FancyReporter()],
level: 'info',
level: 0,
format: {},
stdout: process?.stdout,
stderr: process?.stderr,
Expand Down
59 changes: 57 additions & 2 deletions packages/logger/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,53 @@
export type LogLevel = 'info' | 'warn' | 'error' | 'debug';
export type LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | (number & {});

export const LogLevels: Record<LogType, number> = {
silent: Number.NEGATIVE_INFINITY,

fatal: 0,
error: 0,

warn: 1,

log: 2,
info: 3,

success: 3,
fail: 3,
ready: 3,
start: 3,
box: 3,

debug: 4,

trace: 5,

verbose: Number.POSITIVE_INFINITY
};

export type LogType =
// 0
| 'silent'
| 'fatal'
| 'error'
// 1
| 'warn'
// 2
| 'log'
// 3
| 'info'
| 'success'
| 'fail'
| 'ready'
| 'start'
| 'box'
// Verbose
| 'debug'
| 'trace'
| 'verbose';

export interface LogObject {
level?: LogLevel;
type?: LogType;
tag?: string;
date?: Date;
message?: string;
Expand All @@ -11,4 +57,13 @@ export interface Reporter {
print: (log: LogObject) => void;
}

export interface FormatOptions {}
/**
* @see https://nodejs.org/api/util.html#util_util_inspect_object_showhidden_depth_colors
*/
export interface FormatOptions {
columns?: number;
date?: boolean;
colors?: boolean;
compact?: boolean | number;
[key: string]: unknown;
}

0 comments on commit 49fbc4c

Please sign in to comment.