Skip to content

Commit

Permalink
fix: replace missing usage of new levels api
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoVazquez committed Jan 28, 2024
1 parent 13a4363 commit ee12776
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 162 deletions.
4 changes: 2 additions & 2 deletions packages/docs/lumberjack-docs-app/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class MyComponent implements OnInit {
// (...)
ngOnInit(): void {
this.#lumberjack.log({
level: LumberjackLevel.Info,
level: 'info',
message: 'Hello, World!',
scope: 'MyComponent',
createdAt: this.#time.getUnixEpochTicks(),
Expand All @@ -158,7 +158,7 @@ export class MyComponent implements OnInit {
}
```

> Each log level has its associated shorthand version: `LumberjackLevel.Info` is `logInfo`, `LumberjackLevel.Debug` is `logDebug`, etc.
> Each log level has its associated shorthand version: `'info'` is `logInfo`, `'debug'` is `logDebug`, etc.
### LumberjackModule and provideLumberjack

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { LumberjackLevel } from '@ngworker/lumberjack';

import { ErrorThrowingDriverConfig } from './error-throwing-driver.config';
import { ErrorThrowingDriver } from './error-throwing.driver';

export const defaultErrorThrowingDriverConfig: ErrorThrowingDriverConfig = {
logsBeforeThrowing: 0,
levels: [LumberjackLevel.Verbose],
levels: ['verbose'],
identifier: ErrorThrowingDriver.driverIdentifier,
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { TestBed } from '@angular/core/testing';

import { LumberjackLevel, LumberjackLogDriverConfig, lumberjackLogDriverConfigToken } from '@ngworker/lumberjack';
import { LumberjackLogDriverConfig, lumberjackLogDriverConfigToken } from '@ngworker/lumberjack';

import { lumberjackConsoleDriverConfigToken } from './lumberjack-console-driver-config.token';

const debugDriverConfig: LumberjackLogDriverConfig = {
levels: [LumberjackLevel.Debug],
levels: ['debug'],
identifier: 'TestConsoleDriver',
};
const verboseDriverConfig: Partial<LumberjackLogDriverConfig> = {
levels: [LumberjackLevel.Verbose],
levels: ['verbose'],
};

describe('consoleDriverConfigToken', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { TestBed } from '@angular/core/testing';
import { expectNgModuleToBeGuardedAgainstDirectImport } from '@internal/test-util';
import {
lumberjackConfigToken,
LumberjackLevel,
LumberjackLogDriver,
LumberjackLogDriverConfig,
lumberjackLogDriverToken,
Expand Down Expand Up @@ -49,7 +48,7 @@ describe(LumberjackConsoleDriverModule.name, () => {

it('registers the specified log driver configuration given the specified identifier', () => {
const expectedConfig: LumberjackLogDriverConfig = {
levels: [LumberjackLevel.Error],
levels: ['error'],
identifier: 'TestDriverIdentifier',
};

Expand All @@ -61,7 +60,7 @@ describe(LumberjackConsoleDriverModule.name, () => {

it('registers the specified log driver configuration given no identifier', () => {
const config: LumberjackConsoleDriverConfig = {
levels: [LumberjackLevel.Error],
levels: ['error'],
};
const expectedConfig: LumberjackLogDriverConfig = {
...config,
Expand All @@ -88,7 +87,7 @@ describe(LumberjackConsoleDriverModule.name, () => {

it('registers the specified log driver configuration when the Lumberjack module is imported after the console driver module', () => {
const expectedConfig: LumberjackLogDriverConfig = {
levels: [LumberjackLevel.Debug],
levels: ['debug'],
identifier: 'TestConsoleDriver',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { TestBed } from '@angular/core/testing';

import {
lumberjackConfigToken,
LumberjackLevel,
LumberjackLogDriver,
LumberjackLogDriverConfig,
lumberjackLogDriverToken,
Expand Down Expand Up @@ -43,7 +42,7 @@ describe(provideLumberjackConsoleDriver.name, () => {

it('registers the specified log driver configuration given the specified identifier', () => {
const expectedConfig: LumberjackLogDriverConfig = {
levels: [LumberjackLevel.Error],
levels: ['error'],
identifier: 'TestDriverIdentifier',
};

Expand All @@ -55,7 +54,7 @@ describe(provideLumberjackConsoleDriver.name, () => {

it('registers the specified log driver configuration given no identifier', () => {
const config: LumberjackConsoleDriverConfig = {
levels: [LumberjackLevel.Error],
levels: ['error'],
};
const expectedConfig: LumberjackLogDriverConfig = {
...config,
Expand All @@ -82,7 +81,7 @@ describe(provideLumberjackConsoleDriver.name, () => {

it('registers the specified log driver configuration when the Lumberjack module is imported after the console driver module', () => {
const expectedConfig: LumberjackLogDriverConfig = {
levels: [LumberjackLevel.Debug],
levels: ['debug'],
identifier: 'TestConsoleDriver',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { TestBed } from '@angular/core/testing';

import { provideSpyConsole, SpyConsole } from '@internal/console-driver/test-util';
import {
LumberjackLevel,
LumberjackLogDriver,
lumberjackLogDriverToken,
LumberjackLogFactory,
Expand All @@ -20,7 +19,7 @@ describe(LumberjackConsoleDriver.name, () => {
imports: [
LumberjackModule.forRoot(),
LumberjackConsoleDriverModule.forRoot({
levels: [LumberjackLevel.Verbose],
levels: ['verbose'],
identifier: LumberjackConsoleDriver.driverIdentifier,
}),
],
Expand All @@ -38,7 +37,7 @@ describe(LumberjackConsoleDriver.name, () => {
let spyLogger: SpyConsole;

it("logs the critical level to the console's error channel", () => {
const expectedMessage = LumberjackLevel.Critical;
const expectedMessage = 'critical';
const expectedLog = logFactory.createCriticalLog(expectedMessage).build();

driver.logCritical({ formattedLog: expectedMessage, log: expectedLog });
Expand All @@ -48,7 +47,7 @@ describe(LumberjackConsoleDriver.name, () => {
});

it("logs the debug level to the console's debug channel", () => {
const expectedMessage = LumberjackLevel.Debug;
const expectedMessage = 'debug';
const expectedLog = logFactory.createDebugLog(expectedMessage).build();

driver.logDebug({ formattedLog: expectedMessage, log: expectedLog });
Expand All @@ -58,7 +57,7 @@ describe(LumberjackConsoleDriver.name, () => {
});

it("logs the error level to the console's error channel", () => {
const expectedMessage = LumberjackLevel.Error;
const expectedMessage = 'error';
const expectedLog = logFactory.createErrorLog(expectedMessage).build();

driver.logError({ formattedLog: expectedMessage, log: expectedLog });
Expand All @@ -68,7 +67,7 @@ describe(LumberjackConsoleDriver.name, () => {
});

it("logs the info level to the console's info channel", () => {
const expectedMessage = LumberjackLevel.Info;
const expectedMessage = 'info';
const expectedLog = logFactory.createInfoLog(expectedMessage).build();

driver.logInfo({ formattedLog: expectedMessage, log: expectedLog });
Expand All @@ -78,7 +77,7 @@ describe(LumberjackConsoleDriver.name, () => {
});

it("logs the trace level to the console's trace channel", () => {
const expectedMessage = LumberjackLevel.Trace;
const expectedMessage = 'trace';
const expectedLog = logFactory.createTraceLog(expectedMessage).build();

driver.logTrace({ formattedLog: expectedMessage, log: expectedLog });
Expand All @@ -88,7 +87,7 @@ describe(LumberjackConsoleDriver.name, () => {
});

it("logs the warning level to the console's warn channel", () => {
const expectedMessage = LumberjackLevel.Warning;
const expectedMessage = 'warn';
const expectedLog = logFactory.createWarningLog(expectedMessage).build();

driver.logWarning({ formattedLog: expectedMessage, log: expectedLog });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { TestBed } from '@angular/core/testing';

import { expectNgModuleToBeGuardedAgainstDirectImport } from '@internal/test-util';
import {
ConfigLevels,
LumberjackConfigLevels,
LumberjackLevel,
LumberjackLogDriver,
lumberjackLogDriverToken,
LumberjackModule,
Expand All @@ -17,7 +17,7 @@ import { LumberjackHttpDriverModule } from './lumberjack-http-driver.module';
import { LumberjackHttpDriverOptions } from './lumberjack-http-driver.options';

function createHttpOptions(
extraOptions: { levels?: LumberjackConfigLevels; identifier?: string } = {}
extraOptions: { levels?: LumberjackConfigLevels | ConfigLevels; identifier?: string } = {}
): LumberjackHttpDriverOptions {
return {
origin: 'TEST_MODULE',
Expand All @@ -27,7 +27,10 @@ function createHttpOptions(
};
}

function createHttpConfig(levels: LumberjackConfigLevels, identifier?: string): LumberjackHttpDriverConfig {
function createHttpConfig(
levels: LumberjackConfigLevels | ConfigLevels,
identifier?: string
): LumberjackHttpDriverConfig {
const config = {
levels,
origin: 'TEST_MODULE',
Expand All @@ -51,7 +54,7 @@ const createHttpDriver = (
config: LumberjackHttpDriverConfig;
isLumberjackModuleImportedFirst?: boolean;
} = {
config: createHttpConfig([LumberjackLevel.Verbose], LumberjackHttpDriver.driverIdentifier),
config: createHttpConfig(['verbose'], LumberjackHttpDriver.driverIdentifier),
}
) => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -102,7 +105,7 @@ describe(LumberjackHttpDriverModule.name, () => {
});

it('registers the specified log driver configuration WITH a specified identifier', () => {
const expectedConfig = createHttpConfig([LumberjackLevel.Error], 'TestDriverIdentifier');
const expectedConfig = createHttpConfig(['error'], 'TestDriverIdentifier');

const httpDriver = createHttpDriver({ config: expectedConfig });

Expand All @@ -111,7 +114,7 @@ describe(LumberjackHttpDriverModule.name, () => {
});

it('registers the specified log driver configuration WITHOUT a specified identifier', () => {
const config = createHttpConfig([LumberjackLevel.Error]);
const config = createHttpConfig(['error']);
const expectedConfig = { ...config, identifier: LumberjackHttpDriver.driverIdentifier };
const httpDriver = createHttpDriver({ config });

Expand All @@ -120,7 +123,7 @@ describe(LumberjackHttpDriverModule.name, () => {
});

it('does register the specified log driver configuration when the lumberjack module is imported after the http driver module', () => {
const expectedConfig = createHttpConfig([LumberjackLevel.Debug], 'TestDriverIdentifier');
const expectedConfig = createHttpConfig(['debug'], 'TestDriverIdentifier');

const httpDriver = createHttpDriver({
config: expectedConfig,
Expand All @@ -147,14 +150,14 @@ describe(LumberjackHttpDriverModule.name, () => {
const actualConfig = httpDriver.config;
const expectedConfig: LumberjackHttpDriverInternalConfig = {
...options,
levels: [LumberjackLevel.Verbose],
levels: ['verbose'],
identifier: 'LumberjackHttpDriver',
};
expect(actualConfig).toEqual(expectedConfig);
});

it('registers the specified options with custom levels', () => {
const customLevels: LumberjackConfigLevels = [LumberjackLevel.Critical];
const customLevels: ConfigLevels = ['critical'];
const options = createHttpOptions({ levels: customLevels });

const httpDriver = createHttpDriverWithOptions({ options });
Expand All @@ -177,7 +180,7 @@ describe(LumberjackHttpDriverModule.name, () => {
const actualConfig = httpDriver.config;
const expectedConfig: LumberjackHttpDriverInternalConfig = {
...options,
levels: [LumberjackLevel.Verbose],
levels: ['verbose'],
identifier: customIdentifier,
};
expect(actualConfig).toEqual(expectedConfig);
Expand All @@ -189,7 +192,7 @@ describe(LumberjackHttpDriverModule.name, () => {
const httpDriver = createHttpDriverWithOptions({ options });

const { levels, identifier } = httpDriver.config;
expect(levels).toEqual([LumberjackLevel.Verbose]);
expect(levels).toEqual(['verbose']);
expect(identifier).toEqual(LumberjackHttpDriver.driverIdentifier);
});

Expand All @@ -204,7 +207,7 @@ describe(LumberjackHttpDriverModule.name, () => {
const actualConfig = httpDriver.config;
const expectedConfig: LumberjackHttpDriverInternalConfig = {
...options,
levels: [LumberjackLevel.Verbose],
levels: ['verbose'],
identifier: LumberjackHttpDriver.driverIdentifier,
};
expect(actualConfig).toEqual(expectedConfig);
Expand Down
Loading

0 comments on commit ee12776

Please sign in to comment.