(
config: LoggingConfig,
level: Exclude<LogLevel, "silent">,
event: string,
fields: LogFields = {},
)
| 28 | } |
| 29 | |
| 30 | export function logEvent( |
| 31 | config: LoggingConfig, |
| 32 | level: Exclude<LogLevel, "silent">, |
| 33 | event: string, |
| 34 | fields: LogFields = {}, |
| 35 | ): void { |
| 36 | if (!shouldLog(config, level)) return; |
| 37 | |
| 38 | const entry = { |
| 39 | ts: new Date().toISOString(), |
| 40 | level, |
| 41 | event, |
| 42 | ...fields, |
| 43 | }; |
| 44 | |
| 45 | const line = config.format === "pretty" ? formatPretty(entry) : JSON.stringify(entry); |
| 46 | if (level === "error") { |
| 47 | console.error(line); |
| 48 | } else if (level === "warn") { |
| 49 | console.warn(line); |
| 50 | } else { |
| 51 | console.log(line); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | export function requestIp(req: Request, trustProxy: boolean): string | undefined { |
| 56 | if (trustProxy) { |
no test coverage detected