Skip to content
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

Support more human readable log output #1929

Merged
merged 15 commits into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/attestation-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ You can use the following environment variables to configure the attestation ser

### Operations

This service uses `bunyan` for structured logging with JSON lines. You can pipe STDOUT to `yarn run bunyan` for a more human friendly output. The `LOG_LEVEL` environment variable can specify desired log levels. With `LOG_FORMAT=stackdriver` you can get stackdriver specific format to recover information such as error traces etc.
This service uses `bunyan` for structured logging with JSON lines. You can pipe STDOUT to `yarn run bunyan` for a more human friendly output. The `LOG_LEVEL` environment variable can specify desired log levels. We support the following `LOG_FORMAT`s:

- Default are json lines `LOG_FORMAT=json`
- With `LOG_FORMAT=stackdriver` you can get stackdriver specific format to recover information such as error traces etc.
- To get something more human readable, use `LOG_FORMAT=human`

This service exposes prometheus metrics under `/metrics`.

Expand Down
6 changes: 3 additions & 3 deletions packages/attestation-service/config/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TWILIO_ACCOUNT_SID=x
TWILIO_MESSAGING_SERVICE_SID=x
TWILIO_AUTH_TOKEN=x
TWILIO_BLACKLIST=
# Options: default, stackdriver
LOG_FORMAT=
# Options: json (default), human, stackdriver
LOG_FORMAT= human
# Options: fatal, error, warn, info, debug, trace
LOG_LEVEL=
LOG_LEVEL=
1 change: 1 addition & 0 deletions packages/attestation-service/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
declare module 'nexmo'
declare module 'express-request-id'
declare module 'bunyan-debug-stream'
1 change: 1 addition & 0 deletions packages/attestation-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"body-parser": "1.19.0",
"bunyan": "1.8.12",
"bunyan-gke-stackdriver": "0.1.2",
"bunyan-debug-stream": "2.0.0",
"debug": "^4.1.1",
"dotenv": "8.0.0",
"eth-lib": "^0.2.8",
Expand Down
19 changes: 14 additions & 5 deletions packages/attestation-service/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import Logger, { createLogger, levelFromName, LogLevelString, stdSerializers } from 'bunyan'
import bunyanDebugStream from 'bunyan-debug-stream'
import { createStream } from 'bunyan-gke-stackdriver'
import { fetchEnvOrDefault } from './env'

const logLevel = fetchEnvOrDefault('LOG_LEVEL', 'info') as LogLevelString
const logFormat = fetchEnvOrDefault('LOG_FORMAT', 'default')
const logFormat = fetchEnvOrDefault('LOG_FORMAT', 'json')

const stream =
logFormat === 'stackdriver'
? createStream(levelFromName[logLevel])
: { stream: process.stdout, level: logLevel }
let stream: any
switch (logFormat) {
case 'stackdriver':
stream = createStream(levelFromName[logLevel])
break
case 'human':
stream = { level: logLevel, stream: bunyanDebugStream() }
break
default:
stream = { stream: process.stdout, level: logLevel }
break
}

export const rootLogger: Logger = createLogger({
name: 'attestation-service',
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9319,6 +9319,14 @@ bun@^0.0.12:
dependencies:
readable-stream "~1.0.32"

bunyan-debug-stream@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/bunyan-debug-stream/-/bunyan-debug-stream-2.0.0.tgz#b9593e38753f594e3f9db3eb2fdebdc2af147a9f"
integrity sha512-Ovl43CJ7nUwalLzdXc6E1nGIy6ift9Z/QpYXUtsjpDAg35ZFKXifKNZyfpMGuN3N7ijLLqbnxPsMMHsXDdXa9A==
dependencies:
colors "^1.0.3"
exception-formatter "^1.0.4"

bunyan-debug-stream@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/bunyan-debug-stream/-/bunyan-debug-stream-1.1.1.tgz#4740a00b7d5c2d9d1b714925ab0802516040813e"
Expand Down