mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
change: add global setGlobalLoggerFactory function
This commit is contained in:
committed by
Ruben Taelman
parent
db9aefe551
commit
4c534e9d5d
@@ -1,11 +1,12 @@
|
||||
import { LazyLogger } from '../../../src/logging/LazyLogger';
|
||||
import { LazyLoggerFactory } from '../../../src/logging/LazyLoggerFactory';
|
||||
import { getLoggerFor } from '../../../src/logging/LogUtil';
|
||||
import { getLoggerFor, setGlobalLoggerFactory } from '../../../src/logging/LogUtil';
|
||||
import { VoidLogger } from '../../../src/logging/VoidLogger';
|
||||
import { VoidLoggerFactory } from '../../../src/logging/VoidLoggerFactory';
|
||||
|
||||
describe('LogUtil', (): void => {
|
||||
beforeEach(async(): Promise<void> => {
|
||||
LazyLoggerFactory.getInstance().setLoggerFactory(undefined);
|
||||
setGlobalLoggerFactory(undefined);
|
||||
});
|
||||
|
||||
it('allows creating a lazy logger for a string label.', async(): Promise<void> => {
|
||||
@@ -17,4 +18,16 @@ describe('LogUtil', (): void => {
|
||||
expect(getLoggerFor(new VoidLogger())).toBeInstanceOf(LazyLogger);
|
||||
expect((getLoggerFor(new VoidLogger()) as any).label).toEqual('VoidLogger');
|
||||
});
|
||||
|
||||
it('allows setting the global logger factory.', async(): Promise<void> => {
|
||||
expect(setGlobalLoggerFactory(new VoidLoggerFactory()));
|
||||
expect(LazyLoggerFactory.getInstance().getLoggerFactoryOrThrow()).toBeInstanceOf(VoidLoggerFactory);
|
||||
});
|
||||
|
||||
it('allows unsetting the global logger factory.', async(): Promise<void> => {
|
||||
expect(setGlobalLoggerFactory(new VoidLoggerFactory()));
|
||||
expect(setGlobalLoggerFactory(undefined));
|
||||
expect((): any => LazyLoggerFactory.getInstance().getLoggerFactoryOrThrow())
|
||||
.toThrow(new Error('Illegal logging during initialization'));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Server } from 'http';
|
||||
import request from 'supertest';
|
||||
import { LazyLoggerFactory } from '../../../src/logging/LazyLoggerFactory';
|
||||
import { setGlobalLoggerFactory } from '../../../src/logging/LogUtil';
|
||||
import { VoidLoggerFactory } from '../../../src/logging/VoidLoggerFactory';
|
||||
import { ExpressHttpServer } from '../../../src/server/ExpressHttpServer';
|
||||
import { HttpHandler } from '../../../src/server/HttpHandler';
|
||||
@@ -33,7 +33,7 @@ describe('ExpressHttpServer', (): void => {
|
||||
beforeAll(async(): Promise<void> => {
|
||||
// Prevent test from writing to stderr
|
||||
mock = jest.spyOn(process.stderr, 'write').mockImplementation((): boolean => true);
|
||||
LazyLoggerFactory.getInstance().setLoggerFactory(new VoidLoggerFactory());
|
||||
setGlobalLoggerFactory(new VoidLoggerFactory());
|
||||
});
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user