-
Notifications
You must be signed in to change notification settings - Fork 5
Add logger utility and integrate with error handling and request logging #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||||||||||||||||||||||||||
| import winston from 'winston'; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const logger = winston.createLogger({ | ||||||||||||||||||||||||||||||
| level: "http", | ||||||||||||||||||||||||||||||
| format: winston.format.combine( | ||||||||||||||||||||||||||||||
| winston.format.timestamp(), | ||||||||||||||||||||||||||||||
| winston.format.json() | ||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||
| transports: [ | ||||||||||||||||||||||||||||||
| new winston.transports.Console({ | ||||||||||||||||||||||||||||||
| format: winston.format.combine( | ||||||||||||||||||||||||||||||
| winston.format.colorize(), | ||||||||||||||||||||||||||||||
| winston.format.simple() | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| logger.stream = { | ||||||||||||||||||||||||||||||
| write: (message: any) => { | ||||||||||||||||||||||||||||||
| logger.info(message.trim()); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } as any; | ||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Replace type assertions with proper TypeScript interfaces. The 🔎 Proposed fix+interface LoggerStream {
+ write(message: string): void;
+}
+
-logger.stream = {
- write: (message: any) => {
+logger.stream = {
+ write: (message: string) => {
logger.info(message.trim());
}
-} as any;
+} as LoggerStream;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export { logger }; | ||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Add type safety and fix edge case in LoggerStream.
The LoggerStream implementation has two issues:
lastIndexOf('\n')returns -1 if no newline exists, causingsubstring(0, -1)to return an empty string🔎 Proposed fix
Note: Using
trim()is simpler and handles all trailing whitespace, matching the pattern already used insrc/utils/logger.tsline 21.📝 Committable suggestion
🤖 Prompt for AI Agents