diff --git a/__tests__/Logger.test.ts b/__tests__/Logger.test.ts index 349f1b0e0..023a45eda 100644 --- a/__tests__/Logger.test.ts +++ b/__tests__/Logger.test.ts @@ -3,7 +3,6 @@ import type {Reactor} from "../src/core/internal"; import { App, Log, - LogLevel, loggingCLAType, booleanCLAType, stringCLAType, @@ -26,9 +25,9 @@ describe("Logger functions", function () { describe("Test for Logger", () => { it("DEBUG Log", () => { - Log.global.level = LogLevel.DEBUG; + Log.setLevel(Log.LogLevel.DEBUG); - console.log("Log level is " + Log.global.level); + console.log("Log level is " + Log.globalLogger.level); Log.getInstance("test module"); Log.debug(null, () => "test"); Log.debug(null, () => "test", "test module"); @@ -65,7 +64,7 @@ describe("Test for Logger", () => { expect(Log.log).toHaveBeenCalledTimes(2); expect(Log.warn).toHaveBeenCalledTimes(2); - console.log(Log.global.level); + console.log(Log.globalLogger.level); }); }); @@ -75,7 +74,7 @@ describe("Command Line Arguments Helper Functions Tests", () => { expect(loggingCLAType("")).toBeNull; }); test("log level check", () => { - expect(loggingCLAType("ERROR")).toBe(1); + expect(loggingCLAType("ERROR")).toBe(Log.LogLevel.ERROR.valueOf()); }); test("boolean test for command line argument parsing", () => { expect(booleanCLAType("true")).toBe(true); diff --git a/__tests__/OutputGet.test.ts b/__tests__/OutputGet.test.ts index 9ae98e4e3..70a1c9e71 100644 --- a/__tests__/OutputGet.test.ts +++ b/__tests__/OutputGet.test.ts @@ -12,9 +12,9 @@ class OutputGetTest extends App { failure: () => void ) { super(timeout, true, false, success, failure); - Log.global.debug(">>>>>>>>----" + this.util); + Log.globalLogger.debug(">>>>>>>>----" + this.util); this.addReaction([this.t], [this.writable(this.o)], function (this, o) { - Log.global.debug(">>>>>>>>>>being triggered>>>>>>>>>>>"); + Log.globalLogger.debug(">>>>>>>>>>being triggered>>>>>>>>>>>"); if (o.get() != null) { throw new Error( "Calling get on an output before it has been set does not return null" diff --git a/__tests__/dependencies.ts b/__tests__/dependencies.ts index d1ab0ae06..8c282df1c 100644 --- a/__tests__/dependencies.ts +++ b/__tests__/dependencies.ts @@ -145,7 +145,7 @@ describe("Manually constructed precedence graphs", () => { graph.removeNode(nodes[1]); expect(graph.size()[0]).toEqual(5); // V expect(graph.size()[1]).toEqual(3); // E - Log.global.debug(graph.toString()); + Log.globalLogger.debug(graph.toString()); expect(graph.toString()).toBe( dontIndent`graph 0["app.R[R3]"] @@ -165,7 +165,7 @@ describe("Manually constructed precedence graphs", () => { graph.addEdge(nodes[3], nodes[2]); expect(graph.size()[0]).toEqual(6); // V expect(graph.size()[1]).toEqual(4); // E - Log.global.debug(graph.toString()); + Log.globalLogger.debug(graph.toString()); expect(graph.toString()).toBe( dontIndent`graph 0["app.R[R3]"] @@ -195,7 +195,7 @@ describe("Manually constructed precedence graphs", () => { it("introduce a cycle", () => { graph.addEdge(nodes[2], nodes[5]); expect(graph.updatePriorities(false)).toBeFalsy(); - Log.global.debug(graph.toString()); + Log.globalLogger.debug(graph.toString()); }); }); @@ -217,18 +217,18 @@ describe("ReactionQ", () => { var reactionQ = new PrioritySet(); for (let i = 0; i < 6; i++) { - Log.global.debug( + Log.globalLogger.debug( "Pushing node: " + i + " with prio: " + nodes[i].getPriority() ); reactionQ.push(nodes[i]); } // duplicate insertions - Log.global.debug( + Log.globalLogger.debug( "Pushing duplicate node with prio: " + nodes[5].getPriority() ); reactionQ.push(nodes[5]); - Log.global.debug( + Log.globalLogger.debug( "Pushing duplicate node with prio: " + nodes[1].getPriority() ); reactionQ.push(nodes[1]); @@ -237,7 +237,7 @@ describe("ReactionQ", () => { const r = reactionQ.pop(); for (let i = 0; i < 6; i++) { if (Object.is(r, nodes[i])) { - Log.global.debug( + Log.globalLogger.debug( "Found matching node: " + i + " with prio: " + nodes[i].getPriority() ); } @@ -251,7 +251,7 @@ describe("ReactionQ", () => { for (let i = 0; i < 6; i++) { if (Object.is(r, nodes[i])) { - Log.global.debug( + Log.globalLogger.debug( "Found matching node: " + i + " with prio: " + nodes[i].getPriority() ); } @@ -264,7 +264,7 @@ describe("ReactionQ", () => { const r = reactionQ.pop(); for (let i = 0; i < 6; i++) { if (Object.is(r, nodes[i])) { - Log.global.debug( + Log.globalLogger.debug( "Found matching node: " + i + " with prio: " + nodes[i].getPriority() ); } @@ -277,7 +277,7 @@ describe("ReactionQ", () => { const r = reactionQ.pop(); for (let i = 0; i < 6; i++) { if (Object.is(r, nodes[i])) { - Log.global.debug( + Log.globalLogger.debug( "Found matching node: " + i + " with prio: " + nodes[i].getPriority() ); } @@ -290,7 +290,7 @@ describe("ReactionQ", () => { const r = reactionQ.pop(); for (let i = 0; i < 6; i++) { if (Object.is(r, nodes[i])) { - Log.global.debug( + Log.globalLogger.debug( "Found matching node: " + i + " with prio: " + nodes[i].getPriority() ); } @@ -303,7 +303,7 @@ describe("ReactionQ", () => { const r = reactionQ.pop(); for (let i = 0; i < 6; i++) { if (Object.is(r, nodes[i])) { - Log.global.debug( + Log.globalLogger.debug( "Found matching node: " + i + " with prio: " + nodes[i].getPriority() ); } diff --git a/__tests__/disconnect.test.ts b/__tests__/disconnect.test.ts index 0d90c64df..b25b31cb2 100644 --- a/__tests__/disconnect.test.ts +++ b/__tests__/disconnect.test.ts @@ -10,7 +10,6 @@ import { TimeValue, Origin, Log, - LogLevel, Action } from "../src/core/internal"; diff --git a/__tests__/mutations.test.ts b/__tests__/mutations.test.ts index 71d3a2894..090e90053 100644 --- a/__tests__/mutations.test.ts +++ b/__tests__/mutations.test.ts @@ -168,7 +168,7 @@ describe("Creating reactors at runtime", function () { jest.setTimeout(5000); it("Reactor with periodic timer", (done) => { - // Log.global.level = LogLevel.DEBUG + // Log.global.level = Log.LogLevel.DEBUG const app = new Zeno(TimeValue.secs(4), done, () => {}); @@ -181,7 +181,7 @@ describe("Creating reactors at runtime", function () { // jest.setTimeout(5000); // it("Simple scatter gather", done => { -// Log.global.level = LogLevel.DEBUG +// Log.global.level = Log.LogLevel.DEBUG // let app = new ScatterGather(TimeValue.secs(5), done, () => {}) diff --git a/__tests__/reactors.errors.test.ts b/__tests__/reactors.errors.test.ts index 446c89918..01c7bad98 100644 --- a/__tests__/reactors.errors.test.ts +++ b/__tests__/reactors.errors.test.ts @@ -6,8 +6,7 @@ import { InPort, TimeUnit, TimeValue, - Log, - LogLevel + Log } from "../src/core/internal"; class R extends Reactor { @@ -49,7 +48,7 @@ class R extends Reactor { } describe("Testing Error Cases", function () { - Log.global.level = LogLevel.DEBUG; + Log.setLevel(Log.LogLevel.DEBUG); it("Multiple reactions for a callee port", () => { var parent = new App(); diff --git a/__tests__/reactors.test.ts b/__tests__/reactors.test.ts index 051308956..eb91b4879 100644 --- a/__tests__/reactors.test.ts +++ b/__tests__/reactors.test.ts @@ -8,7 +8,6 @@ import { TimeValue, Origin, Log, - LogLevel, Action } from "../src/core/internal"; @@ -163,7 +162,7 @@ describe("Testing deadlines", function () { jest.setTimeout(5000); it("Missed reaction deadline on InPort", (done) => { - Log.global.level = LogLevel.WARN; + Log.setLevel(Log.LogLevel.WARN); function fail() { throw new Error("Test has failed."); @@ -187,7 +186,7 @@ describe("Testing deadlines", function () { it("Missed reaction deadline on the second reaction in the chain", (done) => { // let consoleOutput: string[] = [] - Log.global.level = LogLevel.WARN; + Log.setLevel(Log.LogLevel.WARN); function fail() { throw new Error("Test has failed."); @@ -219,7 +218,7 @@ describe("Testing deadlines", function () { }); it("Missed deadline with custom message", (done) => { - Log.global.level = LogLevel.WARN; + Log.setLevel(Log.LogLevel.WARN); // let deadlineMissed:string = "" @@ -233,7 +232,7 @@ describe("Testing deadlines", function () { done, fail, () => { - Log.global.warn("Deadline missed!"); + Log.warn(null, () => "Deadline missed!"); }, TimeValue.withUnits(1, TimeUnit.nsec) ); @@ -274,7 +273,7 @@ describe("Testing Reactions", function () { describe("Testing Actions", function () { it("Mismatched logical time", () => { - Log.global.level = LogLevel.WARN; + Log.setLevel(Log.LogLevel.WARN); function fail() { throw new Error("Test has failed."); diff --git a/src/benchmark/FacilityLocation.ts b/src/benchmark/FacilityLocation.ts index d8395e652..bf72e0bd0 100644 --- a/src/benchmark/FacilityLocation.ts +++ b/src/benchmark/FacilityLocation.ts @@ -18,7 +18,7 @@ import { App } from "../core/internal"; -Log.global.level = Log.levels.INFO; +Log.setLevel(Log.LogLevel.INFO); class Point { x: number; diff --git a/src/benchmark/PingPong.ts b/src/benchmark/PingPong.ts index 3668e7c48..17e187f89 100644 --- a/src/benchmark/PingPong.ts +++ b/src/benchmark/PingPong.ts @@ -9,7 +9,7 @@ import { App } from "../core/internal"; -Log.global.level = Log.levels.ERROR; +Log.setLevel(Log.LogLevel.DEBUG); export class Ping extends Reactor { count: Parameter; diff --git a/src/benchmark/Sieve.ts b/src/benchmark/Sieve.ts index 436936e9e..4b88776ed 100644 --- a/src/benchmark/Sieve.ts +++ b/src/benchmark/Sieve.ts @@ -12,7 +12,7 @@ import { Log } from "../core/internal"; -Log.global.level = Log.levels.INFO; +Log.setLevel(Log.LogLevel.INFO); class Ramp extends Reactor { next: Action; diff --git a/src/core/cli.ts b/src/core/cli.ts index 65b1ada43..5042a9e7e 100644 --- a/src/core/cli.ts +++ b/src/core/cli.ts @@ -1,4 +1,4 @@ -import {TimeUnit, TimeValue, LogLevel} from "./internal"; +import {TimeUnit, TimeValue, Log} from "./internal"; // ---------------------------------------------------------------------// // Command Line Arguments Helper Functions // @@ -9,10 +9,10 @@ import {TimeUnit, TimeValue, LogLevel} from "./internal"; * Returns null if the input is malformed. * @param logging the raw command line argument */ -export function loggingCLAType(logging: string): LogLevel | null { - if (logging in LogLevel) { - type LevelString = keyof typeof LogLevel; - return LogLevel[logging as LevelString]; +export function loggingCLAType(logging: string): Log.LogLevel | null { + if (logging in Log.LogLevel) { + type LevelString = keyof typeof Log.LogLevel; + return Log.LogLevel[logging as LevelString]; } else { return null; } @@ -94,7 +94,7 @@ export interface ProcessedCommandLineArgs { keepalive: boolean | undefined; advanceMessageInterval: TimeValue | undefined; timeout: TimeValue | null | undefined; - logging: LogLevel | undefined; + logging: Log.LogLevel | undefined; id: string | undefined; help: boolean; } diff --git a/src/core/federation.ts b/src/core/federation.ts index 6de896547..2f1ea7b25 100644 --- a/src/core/federation.ts +++ b/src/core/federation.ts @@ -1318,7 +1318,7 @@ export class FederatedApp extends App { // Ignore federatate's _shutdown call if stop is requested. // The final shutdown should be done by calling super._shutdown. if (this.stopRequestInfo.state !== StopRequestState.NOT_SENT) { - Log.global.debug( + Log.globalLogger.debug( "Ignoring FederatedApp._shutdown() as stop is already requested to RTI." ); return; @@ -1330,7 +1330,7 @@ export class FederatedApp extends App { ) { this.sendRTIStopRequest(this.util.getCurrentTag().getMicroStepsLater(1)); } else { - Log.global.debug( + Log.globalLogger.debug( "Ignoring FederatedApp._shutdown() since EndOfExecution is already set earlier than current tag." + `currentTag: ${this.util.getCurrentTag()} endTag: ${String(endTag)}` ); @@ -1396,7 +1396,7 @@ export class FederatedApp extends App { "received from the RTI is less than the timestamp of the " + "next event on the event queue" ); - Log.global.debug("Exiting _next."); + Log.globalLogger.debug("Exiting _next."); return false; } } @@ -1426,7 +1426,7 @@ export class FederatedApp extends App { throw e; } } else { - Log.global.debug( + Log.globalLogger.debug( "Max level allowed to advance is higher than the next reaction's priority." ); return false; @@ -1437,7 +1437,7 @@ export class FederatedApp extends App { // network inputs. return false; } - Log.global.debug("Finished handling all events at current time."); + Log.globalLogger.debug("Finished handling all events at current time."); return true; } diff --git a/src/core/graph.ts b/src/core/graph.ts index 3a3a72ae2..5a61f53bf 100644 --- a/src/core/graph.ts +++ b/src/core/graph.ts @@ -279,7 +279,7 @@ export class PrecedenceGraph { // Start a new line when this is not the first match, // or when the current node is a start node. chain = []; - Log.global.debug("Starting new chain."); + Log.globalLogger.debug("Starting new chain."); } // Mark current node as visited. @@ -288,13 +288,13 @@ export class PrecedenceGraph { chain.push(node); if (chain.includes(v)) { - Log.global.debug("Cycle detected."); + Log.globalLogger.debug("Cycle detected."); printChain(v, chain); } else if (visited.has(v)) { - Log.global.debug("Overlapping chain detected."); + Log.globalLogger.debug("Overlapping chain detected."); printChain(v, chain); } else { - Log.global.debug("Adding link to the chain."); + Log.globalLogger.debug("Adding link to the chain."); buildChain(v, chain); } // Indicate that a match has been found. @@ -302,7 +302,7 @@ export class PrecedenceGraph { } } if (!match) { - Log.global.debug("End of chain."); + Log.globalLogger.debug("End of chain."); printChain(node, chain); } } diff --git a/src/core/reaction.ts b/src/core/reaction.ts index 2dc06580e..1eb2e4446 100644 --- a/src/core/reaction.ts +++ b/src/core/reaction.ts @@ -66,7 +66,7 @@ export class Reaction private readonly react: (...args: ArgList) => void, private deadline?: TimeValue, private readonly late: (...args: ArgList) => void = () => { - Log.global.warn("Deadline violation occurred!"); + Log.globalLogger.warn("Deadline violation occurred!"); } ) {} diff --git a/src/core/reactor.ts b/src/core/reactor.ts index 806bf2af7..075e863ac 100644 --- a/src/core/reactor.ts +++ b/src/core/reactor.ts @@ -48,7 +48,7 @@ import {v4 as uuidv4} from "uuid"; import {Bank} from "./bank"; // Set the default log level. -Log.global.level = Log.levels.ERROR; +Log.setLevel(Log.LogLevel.ERROR); // --------------------------------------------------------------------------// // Interfaces // @@ -784,7 +784,7 @@ export abstract class Reactor extends Component { react: (this: ReactionSandbox, ...args: ArgList) => void, deadline?: TimeValue, late: (this: ReactionSandbox, ...args: ArgList) => void = () => { - Log.global.warn("Deadline violation occurred!"); + Log.globalLogger.warn("Deadline violation occurred!"); } ): void { const calleePorts = trigs.filter((trig) => trig instanceof CalleePort); @@ -843,7 +843,7 @@ export abstract class Reactor extends Component { react: (this: MutationSandbox, ...args: ArgList) => void, deadline?: TimeValue, late: (this: MutationSandbox, ...args: ArgList) => void = () => { - Log.global.warn("Deadline violation occurred!"); + Log.globalLogger.warn("Deadline violation occurred!"); } ): void { const mutation = new Mutation( @@ -2296,7 +2296,7 @@ export class App extends Reactor { throw e; } } - Log.global.debug("Finished handling all events at current time."); + Log.globalLogger.debug("Finished handling all events at current time."); return true; } @@ -2447,19 +2447,19 @@ export class App extends Reactor { this._finish(); } else { if (nextEvent != null) { - Log.global.debug("Event queue not empty."); + Log.globalLogger.debug("Event queue not empty."); this._setAlarmOrYield(nextEvent.tag); } else { // The queue is empty, and no end of execution has been specified. if (this._keepAlive) { // Keep alive: snooze and wake up later. - Log.global.debug("Going to sleep."); + Log.globalLogger.debug("Going to sleep."); this.snooze .asSchedulable(this._getKey(this.snooze)) .schedule(this._advanceMessageInterval, this._currentTag); } else { // Don't keep alive: initiate shutdown. - Log.global.debug("Initiating shutdown."); + Log.globalLogger.debug("Initiating shutdown."); this._shutdown(); } } @@ -2544,7 +2544,7 @@ export class App extends Reactor { this.schedulable(this.shutdown).schedule(0, null); } else { - Log.global.debug( + Log.globalLogger.debug( "Ignoring App._shutdown() call after shutdown has already started." ); } @@ -2615,9 +2615,9 @@ export class App extends Reactor { protected _analyzeDependencies(): void { Log.info(this, () => Log.hr); const initStart = getCurrentPhysicalTime(); - Log.global.info(">>> Initializing"); + Log.globalLogger.info(">>> Initializing"); - Log.global.debug("Initiating startup sequence."); + Log.globalLogger.debug("Initiating startup sequence."); // Obtain the precedence graph, ensure it has no cycles, // and assign a priority to each reaction in the graph. @@ -2634,7 +2634,7 @@ export class App extends Reactor { Log.debug(this, () => "After collapse: " + collapsed.toString()); if (collapsed.updatePriorities(true)) { - Log.global.debug("No cycles."); + Log.globalLogger.debug("No cycles."); } else { throw new Error("Cycle in reaction graph."); } diff --git a/src/core/util.ts b/src/core/util.ts index 312ea63e9..af780926d 100644 --- a/src/core/util.ts +++ b/src/core/util.ts @@ -1,4 +1,4 @@ -import pino, { type Logger } from "pino"; +import pino, {type Logger} from "pino"; /** * Utilities for the reactor runtime. @@ -6,185 +6,155 @@ import pino, { type Logger } from "pino"; * @author Marten Lohstroh (marten@berkeley.edu) */ -/** - * Log levels for `Log`. - * This LogLevel is inherited from ULog and is kept for compatibility/abstraction purposes. - * As we switch to pinojs, it adds `fatal` but lacks `log`. - * @see Log - */ -export enum LogLevel { - FATAL = "fatal", - ERROR = "error", - WARN = "warn", - INFO = "info", - LOG = "info", - DEBUG = "debug" -} - /** * Global logging facility that has multiple levels of severity. */ -// eslint-disable-next-line @typescript-eslint/no-extraneous-class -export class Log { +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace Log { /** - * Available log levels. + * Log levels for `Log`. + * This LogLevel is inherited from ULog and is kept for compatibility/abstraction purposes. + * As we switch to pinojs, it adds `fatal` but lacks `log`. + * @see Log */ - public static levels = LogLevel; + export enum LogLevel { + FATAL = "fatal", + ERROR = "error", + WARN = "warn", + INFO = "info", + DEBUG = "debug" + } /** * Global instance of ulog that performs the logging. */ - public static global = pino({ - name: "reactor-ts", + export const globalLogger = pino({ + name: "reactor-ts" }); /** * Horizontal rule. */ - public static hr = "=".repeat(80); + export const hr = "=".repeat(80); /** * Map that keeps track of active loggers. */ - private static readonly loggers = new Map(); + const loggers = new Map(); /** * Get the logger instance associated with the given module. * If it does not exist, it is created. * @param module The name associated with the logger */ - public static getInstance(module: string): Logger { - let logger = Log.loggers.get(module); + export function getInstance(module: string): Logger { + let logger = loggers.get(module); if (logger == null) { - logger = this.global.child({module}); - Log.loggers.set(module, logger); + logger = globalLogger.child({module}); + loggers.set(module, logger); } return logger; } + export function setLevel(severity: LogLevel, module?: string): void { + if (module != null) { + const logger = loggers.get(module); + if (logger != null) { + logger.level = severity.valueOf(); + } + return; + } + globalLogger.level = severity.valueOf(); + } + /** - * Log a message with severity `LogLevel.DEBUG`. The `message` callback + * Log a message with severity `severity`. The `message` callback * is only invoked if the ulog instance has a log level higher than - * `LogLevel.DEBUG`. + * `severity`. * @param obj The object to call the message callback on. * @param message Callback that returns a message string. * @param module The name associated with the logger. * @see LogLevel */ - public static debug( + const logWithSeverity = ( + severity: LogLevel, obj: unknown, message: () => string, module?: string - ): void { - if (module != null) { - if (Log.global.level >= LogLevel.DEBUG) { - Log.getInstance(module).debug(message.call(obj)); + ): void => { + const logger = module != null ? getInstance(module) : globalLogger; + if (!logger.isLevelEnabled(severity.valueOf())) { + return; + } + switch (severity) { + case LogLevel.FATAL: { + logger.fatal(message.call(obj)); + break; + } + case LogLevel.ERROR: { + logger.error(message.call(obj)); + break; } - } else { - if (Log.global.level >= LogLevel.DEBUG) { - Log.global.debug(message.call(obj)); + case LogLevel.WARN: { + logger.warn(message.call(obj)); + break; + } + case LogLevel.INFO: { + logger.info(message.call(obj)); + break; + } + case LogLevel.DEBUG: { + logger.debug(message.call(obj)); + break; } } + }; + + export function fatal( + obj: unknown, + message: () => string, + module?: string + ): void { + logWithSeverity(LogLevel.FATAL, obj, message, module); } - /** - * Log a message with severity `LogLevel.ERROR`. The `message` callback - * is only invoked if the ulog instance has a log level higher than - * `LogLevel.ERROR`. - * @param obj The object to call the message callback on. - * @param message Callback that returns a message string. - * @param module The name associated with the logger. - * @see LogLevel - */ - public static error( + export function error( obj: unknown, message: () => string, module?: string ): void { - if (module != null) { - if (Log.global.level >= LogLevel.ERROR) { - Log.getInstance(module).error(message.call(obj)); - } - } else { - if (Log.global.level >= LogLevel.ERROR) { - // Log.global.error(message.call(obj)); - console.error(message.call(obj)); - } - } + logWithSeverity(LogLevel.ERROR, obj, message, module); } - /** - * Log a message with severity `LogLevel.INFO`. The `message` callback - * is only invoked if the ulog instance has a log level higher than - * `LogLevel.INFO`. - * @param obj The object to call the message callback on. - * @param message Callback that returns a message string. - * @param module The name associated with the logger. - * @see LogLevel - */ - public static info( + export function warn( obj: unknown, message: () => string, module?: string ): void { - if (module != null) { - if (Log.global.level >= LogLevel.INFO) { - Log.getInstance(module).info(message.call(obj)); - } - } else { - if (Log.global.level >= LogLevel.INFO) { - Log.global.info(message.call(obj)); - } - } + logWithSeverity(LogLevel.WARN, obj, message, module); + } + + export function info( + obj: unknown, + message: () => string, + module?: string + ): void { + logWithSeverity(LogLevel.INFO, obj, message, module); } - /** - * Log a message with severity `LogLevel.LOG`. The `message` callback - * is only invoked if the ulog instance has a log level higher than - * `LogLevel.LOG`. - * @param obj The object to call the message callback on. - * @param message Callback that returns a message string. - * @param module The name associated with the logger. - * @see LogLevel - */ - public static log( + export function log( obj: unknown, message: () => string, module?: string ): void { - if (module != null) { - if (Log.global.level >= LogLevel.LOG) { - Log.getInstance(module).info(message.call(obj)); - } - } else { - if (Log.global.level >= LogLevel.LOG) { - Log.global.info(message.call(obj)); - } - } + logWithSeverity(LogLevel.INFO, obj, message, module); } - /** - * Log a message with severity `LogLevel.WARN`. The `message` callback - * is only invoked if the ulog instance has a log level higher than - * `LogLevel.WARN`. - * @param obj The object to call the message callback on. - * @param message Callback that returns a message string. - * @param module The name associated with the logger. - * @see LogLevel - */ - public static warn( + export function debug( obj: unknown, message: () => string, module?: string ): void { - if (module != null) { - if (Log.global.level >= LogLevel.WARN) { - Log.getInstance(module).warn(message.call(obj)); - } - } else { - if (Log.global.level >= LogLevel.WARN) { - Log.global.warn(message.call(obj)); - } - } + logWithSeverity(LogLevel.DEBUG, obj, message, module); } }