feat(shared): reorder AppError constructor to (message, code, status), add singleton logger, retry and TTL cache utilities
This commit is contained in:
@@ -1,25 +1,34 @@
|
||||
import pino from "pino";
|
||||
|
||||
export type Logger = ReturnType<typeof createLogger>;
|
||||
const rootLogger = pino({
|
||||
level: process.env.LOG_LEVEL || "info",
|
||||
transport:
|
||||
process.env.NODE_ENV === "development"
|
||||
? {
|
||||
target: "pino-pretty",
|
||||
options: {
|
||||
colorize: true,
|
||||
translateTime: "SYS:standard",
|
||||
ignore: "pid,hostname",
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
} as pino.LoggerOptions);
|
||||
|
||||
export function createLogger(context: string) {
|
||||
return pino({
|
||||
name: context,
|
||||
level: process.env.LOG_LEVEL || "info",
|
||||
transport:
|
||||
process.env.NODE_ENV === "development"
|
||||
? {
|
||||
target: "pino-pretty",
|
||||
options: {
|
||||
colorize: true,
|
||||
translateTime: "SYS:standard",
|
||||
ignore: "pid,hostname",
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
} as pino.LoggerOptions);
|
||||
}
|
||||
export type Logger = ReturnType<typeof createChildLogger>;
|
||||
|
||||
/**
|
||||
* Returns a child logger bound to the root singleton via pino's .child().
|
||||
* Preserves parent context and is efficient (no transport re-init per call).
|
||||
*/
|
||||
export function createChildLogger(context: string) {
|
||||
return createLogger(context);
|
||||
return rootLogger.child({ context });
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for createChildLogger for backwards compatibility.
|
||||
* @deprecated Use createChildLogger instead.
|
||||
*/
|
||||
export function createLogger(context: string) {
|
||||
return createChildLogger(context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user