Skip to content

Commit

Permalink
Merge pull request #39 from michaelcoxon/feature/logging-updates
Browse files Browse the repository at this point in the history
include args with logging
  • Loading branch information
michaelcoxon authored Feb 13, 2024
2 parents 671640c + 9fbb57f commit 5c7ffee
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 210 deletions.
19 changes: 11 additions & 8 deletions src/Enumerables/Enumerable.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { ArrayEnumerable, Enumerable } from '../../src/Enumerables';
import { getDefaultLogger } from '../../src/Logging/defaultLogger';

/*
setDefaultLogger(new ConsoleLogger(console, {
loggingVerbosity: LogLevel.Trace,
useTraceMethodForTraceLogLevel: false
}));
*/


// import ConsoleLogger from '../Logging/ConsoleLogger';
// import { LogLevel } from '../Logging/_types';
// import { getDefaultLogger, setDefaultLogger } from '../Logging/utils/defaultLogger';
// setDefaultLogger(new ConsoleLogger(console, {
// loggingVerbosity: LogLevel.Trace,
// useTraceMethodForTraceLogLevel: false
// }));

import { getDefaultLogger } from '../Logging/utils/defaultLogger';
const logger = getDefaultLogger();

describe("Enumerable", () =>
Expand Down
60 changes: 25 additions & 35 deletions src/Logging/AggregateLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,103 +12,93 @@ export default class AggregateLogger implements ILogger
}


debug(msg: string): void
debug(msg: string, ...args: unknown[]): void
{
for (const logger of this.#loggers) logger.debug(msg);
for (const logger of this.#loggers) logger.debug(msg, ...args);
}
debugError(err: Error): void;
debugError(err: Error, msg: string): void;
debugError(err: Error, msg?: string)
debugError(err: Error, msg?: string, ...args: unknown[])
{
for (const logger of this.#loggers)
{
if (msg)
{
logger.debugError(err, msg);
logger.debugError(err, msg, ...args);
}
else
{
logger.debugError(err);
logger.debugError(err, ...args);
}
}
}
error(msg: string): void
error(msg: string, ...args: unknown[]): void
{
for (const logger of this.#loggers) logger.error(msg);
for (const logger of this.#loggers) logger.error(msg, ...args);
}
errorError(err: Error): void;
errorError(err: Error, msg: string): void;
errorError(err: Error, msg?: string)
errorError(err: Error, msg?: string, ...args: unknown[])
{
for (const logger of this.#loggers)
{
if (msg)
{
logger.errorError(err, msg);
logger.errorError(err, msg, ...args);
}
else
{
logger.errorError(err);
logger.errorError(err, ...args);
}
}
}
info(msg: string): void
info(msg: string, ...args: unknown[]): void
{
for (const logger of this.#loggers) logger.info(msg);
for (const logger of this.#loggers) logger.info(msg, ...args);
}
infoError(err: Error): void;
infoError(err: Error, msg: string): void;
infoError(err: Error, msg?: string)
infoError(err: Error, msg?: string, ...args: unknown[])
{
for (const logger of this.#loggers)
{
if (msg)
{
logger.infoError(err, msg);
logger.infoError(err, msg, ...args);
}
else
{
logger.infoError(err);
logger.infoError(err, ...args);
}
}
}
trace(msg: string): void
trace(msg: string, ...args: unknown[]): void
{
for (const logger of this.#loggers) logger.trace(msg);
for (const logger of this.#loggers) logger.trace(msg, ...args);
}
traceError(err: Error): void;
traceError(err: Error, msg: string): void;
traceError(err: Error, msg?: string)
traceError(err: Error, msg?: string, ...args: unknown[])
{
for (const logger of this.#loggers)
{
if (msg)
{
logger.traceError(err, msg);
logger.traceError(err, msg, ...args);
}
else
{
logger.traceError(err);
logger.traceError(err, ...args);
}
}
}
warn(msg: string): void
warn(msg: string, ...args: unknown[]): void
{
for (const logger of this.#loggers) logger.warn(msg);
for (const logger of this.#loggers) logger.warn(msg, ...args);
}
warnError(err: Error): void;
warnError(err: Error, msg: string): void;
warnError(err: Error, msg?: string)
warnError(err: Error, msg?: string, ...args: unknown[])
{
for (const logger of this.#loggers)
{
if (msg)
{
logger.warnError(err, msg);
logger.warnError(err, msg, ...args);
}
else
{
logger.warnError(err);
logger.warnError(err, ...args);
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions src/Logging/ConsoleLogger.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { IConsole } from '../IConsole';
import ConsoleLogger from './ConsoleLogger';
import { LogLevel } from './_types';



describe("ConsoleLogger.constructor", () =>
{
it("should return a new ConsoleLogger", () =>
{
const actual = new ConsoleLogger(console);

expect(actual).not.toBeNull();
});
});

describe("ConsoleLogger.log", () =>
{
it("should always log", () =>
{
const consoleImpl: IConsole = {
log: jest.fn(_ => { })
};

const actual = new ConsoleLogger(consoleImpl, {
loggingVerbosity: LogLevel.Debug,
useTraceMethodForTraceLogLevel: true
});

actual.debug("");
actual.error("");
actual.info("");
actual.trace("");
actual.warn("");

expect(consoleImpl.log).toHaveBeenCalledTimes(5);
});
});
4 changes: 2 additions & 2 deletions src/Logger.spec.ts → src/Logging/Logger.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import testLogVerbosity from '../src/Logging/testLogVerbosity';
import { LogLevel } from '../src/Logging/_types';
import { LogLevel } from './_types';
import testLogVerbosity from './utils/testLogVerbosity';

function testLogVerbosityTest(expected: boolean, desiredLevel: LogLevel, loggingVerbosity: LogLevel)
{
Expand Down
Loading

0 comments on commit 5c7ffee

Please sign in to comment.