Skip to content

Commit d6faa84

Browse files
feat: Add ENV var to use json logging
Signed-off-by: kasey-alusi-vcc <kasey.alusi@validationcloud.io>
1 parent c2c0cd4 commit d6faa84

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Unless you need to set a non-default value, it is recommended to only populate o
119119
| `HEDERA_NETWORK` | "" | Which network to connect to. Automatically populates the main node & mirror node endpoints. Can be `previewnet`, `testnet`, `mainnet` or a map of network IPs -> node accountIds e.g. `{"127.0.0.1:50211":"0.0.3"}` |
120120
| `INPUT_SIZE_LIMIT` | "1mb" | The [koa-jsonrpc](https://github.com/Bitclimb/koa-jsonrpc) maximum size allowed for requests |
121121
| `LOG_LEVEL` | "trace" | The logging level for the application. Valid values are `trace`, `debug`, `info`, `warn`, `error`, and `fatal`. |
122+
| `LOG_FORMAT` | "pretty" | The logging output format. Valid values are `pretty` (human-readable with colors) and `json` (structured JSON format for log aggregation systems). |
122123
| `MAX_BLOCK_RANGE` | "5" | The maximum block number greater than the mirror node's latest block to query for |
123124
| `OPERATOR_ID_MAIN` | "" | Operator account ID used to pay for transactions. In `S.R.N` format, e.g. `0.0.1001`. |
124125
| `OPERATOR_KEY_FORMAT` | "DER" | Operator private key format. Valid types are `DER`, `HEX_ECDSA`, or `HEX_ED25519` |

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/config-service/src/services/globalConfig.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ const _CONFIG = {
362362
required: false,
363363
defaultValue: 'trace',
364364
},
365+
LOG_FORMAT: {
366+
type: 'string',
367+
required: false,
368+
defaultValue: 'pretty',
369+
},
365370
MAX_BLOCK_RANGE: {
366371
type: 'number',
367372
required: false,

packages/server/src/server.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { spec } from './koaJsonRpc/lib/RpcError';
1818
// https://nodejs.org/api/async_context.html#asynchronous-context-tracking
1919
const context = new AsyncLocalStorage<{ requestId: string }>();
2020

21+
const logFormat = ConfigService.get('LOG_FORMAT');
22+
2123
const mainLogger = pino({
2224
name: 'hedera-json-rpc-relay',
2325
level: ConfigService.get('LOG_LEVEL'),
@@ -26,16 +28,19 @@ const mainLogger = pino({
2628
const store = context.getStore();
2729
return store ? { requestId: `[Request ID: ${store.requestId}] ` } : {};
2830
},
29-
transport: {
30-
target: 'pino-pretty',
31-
options: {
32-
colorize: true,
33-
translateTime: true,
34-
messageFormat: '{requestId}{msg}',
35-
// Ignore one or several keys, nested keys are supported with each property delimited by a dot character (`.`)
36-
ignore: 'requestId',
31+
// Only use pino-pretty when LOG_FORMAT is set to 'pretty' (default)
32+
...(logFormat === 'pretty' && {
33+
transport: {
34+
target: 'pino-pretty',
35+
options: {
36+
colorize: true,
37+
translateTime: true,
38+
messageFormat: '{requestId}{msg}',
39+
// Ignore one or several keys, nested keys are supported with each property delimited by a dot character (`.`)
40+
ignore: 'requestId',
41+
},
3742
},
38-
},
43+
}),
3944
});
4045

4146
export const logger = mainLogger.child({ name: 'rpc-server' });

0 commit comments

Comments
 (0)