From 61194d713227e22254b539663cd1c81c1e98249e Mon Sep 17 00:00:00 2001 From: Josh Creek <8179928+jcreek@users.noreply.github.com> Date: Tue, 12 Nov 2024 21:21:47 +0000 Subject: [PATCH] refactor(#92): Move site-name into env var --- .env.example | 4 +++- src/lib/utils/logger/logger.ts | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 4ab3dbc..3959ecc 100644 --- a/.env.example +++ b/.env.example @@ -13,4 +13,6 @@ VITE_BREVO_SENDER_EMAIL="noreply@example.com" # Display name for the sender email VITE_BREVO_SENDER_NAME="No Reply" # Contact email for the contact page form to send to -VITE_CONTACT_EMAIL="" \ No newline at end of file +VITE_CONTACT_EMAIL="" +# Logger service name to identify this website +VITE_LOGGER_SERVICE_NAME="example-site" \ No newline at end of file diff --git a/src/lib/utils/logger/logger.ts b/src/lib/utils/logger/logger.ts index b56c756..dee0abc 100644 --- a/src/lib/utils/logger/logger.ts +++ b/src/lib/utils/logger/logger.ts @@ -1,6 +1,10 @@ import { createLogger, transports, format } from 'winston'; import { WinstonTransport as AxiomTransport } from '@axiomhq/winston'; -import { VITE_AXIOM_DATASET, VITE_AXIOM_TOKEN } from '$env/static/private'; +import { + VITE_AXIOM_DATASET, + VITE_AXIOM_TOKEN, + VITE_LOGGER_SERVICE_NAME +} from '$env/static/private'; const axiomTransport = new AxiomTransport({ dataset: VITE_AXIOM_DATASET, @@ -9,7 +13,7 @@ const axiomTransport = new AxiomTransport({ const logger = createLogger({ level: 'info', - defaultMeta: { service: 'example-site' }, // Change this so you can identify your website if you have multiple logging into Axiom + defaultMeta: { service: VITE_LOGGER_SERVICE_NAME }, // Change this so you can identify your website if you have multiple logging into Axiom format: format.combine( format.errors({ stack: true }), // Captures error stack traces format.timestamp(),