mirror of
https://github.com/lucasrcsantana/story-generator.git
synced 2025-12-17 05:47:52 +00:00
37 lines
784 B
TypeScript
37 lines
784 B
TypeScript
export interface LogContext {
|
|
requestId: string
|
|
recordId: string
|
|
step: string
|
|
timestamp: string
|
|
}
|
|
|
|
export function createLogger(recordId: string) {
|
|
const requestId = crypto.randomUUID()
|
|
|
|
return {
|
|
info: (step: string, message: string, data?: any) => {
|
|
console.log(JSON.stringify({
|
|
level: 'info',
|
|
requestId,
|
|
recordId,
|
|
step,
|
|
message,
|
|
data,
|
|
timestamp: new Date().toISOString()
|
|
}))
|
|
},
|
|
|
|
error: (step: string, error: Error, data?: any) => {
|
|
console.error(JSON.stringify({
|
|
level: 'error',
|
|
requestId,
|
|
recordId,
|
|
step,
|
|
message: error.message,
|
|
stack: error.stack,
|
|
data,
|
|
timestamp: new Date().toISOString()
|
|
}))
|
|
}
|
|
}
|
|
}
|