Skip to content

Commit

Permalink
chore: change prod log driver to gcp (interledger#1163)
Browse files Browse the repository at this point in the history
* chore: change prod log driver to gcp

* feat: setup gcp logging with winston
  • Loading branch information
dragosp1011 authored and devcer committed Mar 13, 2024
1 parent 004833b commit bc63dc7
Show file tree
Hide file tree
Showing 6 changed files with 480 additions and 33 deletions.
4 changes: 1 addition & 3 deletions docker/prod/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ name: 'testnet'

x-logging: &logging
logging:
driver: 'json-file'
options:
max-size: '100m'
driver: 'gcplogs'

services:
postgres:
Expand Down
1 change: 1 addition & 0 deletions packages/boutique/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"test": "jest --passWithNoTests --maxWorkers=2"
},
"dependencies": {
"@google-cloud/logging-winston": "^6.0.0",
"@interledger/open-payments": "^6.1.1",
"awilix": "^10.0.1",
"axios": "^1.6.7",
Expand Down
21 changes: 15 additions & 6 deletions packages/boutique/backend/src/config/logger.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import {
createLogger as createWinstonLogger,
format,
LoggerOptions,
transports
} from 'winston'
import { type Env } from './env'
import { env, type Env } from './env'
import { LoggingWinston } from '@google-cloud/logging-winston'

const loggerTransports: LoggerOptions['transports'] = [
new transports.Console({
level: env.NODE_ENV === 'development' ? 'debug' : 'info'
})
]

if (env.NODE_ENV === 'production') {
const loggingWinston = new LoggingWinston()
loggerTransports.push(loggingWinston)
}

export function createLogger(env: Env) {
const logger = createWinstonLogger({
Expand All @@ -19,11 +32,7 @@ export function createLogger(env: Env) {
(info.stack ? `\n${info.stack}` : '')
)
),
transports: [
new transports.Console({
level: env.NODE_ENV === 'development' ? 'debug' : 'info'
})
]
transports: loggerTransports
})

return logger
Expand Down
3 changes: 2 additions & 1 deletion packages/wallet/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"generate": "graphql-codegen --config codegen.yml"
},
"dependencies": {
"@google-cloud/logging-winston": "^6.0.0",
"@sendgrid/mail": "^8.1.1",
"awilix": "^10.0.1",
"axios": "^1.6.7",
"cors": "^2.8.5",
"awilix": "^10.0.1",
"crypto-js": "^4.2.0",
"date-fns": "^3.3.1",
"disposable-email-domains": "^1.0.62",
Expand Down
20 changes: 14 additions & 6 deletions packages/wallet/backend/src/config/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { createLogger, format, transports } from 'winston'
import { createLogger, format, LoggerOptions, transports } from 'winston'
import { env } from './env'
import { LoggingWinston } from '@google-cloud/logging-winston'

const loggerTransports: LoggerOptions['transports'] = [
new transports.Console({
level: env.NODE_ENV === 'development' ? 'debug' : 'info'
})
]

if (env.NODE_ENV === 'production') {
const loggingWinston = new LoggingWinston()
loggerTransports.push(loggingWinston)
}

export const logger = createLogger({
silent: env.NODE_ENV === 'test',
Expand All @@ -14,9 +26,5 @@ export const logger = createLogger({
(info.stack ? `\n${info.stack}` : '')
)
),
transports: [
new transports.Console({
level: env.NODE_ENV === 'development' ? 'debug' : 'info'
})
]
transports: loggerTransports
})
Loading

0 comments on commit bc63dc7

Please sign in to comment.