Make APIs more similar
This commit is contained in:
parent
9f0e1f8b61
commit
c40d7d056e
57 changed files with 3994 additions and 1801 deletions
27
packages/logger/package.json
Normal file
27
packages/logger/package.json
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "@link-stack/logger",
|
||||
"version": "3.5.0-beta.1",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup src/index.ts --format cjs,esm --dts --clean"
|
||||
},
|
||||
"dependencies": {
|
||||
"pino": "^9.6.0",
|
||||
"pino-pretty": "^13.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@link-stack/typescript-config": "workspace:*",
|
||||
"@types/node": "*",
|
||||
"tsup": "^8.5.0",
|
||||
"typescript": "^5.9.3"
|
||||
}
|
||||
}
|
||||
86
packages/logger/src/index.ts
Normal file
86
packages/logger/src/index.ts
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
import pino, { type Logger as PinoLogger, type LoggerOptions } from "pino";
|
||||
|
||||
export type Logger = PinoLogger;
|
||||
|
||||
const getLogLevel = (): string => {
|
||||
return process.env.LOG_LEVEL || (process.env.NODE_ENV === "production" ? "info" : "debug");
|
||||
};
|
||||
|
||||
const getPinoConfig = (): LoggerOptions => {
|
||||
const isDevelopment = process.env.NODE_ENV !== "production";
|
||||
|
||||
const baseConfig: LoggerOptions = {
|
||||
level: getLogLevel(),
|
||||
formatters: {
|
||||
level: (label) => {
|
||||
return { level: label.toUpperCase() };
|
||||
},
|
||||
},
|
||||
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
|
||||
redact: {
|
||||
paths: [
|
||||
"password",
|
||||
"token",
|
||||
"secret",
|
||||
"api_key",
|
||||
"apiKey",
|
||||
"authorization",
|
||||
"cookie",
|
||||
"HandshakeKey",
|
||||
"receivedSecret",
|
||||
"access_token",
|
||||
"refresh_token",
|
||||
"zammadCsrfToken",
|
||||
"clientSecret",
|
||||
"*.password",
|
||||
"*.token",
|
||||
"*.secret",
|
||||
"*.api_key",
|
||||
"*.apiKey",
|
||||
"*.authorization",
|
||||
"*.cookie",
|
||||
"*.access_token",
|
||||
"*.refresh_token",
|
||||
"*.zammadCsrfToken",
|
||||
"*.HandshakeKey",
|
||||
"*.receivedSecret",
|
||||
"*.clientSecret",
|
||||
"payload.HandshakeKey",
|
||||
"headers.authorization",
|
||||
"headers.cookie",
|
||||
"headers.Authorization",
|
||||
"headers.Cookie",
|
||||
"credentials.password",
|
||||
"credentials.secret",
|
||||
"credentials.token",
|
||||
],
|
||||
censor: "[REDACTED]",
|
||||
},
|
||||
};
|
||||
|
||||
if (isDevelopment) {
|
||||
return {
|
||||
...baseConfig,
|
||||
transport: {
|
||||
target: "pino-pretty",
|
||||
options: {
|
||||
colorize: true,
|
||||
translateTime: "SYS:standard",
|
||||
ignore: "pid,hostname",
|
||||
singleLine: false,
|
||||
messageFormat: "{msg}",
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return baseConfig;
|
||||
};
|
||||
|
||||
export const logger: Logger = pino(getPinoConfig());
|
||||
|
||||
export const createLogger = (name: string, context?: Record<string, unknown>): Logger => {
|
||||
return logger.child({ name, ...context });
|
||||
};
|
||||
|
||||
export default logger;
|
||||
11
packages/logger/tsconfig.json
Normal file
11
packages/logger/tsconfig.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"extends": "@link-stack/typescript-config/tsconfig.node.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"incremental": false,
|
||||
"composite": false
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue