mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: configure logger during setup
This commit is contained in:
committed by
Ruben Taelman
parent
09ac83caa5
commit
aaa49219dc
30
src/logging/LogUtil.ts
Normal file
30
src/logging/LogUtil.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { LazyLoggerFactory } from './LazyLoggerFactory';
|
||||
import type { Logger } from './Logger';
|
||||
|
||||
/**
|
||||
* Gets a logger instance for the given class instance.
|
||||
*
|
||||
* The returned type of logger depends on the configured {@link LoggerFactory} in {@link Setup}.
|
||||
*
|
||||
* The following shows a typical pattern on how to create loggers:
|
||||
* ```
|
||||
* class MyClass {
|
||||
* protected readonly logger = getLoggerFor(this);
|
||||
* }
|
||||
* ```
|
||||
* If no class is applicable, a logger can also be created as follows:
|
||||
* ```
|
||||
* const logger = getLoggerFor('MyFunction');
|
||||
* ```
|
||||
*
|
||||
* @param loggable - A class instance or a class string name.
|
||||
*/
|
||||
export const getLoggerFor = (loggable: string | Instance): Logger => LazyLoggerFactory.getInstance()
|
||||
.createLogger(typeof loggable === 'string' ? loggable : loggable.constructor.name);
|
||||
|
||||
/**
|
||||
* Helper interface to identify class instances.
|
||||
*/
|
||||
interface Instance {
|
||||
constructor: { name: string };
|
||||
}
|
||||
Reference in New Issue
Block a user