Skip to content

Commit

Permalink
Merge pull request ubiquity-os#32 from ubq-testing/development
Browse files Browse the repository at this point in the history
fix: always return a LogReturn instead of null
  • Loading branch information
gentlementlegen authored Aug 21, 2024
2 parents d006c8c + c61e218 commit c3a3ddd
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ export class Logs {
private _maxLevel = -1;
static console: PrettyLogs;

private _log({ level, consoleLog, logMessage, metadata, type }: LogParams): LogReturn | null {
private _log({ level, consoleLog, logMessage, metadata, type }: LogParams): LogReturn {
// filter out more verbose logs according to maxLevel set in config
if (this._getNumericLevel(level) > this._maxLevel) return null;
if (this._getNumericLevel(level) <= this._maxLevel) {
consoleLog(logMessage, metadata);
}

consoleLog(logMessage, metadata);
return new LogReturn(
{
raw: logMessage,
Expand Down Expand Up @@ -45,7 +46,7 @@ export class Logs {
return metadata;
}

public ok(log: string, metadata?: Metadata): LogReturn | null {
public ok(log: string, metadata?: Metadata): LogReturn {
metadata = this._addDiagnosticInformation(metadata);
return this._log({
level: LOG_LEVEL.INFO,
Expand All @@ -56,7 +57,7 @@ export class Logs {
});
}

public info(log: string, metadata?: Metadata): LogReturn | null {
public info(log: string, metadata?: Metadata): LogReturn {
metadata = this._addDiagnosticInformation(metadata);
return this._log({
level: LOG_LEVEL.INFO,
Expand All @@ -67,7 +68,7 @@ export class Logs {
});
}

public error(log: string, metadata?: Metadata): LogReturn | null {
public error(log: string, metadata?: Metadata): LogReturn {
metadata = this._addDiagnosticInformation(metadata);
return this._log({
level: LOG_LEVEL.ERROR,
Expand All @@ -78,7 +79,7 @@ export class Logs {
});
}

public debug(log: string, metadata?: Metadata): LogReturn | null {
public debug(log: string, metadata?: Metadata): LogReturn {
metadata = this._addDiagnosticInformation(metadata);
return this._log({
level: LOG_LEVEL.DEBUG,
Expand All @@ -89,7 +90,7 @@ export class Logs {
});
}

public fatal(log: string, metadata?: Metadata): LogReturn | null {
public fatal(log: string, metadata?: Metadata): LogReturn {
if (!metadata) {
metadata = Logs.convertErrorsIntoObjects(new Error(log)) as Metadata;
const stack = metadata.stack as string[];
Expand All @@ -114,7 +115,7 @@ export class Logs {
});
}

public verbose(log: string, metadata?: Metadata): LogReturn | null {
public verbose(log: string, metadata?: Metadata): LogReturn {
metadata = this._addDiagnosticInformation(metadata);
return this._log({
level: LOG_LEVEL.VERBOSE,
Expand Down

0 comments on commit c3a3ddd

Please sign in to comment.