Skip to content

Commit

Permalink
try to figure out why log levels are ignored on gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jifalops committed Nov 18, 2024
1 parent e83f0da commit de3f772
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { TelemetryServiceMock } from './telemetry/service_mock';
const init_start = performance.now();

export const log = new Log(IS_PRODUCTION_BUILD ? Log.INFO : Log.TRACE);
log.setLevel(IS_PRODUCTION_BUILD ? Log.INFO : Log.TRACE);

log.debug(init_start, 'Initializing...');
log.debug('Config:', {
Expand Down
27 changes: 20 additions & 7 deletions src/lib/log.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
const LEVEL = {
ASSERT: 1,
ERROR: 2,
WARN: 3,
INFO: 4,
DEBUG: 5,
TRACE: 6
} as const;

export class Log {
static readonly ASSERT = 1;
static readonly ERROR = 2;
static readonly WARN = 3;
static readonly INFO = 4;
static readonly DEBUG = 5;
static readonly TRACE = 6;
static readonly ASSERT = LEVEL.ASSERT;
static readonly ERROR = LEVEL.ERROR;
static readonly WARN = LEVEL.WARN;
static readonly INFO = LEVEL.INFO;
static readonly DEBUG = LEVEL.DEBUG;
static readonly TRACE = LEVEL.TRACE;

assert = console.assert.bind(console);
error = console.error.bind(console);
Expand All @@ -13,7 +22,7 @@ export class Log {
debug = console.debug.bind(console);
trace = console.log.bind(console);

level = Log.INFO;
level: number = Log.INFO;

constructor(level?: number) {
if (level !== undefined) {
Expand All @@ -23,6 +32,10 @@ export class Log {
}

setLevel(level: number) {
console.log('Current log level:', this.level);
console.log('New log level:', level);
console.log('Log.INFO:', Log.INFO);
console.log('Log.DEBUG:', Log.DEBUG);
this.level = level;
if (level >= Log.ASSERT) this.assert = console.assert.bind(console);
else this.assert = () => {};
Expand Down

0 comments on commit de3f772

Please sign in to comment.