Skip to content

Instantly share code, notes, and snippets.

@tomfa
Last active January 30, 2023 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomfa/668a1a4b07f01e112667cbe629d33a92 to your computer and use it in GitHub Desktop.
Save tomfa/668a1a4b07f01e112667cbe629d33a92 to your computer and use it in GitHub Desktop.
LogStructure.ts
type ApplicationLog = {
level: 'debug' | 'info' | 'warning' | 'danger' | 'critical',
message: string,
createdAt: number,
userId?: string,
// a business metric, e.g. SIGNUP
action?: string,
monetaryValue?: number,
requestId?: string,
// Common fields depending on your use case
oldValue?: string,
value?: string,
comment?: string,
// Handle custom cases
[key: string]: any;
}
// You typically don't control this type yourself.
// It's determined by your hosting provider. But
// it typically includes at least this info.
type HTTPLog = {
request: {
method: 'GET' | 'POST' | 'PATCH' | 'DELETE' | 'PUT',
path: string,
query?: string,
ipAddress: string,
headers: {
requestId?: string,
}
// ...
},
response: {
httpStatus: number,
responseTime: number,
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment