Skip to content

Commit

Permalink
[#7] feat: add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
glemenneo committed Sep 18, 2024
1 parent 45dcdaa commit 3baa4dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
**/dist
**/coverage

**/*.log

**/.turbo
15 changes: 14 additions & 1 deletion backend/user-service/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import 'dotenv/config'
import http, { Server } from 'http'
import Winston, { Logger } from 'winston'
import index from './index'

// Setup Logger
export const logger: Logger = Winston.createLogger({
level: 'info',
format: Winston.format.json(),
defaultMeta: { service: 'user-service' },
transports: [
new Winston.transports.Console(),
new Winston.transports.File({ filename: 'error.log', level: 'error' }),
new Winston.transports.File({ filename: 'combined.log' }),
],
})

const port: string = process.env.PORT ?? '3000'

const server: Server = http.createServer(index)

server.listen(port, async () => {
console.log(`Server is listening on port ${port}`)
logger.info(`[Init] Server is listening on port ${port}`)
})

0 comments on commit 3baa4dc

Please sign in to comment.