Skip to content

Commit

Permalink
feat!: remove deprecated enum levels
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoVazquez committed Nov 26, 2024
1 parent 762206f commit eaddd72
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 188 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { TestBed } from '@angular/core/testing';

import {
LogLevel,
LumberjackLevel,
LumberjackLogDriver,
LumberjackLogDriverLog,
lumberjackLogDriverToken,
Expand Down Expand Up @@ -33,26 +31,20 @@ describe(ErrorThrowingDriver.name, () => {
}

describe.each([
[LumberjackLevel.Critical, (driver) => driver.logCritical],
[LumberjackLevel.Debug, (driver) => driver.logDebug],
[LumberjackLevel.Error, (driver) => driver.logError],
[LumberjackLevel.Info, (driver) => driver.logInfo],
[LumberjackLevel.Trace, (driver) => driver.logTrace],
[LumberjackLevel.Warning, (driver) => driver.logWarning],
['critical', (driver) => driver.logCritical],
['debug', (driver) => driver.logDebug],
['error', (driver) => driver.logError],
['info', (driver) => driver.logInfo],
['trace', (driver) => driver.logTrace],
['warn', (driver) => driver.logWarning],
] as ReadonlyArray<[LumberjackLogLevel | LogLevel, (driver: LumberjackLogDriver) => (driverLog: LumberjackLogDriverLog) => void]>)(
] as ReadonlyArray<[LumberjackLogLevel, (driver: LumberjackLogDriver) => (driverLog: LumberjackLogDriverLog) => void]>)(
`implements a spy when using the %s log level`,
(logLevel, logMethod) => {
it('throws an error on first log when the default log driver configuration is used', () => {
const { driver } = setup();
const driverLog = createDriverLog(logLevel, logLevel, '', 'ErrorThrowingDriverDefaultTest');

expect(() => logMethod(driver).call(driver, driverLog)).toThrowError();
expect(() => logMethod(driver).call(driver, driverLog)).toThrow();
});

describe.each([0, 1, 2, 3])(
Expand All @@ -64,7 +56,7 @@ describe(ErrorThrowingDriver.name, () => {
const act = () => logMethod(driver).call(driver, driverLog);
repeatSideEffect(logsBeforeThrowing, act);

expect(act).toThrowError();
expect(act).toThrow();
});
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TestBed } from '@angular/core/testing';

import {
LogLevel,
LumberjackLogDriverLog,
LumberjackLogLevel,
LumberjackLogPayload,
Expand All @@ -10,7 +9,7 @@ import {

export const createDriverLog = <TPayload extends LumberjackLogPayload | void = void>(
formattedLog: string,
level: LumberjackLogLevel | LogLevel,
level: LumberjackLogLevel,
message = '',
scope = 'Test',
payload?: TPayload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { TestBed } from '@angular/core/testing';

import { createDriverLog, provideObjectDriver } from '@internal/test-util';
import {
LogLevel,
LumberjackLevel,
LumberjackLogDriver,
LumberjackLogDriverLog,
lumberjackLogDriverToken,
Expand All @@ -30,19 +28,13 @@ describe(ObjectDriver.name, () => {
});

describe.each([
[LumberjackLevel.Critical, (driver) => driver.logCritical, { isWorking: true }],
[LumberjackLevel.Debug, (driver) => driver.logDebug, { isWorking: false }],
[LumberjackLevel.Error, (driver) => driver.logError, undefined],
[LumberjackLevel.Info, (driver) => driver.logInfo, { isWorking: true }],
[LumberjackLevel.Trace, (driver) => driver.logTrace, { isWorking: false }],
[LumberjackLevel.Warning, (driver) => driver.logWarning, undefined],
['critical', (driver) => driver.logCritical, { isWorking: true }],
['debug', (driver) => driver.logDebug, { isWorking: false }],
['error', (driver) => driver.logError, undefined],
['info', (driver) => driver.logInfo, { isWorking: true }],
['trace', (driver) => driver.logTrace, { isWorking: false }],
['warn', (driver) => driver.logWarning, undefined],
] as ReadonlyArray<[LumberjackLogLevel | LogLevel, (driver: LumberjackLogDriver<ObjectPayload>) => (driverLog: LumberjackLogDriverLog<ObjectPayload>) => void, ObjectPayload | undefined]>)(
] as ReadonlyArray<[LumberjackLogLevel, (driver: LumberjackLogDriver<ObjectPayload>) => (driverLog: LumberjackLogDriverLog<ObjectPayload>) => void, ObjectPayload | undefined]>)(
`delegates to ${ObjectService.name} when using the %s log level`,
(logLevel, logMethod, expectedPayload) => {
it(`forwards the log payload to the ${ObjectService.prototype.log.name} method`, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { TestBed } from '@angular/core/testing';

import {
LogLevel,
LumberjackLevel,
LumberjackLogDriver,
LumberjackLogDriverLog,
lumberjackLogDriverToken,
Expand All @@ -27,19 +25,13 @@ describe(SpyDriver.name, () => {
});

describe.each([
[LumberjackLevel.Critical, (driver) => driver.logCritical],
[LumberjackLevel.Debug, (driver) => driver.logDebug],
[LumberjackLevel.Error, (driver) => driver.logError],
[LumberjackLevel.Info, (driver) => driver.logInfo],
[LumberjackLevel.Trace, (driver) => driver.logTrace],
[LumberjackLevel.Warning, (driver) => driver.logWarning],
['critical', (driver) => driver.logCritical],
['debug', (driver) => driver.logDebug],
['error', (driver) => driver.logError],
['info', (driver) => driver.logInfo],
['trace', (driver) => driver.logTrace],
['warn', (driver) => driver.logWarning],
] as ReadonlyArray<[LumberjackLogLevel | LogLevel, (driver: LumberjackLogDriver<void>) => (driverLog: LumberjackLogDriverLog<void>) => void]>)(
] as ReadonlyArray<[LumberjackLogLevel, (driver: LumberjackLogDriver<void>) => (driverLog: LumberjackLogDriverLog<void>) => void]>)(
`implements a spy when using the %s log level`,
(logLevel, logMethod) => {
it('records calls', () => {
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 { HttpHandlerFn, HttpRequest, withInterceptors } from '@angular/common/http';

import {
ConfigLevels,
LumberjackConfigLevels,
LumberjackLogDriver,
lumberjackLogDriverToken,
Expand All @@ -23,7 +22,7 @@ import { LumberjackHttpDriverInternalConfig } from './lumberjack-http-driver-int
import { LumberjackHttpDriverOptions } from './lumberjack-http-driver.options';

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

function createHttpConfig(
levels: LumberjackConfigLevels | ConfigLevels,
identifier?: string
): LumberjackHttpDriverConfig {
function createHttpConfig(levels: LumberjackConfigLevels, identifier?: string): LumberjackHttpDriverConfig {
const config: Writable<LumberjackHttpDriverConfig> = {
levels,
origin: 'TEST_MODULE',
Expand Down Expand Up @@ -169,7 +165,7 @@ describe(provideLumberjackHttpDriver.name, () => {
});

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

const httpDriver = createHttpDriverWithOptions({ options });
Expand Down Expand Up @@ -228,7 +224,7 @@ describe(provideLumberjackHttpDriver.name, () => {
it('does register the specified log driver options WITH HttpClient features', () => {
const testInterceptor = jest.fn((req, next) => next(req));
const features: HttpClientFeatures = [withInterceptors([testInterceptor])];
const customLevels: ConfigLevels = ['critical'];
const customLevels: LumberjackConfigLevels = ['critical'];
const options = createHttpOptions({ levels: customLevels });

const httpDriver = createHttpDriverWithOptions({ options, features });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { VERSION } from '@angular/platform-browser';

import { createCriticalDriverLog, createDriverLog, repeatSideEffect } from '@internal/test-util';
import {
LogLevel,
LumberjackLevel,
LumberjackLogDriver,
LumberjackLogDriverLog,
lumberjackLogDriverToken,
Expand Down Expand Up @@ -104,19 +102,13 @@ describe(LumberjackHttpDriver.name, () => {
});

describe.each([
[LumberjackLevel.Critical, (driver) => driver.logCritical],
[LumberjackLevel.Debug, (driver) => driver.logDebug],
[LumberjackLevel.Error, (driver) => driver.logError],
[LumberjackLevel.Info, (driver) => driver.logInfo],
[LumberjackLevel.Trace, (driver) => driver.logTrace],
[LumberjackLevel.Warning, (driver) => driver.logWarning],
['critical', (driver) => driver.logCritical],
['debug', (driver) => driver.logDebug],
['error', (driver) => driver.logError],
['info', (driver) => driver.logInfo],
['trace', (driver) => driver.logTrace],
['warn', (driver) => driver.logWarning],
] as ReadonlyArray<[LumberjackLogLevel | LogLevel, (driver: LumberjackLogDriver<HttpDriverPayload>) => (driverLog: LumberjackLogDriverLog<HttpDriverPayload>) => void]>)(
] as ReadonlyArray<[LumberjackLogLevel, (driver: LumberjackLogDriver<HttpDriverPayload>) => (driverLog: LumberjackLogDriverLog<HttpDriverPayload>) => void]>)(
'logs to a web API using the %s log level',
(logLevel, logMethod) => {
it('sends the driver log to the configured URL', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/ngworker/lumberjack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export { LumberjackLogFactory } from './lib/logging/lumberjack-log-factory';
export { LumberjackLogBuilder } from './lib/logging/lumberjack-log.builder';

// Logs
export { LumberjackConfigLevels, ConfigLevels } from './lib/logs/lumberjack-config-levels';
export { LumberjackLevel, Level } from './lib/logs/lumberjack-level';
export { LumberjackConfigLevels } from './lib/logs/lumberjack-config-levels';
export { LumberjackLevel } from './lib/logs/lumberjack-level';
export { LumberjackLog } from './lib/logs/lumberjack.log';
export { LumberjackLogLevel, LogLevel } from './lib/logs/lumberjack-log-level';
export { LumberjackLogLevel } from './lib/logs/lumberjack-log-level';
export { LumberjackLogPayload } from './lib/logs/lumberjack-log-payload';

// Time
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ConfigLevels, LumberjackConfigLevels } from '../logs/lumberjack-config-levels';
import { LumberjackConfigLevels } from '../logs/lumberjack-config-levels';

export const defaultDevelopmentLevels: LumberjackConfigLevels | ConfigLevels = ['verbose'];
export const defaultDevelopmentLevels: LumberjackConfigLevels = ['verbose'];
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ConfigLevels, LumberjackConfigLevels } from '../logs/lumberjack-config-levels';
import { LumberjackConfigLevels } from '../logs/lumberjack-config-levels';

export const defaultProductionLevels: LumberjackConfigLevels | ConfigLevels = ['critical', 'error', 'info', 'warn'];
export const defaultProductionLevels: LumberjackConfigLevels = ['critical', 'error', 'info', 'warn'];
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConfigLevels, LumberjackConfigLevels } from '../logs/lumberjack-config-levels';
import { LumberjackConfigLevels } from '../logs/lumberjack-config-levels';

/**
* Settings for a log driver.
Expand All @@ -9,7 +9,7 @@ export interface LumberjackLogDriverConfig {
*
* `['verbose']` indicates that all log levels are allowed.
*/
readonly levels: LumberjackConfigLevels | ConfigLevels;
readonly levels: LumberjackConfigLevels;

/**
* Driver Identifier, necessary for driver filtering.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConfigLevels, LumberjackConfigLevels } from '../logs/lumberjack-config-levels';
import { LumberjackConfigLevels } from '../logs/lumberjack-config-levels';
import { LumberjackLogPayload } from '../logs/lumberjack-log-payload';

import { LumberjackFormatFunction } from './lumberjack-format-function';
Expand All @@ -15,5 +15,5 @@ export interface LumberjackConfig<TPayload extends LumberjackLogPayload | void =
/**
* The default log level filter.
*/
readonly levels: LumberjackConfigLevels | ConfigLevels;
readonly levels: LumberjackConfigLevels;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { TestBed } from '@angular/core/testing';

import { LumberjackLogFactory } from '../logging/lumberjack-log-factory';
import { LumberjackLogBuilder } from '../logging/lumberjack-log.builder';
import { LumberjackLevel } from '../logs/lumberjack-level';
import { LogLevel, LumberjackLogLevel } from '../logs/lumberjack-log-level';
import { LumberjackLogLevel } from '../logs/lumberjack-log-level';
import { LumberjackLog } from '../logs/lumberjack.log';
import { LumberjackTimeService } from '../time/lumberjack-time.service';
import { provideLumberjack } from '../configuration/provide-lumberjack';
Expand Down Expand Up @@ -38,20 +37,7 @@ describe(lumberjackFormatLog.name, () => {
let logFactory: LumberjackLogFactory;

describe('Log level', () => {
const logLevels: (LumberjackLogLevel | LogLevel)[] = [
LumberjackLevel.Critical,
LumberjackLevel.Debug,
LumberjackLevel.Error,
LumberjackLevel.Info,
LumberjackLevel.Trace,
LumberjackLevel.Warning,
'critical',
'debug',
'error',
'info',
'trace',
'warn',
];
const logLevels: LumberjackLogLevel[] = ['critical', 'debug', 'error', 'info', 'trace', 'warn'];

logLevels.forEach((expectedLevel) => {
it(`prefixes the message with log level "${expectedLevel}"`, () => {
Expand All @@ -78,7 +64,7 @@ describe(lumberjackFormatLog.name, () => {
it('adds the 0 hours UTC offset with milliseconds resolution', () => {
const log: LumberjackLog = {
createdAt: unixEpochTicks,
level: LumberjackLevel.Debug,
level: 'debug',
message: 'Timestamp test',
scope: 'Timestamp',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { TestBed } from '@angular/core/testing';

import { FakeTimeService } from '@internal/test-util';

import { LumberjackLevel } from '../logs/lumberjack-level';
import { LogLevel, LumberjackLogLevel } from '../logs/lumberjack-log-level';
import { LumberjackLogLevel } from '../logs/lumberjack-log-level';
import { LumberjackLogPayload } from '../logs/lumberjack-log-payload';
import { LumberjackLog } from '../logs/lumberjack.log';
import { LumberjackTimeService } from '../time/lumberjack-time.service';
Expand All @@ -14,12 +13,7 @@ interface TestPayload extends LumberjackLogPayload {
testProperty: string;
}

const lumberjackLogLevels: (LumberjackLogLevel | LogLevel)[] = [
LumberjackLevel.Critical,
LumberjackLevel.Error,
'critical',
'error',
];
const lumberjackLogLevels: LumberjackLogLevel[] = ['critical', 'error'];

describe(LumberjackLogBuilder.name, () => {
const testMessage = 'Test Message';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LogLevel, LumberjackLogLevel } from '../logs/lumberjack-log-level';
import { LumberjackLogLevel } from '../logs/lumberjack-log-level';
import { LumberjackLogPayload } from '../logs/lumberjack-log-payload';
import { LumberjackLog } from '../logs/lumberjack.log';
import { LumberjackTimeService } from '../time/lumberjack-time.service';
Expand All @@ -18,7 +18,7 @@ export class LumberjackLogBuilder<TPayload extends LumberjackLogPayload | void =
#payload?: TPayload;
#scope?: string;
readonly #time: LumberjackTimeService;
readonly #level: LumberjackLogLevel | LogLevel;
readonly #level: LumberjackLogLevel;
readonly #message: string;

/**
Expand All @@ -28,7 +28,7 @@ export class LumberjackLogBuilder<TPayload extends LumberjackLogPayload | void =
* @param level The log level.
* @param message The log message.
*/
constructor(time: LumberjackTimeService, level: LumberjackLogLevel | LogLevel, message: string) {
constructor(time: LumberjackTimeService, level: LumberjackLogLevel, message: string) {
this.#time = time;
this.#level = level;
this.#message = message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TestBed } from '@angular/core/testing';

import { FakeTimeService } from '@internal/test-util';

import { LogLevel, LumberjackLogLevel } from '../logs/lumberjack-log-level';
import { LumberjackLogLevel } from '../logs/lumberjack-log-level';
import { LumberjackLogPayload } from '../logs/lumberjack-log-payload';
import { LumberjackLog } from '../logs/lumberjack.log';
import { LumberjackTimeService } from '../time/lumberjack-time.service';
Expand All @@ -16,7 +16,7 @@ interface TestPayload extends LumberjackLogPayload {
testProperty: string;
}

const lumberjackLogLevels: (LumberjackLogLevel | LogLevel)[] = ['critical', 'error'];
const lumberjackLogLevels: LumberjackLogLevel[] = ['critical', 'error'];

describe(LumberjackLoggerBuilder.name, () => {
const testMessage = 'Test Message';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LogLevel, LumberjackLogLevel } from '../logs/lumberjack-log-level';
import { LumberjackLogLevel } from '../logs/lumberjack-log-level';
import { LumberjackLogPayload } from '../logs/lumberjack-log-payload';
import { LumberjackTimeService } from '../time/lumberjack-time.service';

Expand All @@ -9,13 +9,13 @@ export class LumberjackLoggerBuilder<TPayload extends LumberjackLogPayload | voi
#payload?: TPayload;
readonly #lumberjack: LumberjackService<TPayload>;
readonly #time: LumberjackTimeService;
readonly #level: LumberjackLogLevel | LogLevel;
readonly #level: LumberjackLogLevel;
readonly #message: string;

constructor(
lumberjack: LumberjackService<TPayload>,
time: LumberjackTimeService,
level: LumberjackLogLevel | LogLevel,
level: LumberjackLogLevel,
message: string
) {
this.#lumberjack = lumberjack;
Expand Down
Loading

0 comments on commit eaddd72

Please sign in to comment.