-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathnext-logger.config.cjs
More file actions
56 lines (50 loc) · 1.7 KB
/
Copy pathnext-logger.config.cjs
File metadata and controls
56 lines (50 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pino = require('pino'); // It's ok that pino is transit dependency, it's required by next-logger
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { satanizer, commonPatterns } = require('@lidofinance/satanizer');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const loadEnvConfig = require('@next/env').loadEnvConfig;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { clampArgs } = require('./utilsApi/clamp-log-args.cjs');
// Must load env first
const projectDir = process.cwd();
loadEnvConfig(projectDir);
const RPC_URL_ENV_KEYS = [
'EL_RPC_URLS_1',
'EL_RPC_URLS_10',
'EL_RPC_URLS_130',
'EL_RPC_URLS_1301',
'EL_RPC_URLS_17000',
'EL_RPC_URLS_560048',
'EL_RPC_URLS_11155111',
'EL_RPC_URLS_11155420',
];
// Comma-split so each URL becomes its own pattern; otherwise satanizer only matches the full concatenation.
const rpcUrlPatterns = RPC_URL_ENV_KEYS.flatMap((key) =>
(process.env[key] || '')
.split(',')
.map((url) => url.trim())
.filter(Boolean),
);
const patterns = [...commonPatterns, ...rpcUrlPatterns].filter(Boolean);
const mask = satanizer(patterns);
const logger = (defaultConfig) =>
pino({
...defaultConfig,
formatters: {
...defaultConfig.formatters,
level(label, _number) {
return { level: label };
},
},
hooks: {
// Cap arguments before masking — masking cost grows faster than linearly
// with payload size. See utilsApi/clamp-log-args.cjs for the limits.
logMethod(inputArgs, method) {
return method.apply(this, mask(clampArgs(inputArgs)));
},
},
});
module.exports = {
logger,
};