Skip to content

Commit

Permalink
fix: file organization
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyrlex committed Jul 3, 2024
1 parent f8d5cd8 commit 491ae80
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions src/loggage/loggage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,7 @@ export class Loggage {
private name: string;
private verbosity: Verbosity;

public static TAGS: Readonly<Record<keyof typeof Verbosity, string>> = {
FATAL_ERROR: S.reset(B.red(' ERROR ')) + ' ' + S.reset(B.magenta(' FATAL ')) + this.pad(' ERROR FATAL '),
ERROR: S.reset(B.red(' ERROR ')) + this.pad(' ERROR '),
WARNING: S.reset(B.orange(' WARNING ')) + this.pad(' WARNING '),
INFO: S.reset(B.grey(' INFO ')) + this.pad(' INFO '),
DEBUG: S.reset(B.cyan(' DEBUG ')) + this.pad(' DEBUG '),
VERBOSE: S.reset(B.blue(' VERBOSE ')) + this.pad(' VERBOSE '),
};

/**
* Pad a word with spaces to the right.
* @param word The word to pad.
* @param length The length of the padding.
* @returns string
*/
private static pad(word: string, length = 18): string {
return ' '.repeat(Math.max(length - word.length, 1));
}

constructor ({
name,
verbosity = Verbosity.INFO,
save = true,
}: LoggageOptions) {
constructor ({ name, verbosity = Verbosity.INFO, save = false, }: LoggageOptions) {
this.name = name;
this.verbosity = verbosity;
this.save = save;
Expand All @@ -54,6 +31,15 @@ export class Loggage {
}
}

public static TAGS: Readonly<Record<keyof typeof Verbosity, string>> = {
FATAL_ERROR: S.reset(B.red(' ERROR ')) + ' ' + S.reset(B.magenta(' FATAL ')) + this.pad(' ERROR FATAL '),
ERROR: S.reset(B.red(' ERROR ')) + this.pad(' ERROR '),
WARNING: S.reset(B.orange(' WARNING ')) + this.pad(' WARNING '),
INFO: S.reset(B.grey(' INFO ')) + this.pad(' INFO '),
DEBUG: S.reset(B.cyan(' DEBUG ')) + this.pad(' DEBUG '),
VERBOSE: S.reset(B.blue(' VERBOSE ')) + this.pad(' VERBOSE '),
};

public getVerbosity(): Verbosity {
return this.verbosity;
}
Expand Down Expand Up @@ -123,4 +109,14 @@ export class Loggage {
this.file.log(log, message);
}
}

/**
* Pad a word with spaces to the right.
* @param word The word to pad.
* @param length The length of the padding.
* @returns string
*/
private static pad(word: string, length = 18): string {
return ' '.repeat(Math.max(length - word.length, 1));
}
}

0 comments on commit 491ae80

Please sign in to comment.