WhatsApp/Signal/Formstack/admin updates
This commit is contained in:
parent
bcecf61a46
commit
d0cc5a21de
451 changed files with 16139 additions and 39623 deletions
81
packages/logger/src/config.ts
Normal file
81
packages/logger/src/config.ts
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
import type { LoggerOptions } from 'pino';
|
||||
|
||||
export const getLogLevel = (): string => {
|
||||
return process.env.LOG_LEVEL || (process.env.NODE_ENV === 'production' ? 'info' : 'debug');
|
||||
};
|
||||
|
||||
export 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: [
|
||||
// Top-level sensitive fields
|
||||
'password',
|
||||
'token',
|
||||
'secret',
|
||||
'api_key',
|
||||
'apiKey',
|
||||
'authorization',
|
||||
'cookie',
|
||||
'HandshakeKey',
|
||||
'receivedSecret',
|
||||
'access_token',
|
||||
'refresh_token',
|
||||
'zammadCsrfToken',
|
||||
'clientSecret',
|
||||
// Nested sensitive fields (one level)
|
||||
'*.password',
|
||||
'*.token',
|
||||
'*.secret',
|
||||
'*.api_key',
|
||||
'*.apiKey',
|
||||
'*.authorization',
|
||||
'*.cookie',
|
||||
'*.access_token',
|
||||
'*.refresh_token',
|
||||
'*.zammadCsrfToken',
|
||||
'*.HandshakeKey',
|
||||
'*.receivedSecret',
|
||||
'*.clientSecret',
|
||||
// Common nested patterns
|
||||
'payload.HandshakeKey',
|
||||
'headers.authorization',
|
||||
'headers.cookie',
|
||||
'headers.Authorization',
|
||||
'headers.Cookie',
|
||||
'credentials.password',
|
||||
'credentials.secret',
|
||||
'credentials.token',
|
||||
],
|
||||
censor: '[REDACTED]',
|
||||
},
|
||||
};
|
||||
|
||||
if (isDevelopment) {
|
||||
// In development, use pretty printing for better readability
|
||||
return {
|
||||
...baseConfig,
|
||||
transport: {
|
||||
target: 'pino-pretty',
|
||||
options: {
|
||||
colorize: true,
|
||||
translateTime: 'SYS:standard',
|
||||
ignore: 'pid,hostname',
|
||||
singleLine: false,
|
||||
messageFormat: '{msg}',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// In production, use JSON for structured logging
|
||||
return baseConfig;
|
||||
};
|
||||
35
packages/logger/src/index.ts
Normal file
35
packages/logger/src/index.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import pino, { Logger as PinoLogger } from 'pino';
|
||||
import { getPinoConfig } from './config';
|
||||
|
||||
export type Logger = PinoLogger;
|
||||
|
||||
// Create the default logger instance
|
||||
export const logger: Logger = pino(getPinoConfig());
|
||||
|
||||
// Factory function to create child loggers with context
|
||||
export const createLogger = (name: string, context?: Record<string, any>): Logger => {
|
||||
return logger.child({ name, ...context });
|
||||
};
|
||||
|
||||
// Export log levels for consistency
|
||||
export const LogLevel = {
|
||||
TRACE: 'trace',
|
||||
DEBUG: 'debug',
|
||||
INFO: 'info',
|
||||
WARN: 'warn',
|
||||
ERROR: 'error',
|
||||
FATAL: 'fatal',
|
||||
} as const;
|
||||
|
||||
export type LogLevelType = typeof LogLevel[keyof typeof LogLevel];
|
||||
|
||||
// Utility to check if a log level is enabled
|
||||
export const isLogLevelEnabled = (level: LogLevelType): boolean => {
|
||||
return logger.isLevelEnabled(level);
|
||||
};
|
||||
|
||||
// Re-export pino types that might be useful
|
||||
export type { LoggerOptions, DestinationStream } from 'pino';
|
||||
|
||||
// Default export for convenience
|
||||
export default logger;
|
||||
Loading…
Add table
Add a link
Reference in a new issue