From 2b98ca650c2cf2d07bf1fb1c4e282de95171ea98 Mon Sep 17 00:00:00 2001 From: Saurajit Bhuyan Date: Thu, 5 Sep 2024 00:40:12 +0530 Subject: [PATCH 1/2] improve types for context --- bufflog.ts | 12 ++++++------ index.ts | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bufflog.ts b/bufflog.ts index cb023e6..404e413 100644 --- a/bufflog.ts +++ b/bufflog.ts @@ -24,28 +24,28 @@ export function getLogger() { return pinoLogger; } -export function debug(message: string, context?: object) { +export function debug(message: string, context?: T) { pinoLogger.debug({context: context}, message); } -export function info(message: string, context?: object) { +export function info(message: string, context?: T) { pinoLogger.info({context: context}, message); } -export function notice(message: string, context?: object) { +export function notice(message: string, context?: T) { pinoLogger.notice({context: context}, message); } -export function warning(message: string, context?: object) { +export function warning(message: string, context?: T) { pinoLogger.warn({context: context}, message); } -export function error(message: string, context?: object) { +export function error(message: string, context?: T) { pinoLogger.error({context: context}, message); } // for consistency with php-bufflog, critical == fatal -export function critical(message: string, context?: object) { +export function critical(message: string, context?: T) { pinoLogger.fatal({context: context}, message); } diff --git a/index.ts b/index.ts index 967415e..2e8ea0e 100644 --- a/index.ts +++ b/index.ts @@ -21,6 +21,7 @@ BuffLog.warning('hello warning'); BuffLog.error('hello error'); BuffLog.critical('hello critical'); BuffLog.critical('hello critical', {"some":"stuff"}); +BuffLog.critical<{type: string}>('hello critical', {"type":"with type enforced context"}); const app = express(); From 2a2dde3a6be397e96782b944c0eced32e8db7d09 Mon Sep 17 00:00:00 2001 From: Saurajit Bhuyan Date: Thu, 5 Sep 2024 00:40:12 +0530 Subject: [PATCH 2/2] chore: improve types for context --- bufflog.ts | 12 ++++++------ index.ts | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bufflog.ts b/bufflog.ts index cb023e6..404e413 100644 --- a/bufflog.ts +++ b/bufflog.ts @@ -24,28 +24,28 @@ export function getLogger() { return pinoLogger; } -export function debug(message: string, context?: object) { +export function debug(message: string, context?: T) { pinoLogger.debug({context: context}, message); } -export function info(message: string, context?: object) { +export function info(message: string, context?: T) { pinoLogger.info({context: context}, message); } -export function notice(message: string, context?: object) { +export function notice(message: string, context?: T) { pinoLogger.notice({context: context}, message); } -export function warning(message: string, context?: object) { +export function warning(message: string, context?: T) { pinoLogger.warn({context: context}, message); } -export function error(message: string, context?: object) { +export function error(message: string, context?: T) { pinoLogger.error({context: context}, message); } // for consistency with php-bufflog, critical == fatal -export function critical(message: string, context?: object) { +export function critical(message: string, context?: T) { pinoLogger.fatal({context: context}, message); } diff --git a/index.ts b/index.ts index 967415e..2e8ea0e 100644 --- a/index.ts +++ b/index.ts @@ -21,6 +21,7 @@ BuffLog.warning('hello warning'); BuffLog.error('hello error'); BuffLog.critical('hello critical'); BuffLog.critical('hello critical', {"some":"stuff"}); +BuffLog.critical<{type: string}>('hello critical', {"type":"with type enforced context"}); const app = express();