CognxSafeTrack commited on
Commit ·
c96ef69
1
Parent(s): 38df3bf
fix: implement compatible logger wrapper to resolve project-wide TS errors
Browse files- apps/api/src/logger.ts +25 -3
apps/api/src/logger.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
| 1 |
import pino from 'pino';
|
| 2 |
|
| 3 |
-
// Use a simple configuration to maintain compatibility with existing logger.info/error calls
|
| 4 |
const isProduction = process.env.NODE_ENV === 'production';
|
| 5 |
|
| 6 |
-
|
|
|
|
| 7 |
level: process.env.LOG_LEVEL || (isProduction ? 'info' : 'debug'),
|
| 8 |
base: {
|
| 9 |
env: process.env.NODE_ENV,
|
| 10 |
service: 'api-gateway'
|
| 11 |
},
|
| 12 |
-
// Standard transport configuration
|
| 13 |
transport: {
|
| 14 |
targets: [
|
| 15 |
{
|
|
@@ -30,4 +29,27 @@ export const logger = pino({
|
|
| 30 |
}
|
| 31 |
});
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
export const log = logger;
|
|
|
|
| 1 |
import pino from 'pino';
|
| 2 |
|
|
|
|
| 3 |
const isProduction = process.env.NODE_ENV === 'production';
|
| 4 |
|
| 5 |
+
// Initialize the base pino instance
|
| 6 |
+
const baseLogger = pino({
|
| 7 |
level: process.env.LOG_LEVEL || (isProduction ? 'info' : 'debug'),
|
| 8 |
base: {
|
| 9 |
env: process.env.NODE_ENV,
|
| 10 |
service: 'api-gateway'
|
| 11 |
},
|
|
|
|
| 12 |
transport: {
|
| 13 |
targets: [
|
| 14 |
{
|
|
|
|
| 29 |
}
|
| 30 |
});
|
| 31 |
|
| 32 |
+
/**
|
| 33 |
+
* Compatible Logger Wrapper
|
| 34 |
+
*
|
| 35 |
+
* Provides a more permissive interface to match existing codebase usage:
|
| 36 |
+
* logger.error("Message", errorObject) -> logger.error({ err: errorObject }, "Message")
|
| 37 |
+
*/
|
| 38 |
+
const wrap = (level: 'info' | 'error' | 'warn' | 'debug') => (arg1: any, arg2?: any, ...args: any[]) => {
|
| 39 |
+
if (typeof arg1 === 'string' && arg2 !== undefined) {
|
| 40 |
+
// Handle (msg, data) pattern by flipping it for Pino
|
| 41 |
+
return baseLogger[level]({ err: arg2, data: args.length > 0 ? args : undefined }, arg1);
|
| 42 |
+
}
|
| 43 |
+
return baseLogger[level](arg1, arg2, ...args);
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
export const logger = {
|
| 47 |
+
info: wrap('info'),
|
| 48 |
+
error: wrap('error'),
|
| 49 |
+
warn: wrap('warn'),
|
| 50 |
+
debug: wrap('debug'),
|
| 51 |
+
child: (bindings: pino.Bindings) => baseLogger.child(bindings),
|
| 52 |
+
pino: baseLogger // Access to raw instance if needed
|
| 53 |
+
} as any;
|
| 54 |
+
|
| 55 |
export const log = logger;
|