Skip to content

Commit

Permalink
Update logs.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
imabutahersiddik authored Oct 28, 2024
1 parent e528d9c commit 4d52c7c
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions src/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ export class Logs {
consoleLog(logMessage, metadata);
}

// Ensure metadata is set correctly in LogReturn
return new LogReturn(
{
raw: logMessage,
diff: this._diffColorCommentMessage(type, logMessage),
type,
level,
},
metadata // Ensure metadata is passed correctly here
metadata
);
}

Expand Down Expand Up @@ -126,6 +125,17 @@ export class Logs {
type: "verbose",
});
}

public trace(log: string, metadata?: Metadata): LogReturn {
metadata = this._addDiagnosticInformation(metadata);
return this._log({
level: LOG_LEVEL.TRACE,
consoleLog: Logs.console.trace,
logMessage: log,
metadata,
type: "trace",
});
}

constructor(logLevel: LogLevel) {
this._maxLevel = this._getNumericLevel(logLevel);
Expand Down Expand Up @@ -169,22 +179,23 @@ export class Logs {
}

private _getNumericLevel(level: LogLevel) {
switch (level) {
case LOG_LEVEL.FATAL:
return 0;
case LOG_LEVEL.ERROR:
return 1;
case LOG_LEVEL.INFO:
return 2;
case LOG_LEVEL.VERBOSE:
return 4;
case LOG_LEVEL.DEBUG:
return 5;
default:
return -1;
}
switch (level) {
case LOG_LEVEL.FATAL:
return 0;
case LOG_LEVEL.ERROR:
return 1;
case LOG_LEVEL.INFO:
return 2;
case LOG_LEVEL.VERBOSE:
return 4;
case LOG_LEVEL.DEBUG:
return 5;
case LOG_LEVEL.TRACE: // New log level
return 6; // Assign a higher numeric value
default:
return -1;
}
}
static convertErrorsIntoObjects(obj: unknown): Metadata | unknown {
// this is a utility function to render native errors in the console, the database, and on GitHub.
if (obj instanceof Error) {
Expand All @@ -199,7 +210,6 @@ export class Logs {
obj[key] = this.convertErrorsIntoObjects(obj[key]);
});
}

return obj;
return obj;
}
}

0 comments on commit 4d52c7c

Please sign in to comment.