mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +00:00
feat: add default properties for logger, ignore these in pino-pretty output
This commit is contained in:
1 parent
4d9353d43a
commit
55316995e5
2 files changed
+16
-6
No files matched your search
+3
-2
@@ -20,9 +20,10 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"start": "node ./src/index.js",
|
"start": "node ./src/index.js",
|
||||||
"start-pretty": "node ./src/index.js | pino-pretty",
|
"start-pretty": "node ./src/index.js | pino-pretty --ignore environment,source,module,name,context,err,error",
|
||||||
|
"start-pretty-no-ignore": "node ./src/index.js | pino-pretty",
|
||||||
"deploy": "node ./src/utils/deploySlashCommands.js",
|
"deploy": "node ./src/utils/deploySlashCommands.js",
|
||||||
"deploy-pretty": "node ./src/utils/deploySlashCommands.js | pino-pretty",
|
"deploy-pretty": "node ./src/utils/deploySlashCommands.js | pino-pretty --ignore environment,source,module,name,context,err,error",
|
||||||
"eslint": "eslint ./"
|
"eslint": "eslint ./"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
+13
-4
@@ -1,5 +1,7 @@
|
|||||||
const pino = require('pino');
|
const pino = require('pino');
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
|
|
||||||
|
// Retrieve logger options from config
|
||||||
const loggerOptions = config.get('loggerOptions');
|
const loggerOptions = config.get('loggerOptions');
|
||||||
|
|
||||||
const targets = [
|
const targets = [
|
||||||
@@ -42,6 +44,7 @@ const targets = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Check for Loki credentials and add Loki as a target if present
|
||||||
if (process.env.LOKI_AUTH_PASSWORD && process.env.LOKI_AUTH_USERNAME) {
|
if (process.env.LOKI_AUTH_PASSWORD && process.env.LOKI_AUTH_USERNAME) {
|
||||||
targets.push({
|
targets.push({
|
||||||
target: 'pino-loki',
|
target: 'pino-loki',
|
||||||
@@ -50,8 +53,7 @@ if (process.env.LOKI_AUTH_PASSWORD && process.env.LOKI_AUTH_USERNAME) {
|
|||||||
sync: false,
|
sync: false,
|
||||||
batching: false,
|
batching: false,
|
||||||
interval: 5,
|
interval: 5,
|
||||||
|
host: process.env.LOKI_HOST || 'http://localhost:3100',
|
||||||
host: 'https://logs-prod-025.grafana.net',
|
|
||||||
basicAuth: {
|
basicAuth: {
|
||||||
username: process.env.LOKI_AUTH_USERNAME || '',
|
username: process.env.LOKI_AUTH_USERNAME || '',
|
||||||
password: process.env.LOKI_AUTH_PASSWORD || ''
|
password: process.env.LOKI_AUTH_PASSWORD || ''
|
||||||
@@ -62,10 +64,17 @@ if (process.env.LOKI_AUTH_PASSWORD && process.env.LOKI_AUTH_USERNAME) {
|
|||||||
|
|
||||||
const transport = pino.transport({ targets });
|
const transport = pino.transport({ targets });
|
||||||
|
|
||||||
|
// Default properties for the logger, these will be added to every log entry
|
||||||
|
const defaultProperties = {
|
||||||
|
environment: process.env.NODE_ENV || 'development'
|
||||||
|
};
|
||||||
|
|
||||||
const logLevelConfig = {
|
const logLevelConfig = {
|
||||||
level: loggerOptions.minimumLogLevel,
|
level: loggerOptions.minimumLogLevel,
|
||||||
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
|
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
|
||||||
base: undefined
|
base: defaultProperties
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = pino(logLevelConfig, transport);
|
const logger = pino(logLevelConfig, transport);
|
||||||
|
|
||||||
|
module.exports = logger;
|
||||||
Reference in new issue
Block a user