From dd6cfd2f2779efb90e25adcdff41b5a1ca2c517d Mon Sep 17 00:00:00 2001 From: Daniel Freytag Date: Fri, 10 Jan 2025 10:45:34 +0100 Subject: [PATCH] chore: update docs --- logger/README.md | 7 +++++-- logger/logger.ts | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/logger/README.md b/logger/README.md index dcbdf35..ff3223c 100644 --- a/logger/README.md +++ b/logger/README.md @@ -38,9 +38,12 @@ The logger accesses and injects several env variables to each log event (envs li - from `os.hostname()` - fallback - `serviceName` - the service name (e.g. `my-service`) - from env `SERVICE_NAME` - set by your deployment + - from env `K_SERVICE` - set by Knative such as Google Cloud Run - `stage` - the stage (e.g. `dev`) - from env `STAGE` - set by your deployment + - from env `NODE_ENV` - set by your deployment - `version` - the version (e.g. `1.0.0`) + - from env `SERVICE_VERSION` - set by your deployment - from env `npm_package_version` - set by your deployment in `package.json` - `region` - the region (e.g. `eu-west-1`) - from env `REGION` - set by your deployment @@ -48,7 +51,7 @@ The logger accesses and injects several env variables to each log event (envs li - `runtime` - the runtime (e.g. `nodejs-20.11.0`) - from `process.versions.bun` - set by Bun - from `process.versions.deno` - set by Deno - - from `process.env.AWS_EXECUTION_ENV` - set by AWS Lambda + - from env `AWS_EXECUTION_ENV` - set by AWS Lambda - from `process.version` - fallback (usually Node.js) Additionally these environment variables are triggering different logging formats: @@ -59,7 +62,7 @@ Additionally these environment variables are triggering different logging format ## Log Levels It is currently pre-configured with the -[syslog log levels](https://github.com/winstonjs/winston?tab=readme-ov-file#logging-levels): +[syslog log levels](https://github.com/winstonjs/winston?tab=readme-ov-file#logging-levels) from most to least severe: ```ts { diff --git a/logger/logger.ts b/logger/logger.ts index d104995..ad6a8d4 100644 --- a/logger/logger.ts +++ b/logger/logger.ts @@ -39,9 +39,9 @@ export const detectProcessVersion = (): string => { // Add global context to log events const convertGlobals = format((event) => { event.host = process.env.K_REVISION || process.env.AWS_LAMBDA_FUNCTION_NAME || hostName - event.serviceName = process.env.SERVICE_NAME || null - event.stage = process.env.STAGE || null - event.version = process.env.npm_package_version + event.serviceName = process.env.SERVICE_NAME || process.env.K_SERVICE || null + event.stage = process.env.STAGE || process.env.NODE_ENV || null + event.version = process.env.SERVICE_VERSION || process.env.npm_package_version event.region = process.env.REGION || process.env.AWS_REGION || null event.runtime = detectProcessVersion() return event