mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-23 18:08:05 +01:00
Better usage of pino
This commit is contained in:
@@ -5,67 +5,27 @@ import type { LoggerType } from '../types/Logging';
|
||||
|
||||
/* eslint-disable no-console */
|
||||
export const consoleLogger: LoggerType = {
|
||||
fatal(...args: Array<unknown>) {
|
||||
fatal(...args) {
|
||||
console.error(...args);
|
||||
},
|
||||
error(...args: Array<unknown>) {
|
||||
error(...args) {
|
||||
console.error(...args);
|
||||
},
|
||||
warn(...args: Array<unknown>) {
|
||||
warn(...args) {
|
||||
console.warn(...args);
|
||||
},
|
||||
info(...args: Array<unknown>) {
|
||||
info(...args) {
|
||||
console.info(...args);
|
||||
},
|
||||
debug(...args: Array<unknown>) {
|
||||
debug(...args) {
|
||||
console.debug(...args);
|
||||
},
|
||||
trace(...args: Array<unknown>) {
|
||||
trace(...args) {
|
||||
console.log(...args);
|
||||
},
|
||||
child() {
|
||||
throw new Error('Not supported');
|
||||
},
|
||||
};
|
||||
|
||||
export type BufferedLoggerType = LoggerType & {
|
||||
writeBufferInto(logger: LoggerType): void;
|
||||
};
|
||||
|
||||
export function createBufferedConsoleLogger(): BufferedLoggerType {
|
||||
type BufferEntryType = Readonly<{
|
||||
level: keyof LoggerType;
|
||||
args: Array<unknown>;
|
||||
}>;
|
||||
const buffer = new Array<BufferEntryType>();
|
||||
return {
|
||||
fatal(...args: Array<unknown>) {
|
||||
buffer.push({ level: 'fatal', args });
|
||||
console.error(...args);
|
||||
},
|
||||
error(...args: Array<unknown>) {
|
||||
buffer.push({ level: 'error', args });
|
||||
console.error(...args);
|
||||
},
|
||||
warn(...args: Array<unknown>) {
|
||||
buffer.push({ level: 'warn', args });
|
||||
console.warn(...args);
|
||||
},
|
||||
info(...args: Array<unknown>) {
|
||||
buffer.push({ level: 'info', args });
|
||||
console.info(...args);
|
||||
},
|
||||
debug(...args: Array<unknown>) {
|
||||
buffer.push({ level: 'debug', args });
|
||||
console.debug(...args);
|
||||
},
|
||||
trace(...args: Array<unknown>) {
|
||||
buffer.push({ level: 'trace', args });
|
||||
console.log(...args);
|
||||
},
|
||||
|
||||
writeBufferInto(output) {
|
||||
for (const { level, args } of buffer) {
|
||||
output[level](...args);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
/* eslint-enable no-console */
|
||||
|
||||
Reference in New Issue
Block a user