mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: add winston
This commit is contained in:
1 parent
9bdaa95bad
commit
515aefcadc
4 files changed
+180
-5
No files matched your search
+3
-3
@@ -16,13 +16,13 @@ import { globalRateLimit } from './middleware/rateLimiter.js'
|
||||
import sessionMiddleware from './middleware/session.js'
|
||||
import expiryRemovalScheduler from './containers/expiryChecker.js'
|
||||
import setupTest from './utils/setupTest.js'
|
||||
import logger from './utils/logger.js'
|
||||
|
||||
async function main() {
|
||||
if (!config.secret) {
|
||||
console.warn(
|
||||
'No SECRET_KEY found in .env! To set up a persistent key, please run the setup script:'
|
||||
logger.error(
|
||||
'No SECRET_KEY found in .env! To set up a persistent key, please run `yarn setup`:'
|
||||
)
|
||||
console.warn('yarn setup')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import winston from 'winston'
|
||||
|
||||
const logger = winston.createLogger({
|
||||
level: 'info',
|
||||
format: winston.format.json(),
|
||||
defaultMeta: { service: 'user-service' },
|
||||
transports: [
|
||||
//
|
||||
// - Write all logs with importance level of `error` or less to `error.log`
|
||||
// - Write all logs with importance level of `info` or less to `combined.log`
|
||||
//
|
||||
new winston.transports.File({ filename: 'error.log', level: 'error' }),
|
||||
new winston.transports.File({ filename: 'combined.log' }),
|
||||
],
|
||||
})
|
||||
|
||||
//
|
||||
// If we're not in production then log to the `console` with the format:
|
||||
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
|
||||
//
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
logger.add(
|
||||
new winston.transports.Console({
|
||||
format: winston.format.simple(),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export default logger
|
||||
Reference in new issue
Block a user