mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 06:28:53 +00:00
feat: Optionally add pino-pretty and pino-loki transports if installed
This commit is contained in:
1 parent
794f440278
commit
eb9eceb539
2 files changed
+39
-6
No files matched your search
+38
-6
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable no-console */
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import pino, { DestinationStream, Logger, LoggerOptions } from 'pino';
|
import pino, { DestinationStream, Logger, LoggerOptions } from 'pino';
|
||||||
import { CustomLoggerOptions } from '../types/configTypes';
|
import { CustomLoggerOptions } from '../types/configTypes';
|
||||||
@@ -26,8 +27,39 @@ const targets: TargetOptions[] = [
|
|||||||
mkdir: true,
|
mkdir: true,
|
||||||
sync: false
|
sync: false
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
{
|
];
|
||||||
|
|
||||||
|
// Add console logging with pino-pretty if available
|
||||||
|
let pinoPrettyAvailable = false;
|
||||||
|
let pinoLokiAvailable = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
require.resolve('pino-pretty');
|
||||||
|
pinoPrettyAvailable = true;
|
||||||
|
} catch (e) {
|
||||||
|
console.log('pino-pretty not available. Falling back to default console logging.');
|
||||||
|
console.log('install pino-pretty for better console logging: npm i pino-pretty');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
require.resolve('pino-loki');
|
||||||
|
pinoLokiAvailable = true;
|
||||||
|
} catch (e) {
|
||||||
|
console.log('pino-loki not available. Sending logs to Grafana Loki will be skipped.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pinoPrettyAvailable) {
|
||||||
|
targets.push({
|
||||||
|
target: 'pino-pretty',
|
||||||
|
level: loggerOptions.minimumLogLevelConsole,
|
||||||
|
options: {
|
||||||
|
colorize: true,
|
||||||
|
ignore: 'environment,source,module,action,name,context,executionId,executionTime,shardId,guildId,interactionType'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
targets.push({
|
||||||
// This target is used for logging to the console
|
// This target is used for logging to the console
|
||||||
target: 'pino/file',
|
target: 'pino/file',
|
||||||
level: loggerOptions.minimumLogLevelConsole,
|
level: loggerOptions.minimumLogLevelConsole,
|
||||||
@@ -35,11 +67,11 @@ const targets: TargetOptions[] = [
|
|||||||
colorize: true,
|
colorize: true,
|
||||||
sync: false
|
sync: false
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
];
|
}
|
||||||
|
|
||||||
// Check for Loki credentials and add Loki as a target if present
|
// Check for Loki credentials and add Loki as a target if present and pino-loki is installed
|
||||||
if (process.env.LOKI_AUTH_PASSWORD && process.env.LOKI_AUTH_USERNAME) {
|
if (pinoLokiAvailable && process.env.LOKI_AUTH_PASSWORD && process.env.LOKI_AUTH_USERNAME) {
|
||||||
targets.push({
|
targets.push({
|
||||||
target: 'pino-loki',
|
target: 'pino-loki',
|
||||||
level: loggerOptions.minimumLogLevel,
|
level: loggerOptions.minimumLogLevel,
|
||||||
|
|||||||
Vendored
+1
@@ -16,5 +16,6 @@ export type TargetOptions = {
|
|||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
};
|
};
|
||||||
|
ignore?: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user