-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from Xitija/main2
PS -2403 UserId from Query Params and logging
- Loading branch information
Showing
10 changed files
with
237 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as winston from 'winston'; | ||
|
||
export class LoggerWinston { | ||
private static logger: winston.Logger; | ||
|
||
static getLogger() { | ||
if (!this.logger) { | ||
const customFormat = winston.format.printf( | ||
({ timestamp, level, message, context, user, error }) => { | ||
return JSON.stringify({ | ||
timestamp: timestamp, | ||
context: context, | ||
user: user, | ||
level: level, | ||
message: message, | ||
error: error, | ||
}); | ||
}, | ||
); | ||
|
||
this.logger = winston.createLogger({ | ||
level: 'info', | ||
format: winston.format.combine( | ||
winston.format.timestamp(), | ||
customFormat, | ||
), | ||
transports: [ | ||
new winston.transports.File({ | ||
filename: 'error.log', | ||
level: 'error', | ||
}), | ||
new winston.transports.File({ filename: 'combined.log' }), | ||
], | ||
}); | ||
} | ||
return this.logger; | ||
} | ||
static log(message: string, context?: string, user?: string) { | ||
this.getLogger().log({ | ||
level: 'info', | ||
message: message, | ||
context: context, | ||
user: user, | ||
timestamp: new Date().toISOString(), | ||
}); | ||
} | ||
|
||
static error( | ||
message: string, | ||
error?: string, | ||
context?: string, | ||
user?: string, | ||
) { | ||
this.getLogger().error({ | ||
level: 'error', | ||
message: message, | ||
error: error, | ||
context: context, | ||
user: user, | ||
timestamp: new Date().toISOString(), | ||
}); | ||
} | ||
|
||
static warn(message: string, context?: string) { | ||
this.getLogger().warn({ | ||
message: message, | ||
context: context, | ||
timestamp: new Date().toISOString(), | ||
}); | ||
} | ||
|
||
static debug(message: string, context?: string) { | ||
this.getLogger().debug({ | ||
message: message, | ||
context: context, | ||
timestamp: new Date().toISOString(), | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.