Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 15 additions & 19 deletions src/node/logging/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@ import pino from 'pino'


/**
* Build and configure a base `pino` logger instance used by the helpers.
* Shared pino logger instance used by all logging functions.
*
* The logger uses ISO timestamps and a simple level formatter that exposes
* the textual level as the `level` property on emitted objects.
*
* @returns {import('pino').Logger} A configured pino logger instance.
*/
const buildBaseLogger = () => {
return pino({
timestamp: pino.stdTimeFunctions.isoTime,
formatters: {
level(label, number) {
return { level: label }
}
const logger = pino({
timestamp: pino.stdTimeFunctions.isoTime,
formatters: {
level(label, number) {
return { level: label }
}
})
}
}
})


/**
Expand All @@ -30,7 +26,7 @@ const buildBaseLogger = () => {
* @param {Record<string, any>} [options={}] - Additional metadata to include.
*/
export const loggyInfo = (label: string, message: string, options: Record<string, any> = {}): void => {
buildBaseLogger().info({ ...options, label, message })
logger.info({ ...options, label, message })
}


Expand All @@ -42,7 +38,7 @@ export const loggyInfo = (label: string, message: string, options: Record<string
* @param {Record<string, any>} [options={}] - Additional metadata to include.
*/
export const loggyDebug = (label: string, message: string, options: Record<string, any> = {}): void => {
buildBaseLogger().debug({ ...options, label, message })
logger.debug({ ...options, label, message })
}


Expand All @@ -54,7 +50,7 @@ export const loggyDebug = (label: string, message: string, options: Record<strin
* @param {Record<string, any>} [options={}] - Additional metadata to include.
*/
export const loggyWarn = (label: string, message: string, options: Record<string, any> = {}): void => {
buildBaseLogger().warn({ ...options, label, message })
logger.warn({ ...options, label, message })
}


Expand All @@ -66,7 +62,7 @@ export const loggyWarn = (label: string, message: string, options: Record<string
* @param {Record<string, any>} [options={}] - Additional metadata to include.
*/
export const loggyTrace = (label: string, message: string, options: Record<string, any> = {}): void => {
buildBaseLogger().trace({ ...options, label, message })
logger.trace({ ...options, label, message })
}


Expand All @@ -80,7 +76,7 @@ export const loggyTrace = (label: string, message: string, options: Record<strin
* @param {Record<string, any>} [options={}] - Additional metadata to include.
*/
export const loggyFatal = (label: string, message: string, options: Record<string, any> = {}): void => {
buildBaseLogger().fatal({ ...options, label, message })
logger.fatal({ ...options, label, message })
}


Expand All @@ -95,7 +91,7 @@ export const loggyFatal = (label: string, message: string, options: Record<strin
export const loggyError = (label: string, err: Error | string, options: Record<string, any> = {}): void => {
const message = typeof err === 'string' ? err : err.message
const extra = typeof err === 'string' ? options : { ...options, stack: err.stack }
buildBaseLogger().error({ ...extra, label, message })
logger.error({ ...extra, label, message })
}


Expand Down Expand Up @@ -125,7 +121,7 @@ export const loggyRequestReceived = (
route: string,
method: string,
options: Record<string, any> = {}) => {
loggyInfo("Request Recieved", `${method}: ${route}`, options)
loggyInfo("Request Received", `${method}: ${route}`, options)
}


Expand Down