Replace bunyan with pino

This commit is contained in:
Josh Perez 2021-03-10 17:41:38 -05:00 committed by Josh Perez
parent b0bee86fd3
commit d85a43fe93
7 changed files with 251 additions and 130 deletions

View file

@ -8,12 +8,14 @@
import * as path from 'path';
import * as fs from 'fs';
import { app, ipcMain as ipc } from 'electron';
import * as bunyan from 'bunyan';
import pinoms from 'pino-multi-stream';
import pino from 'pino';
import * as mkdirp from 'mkdirp';
import * as _ from 'lodash';
import readFirstLine from 'firstline';
import { read as readLastLines } from 'read-last-lines';
import rimraf from 'rimraf';
import { createStream } from 'rotating-file-stream';
import {
LogEntryType,
@ -33,11 +35,11 @@ declare global {
}
}
let globalLogger: undefined | bunyan;
let globalLogger: undefined | pinoms.Logger;
const isRunningFromConsole = Boolean(process.stdout.isTTY);
export async function initialize(): Promise<bunyan> {
export async function initialize(): Promise<pinoms.Logger> {
if (globalLogger) {
throw new Error('Already called initialize!');
}
@ -62,26 +64,25 @@ export async function initialize(): Promise<bunyan> {
}
const logFile = path.join(logPath, 'main.log');
const loggerOptions: bunyan.LoggerOptions = {
name: 'main',
streams: [
{
type: 'rotating-file',
path: logFile,
period: '1d',
count: 3,
},
],
};
const stream = createStream(logFile, {
interval: '1d',
maxFiles: 3,
});
const streams: pinoms.Streams = [];
streams.push({ stream });
if (isRunningFromConsole) {
loggerOptions.streams?.push({
level: 'debug',
streams.push({
level: 'debug' as const,
stream: process.stdout,
});
}
const logger = bunyan.createLogger(loggerOptions);
const logger = pinoms({
streams,
timestamp: pino.stdTimeFunctions.isoTime,
});
ipc.on('fetch-log', event => {
fetch(logPath).then(