Skip to content

Commit 3376a50

Browse files
committed
feat: Formatted error logging in developer mode
1 parent bc09eba commit 3376a50

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

packages/cubejs-api-gateway/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ class ApiGateway {
302302
} else {
303303
this.log(req, {
304304
type: 'Invalid Token',
305+
token: auth,
305306
error: e.stack || e.toString()
306307
});
307308
return next && next();

packages/cubejs-server-core/core/index.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ class CubejsServerCore {
5656
this.apiSecret = options.apiSecret;
5757
this.schemaPath = options.schemaPath || 'schema';
5858
this.dbType = options.dbType;
59-
this.logger = options.logger || ((msg, params) => { console.log(`${msg}: ${JSON.stringify(params)}`); });
59+
this.logger = options.logger || ((msg, params) => {
60+
const { error, ...restParams } = params;
61+
if (process.env.NODE_ENV !== 'production') {
62+
console.log(`${msg}: ${JSON.stringify(restParams)}${error ? `\n${error}` : ''}`);
63+
} else {
64+
console.log(JSON.stringify({ message: msg, ...params }));
65+
}
66+
});
6067
this.repository = new FileRepository(this.schemaPath);
6168

6269
const Analytics = require('analytics-node');
@@ -91,21 +98,20 @@ class CubejsServerCore {
9198

9299
if (this.options.devServer) {
93100
this.devServer = new DevServer(this);
94-
if (!options.logger) {
95-
this.logger = ((msg, params) => {
96-
if (
97-
msg === 'Load Request' ||
98-
msg === 'Load Request Success' ||
99-
msg === 'Orchestrator error' ||
100-
msg === 'Internal Server Error' ||
101-
msg === 'User Error' ||
102-
msg === 'Compiling schema'
103-
) {
104-
this.event(msg, { error: params.error });
105-
}
106-
console.log(`${msg}: ${JSON.stringify(params)}`);
107-
});
108-
}
101+
const oldLogger = this.logger;
102+
this.logger = ((msg, params) => {
103+
if (
104+
msg === 'Load Request' ||
105+
msg === 'Load Request Success' ||
106+
msg === 'Orchestrator error' ||
107+
msg === 'Internal Server Error' ||
108+
msg === 'User Error' ||
109+
msg === 'Compiling schema'
110+
) {
111+
this.event(msg, { error: params.error });
112+
}
113+
oldLogger(msg, params);
114+
});
109115
let causeErrorPromise;
110116
process.on('uncaughtException', async (e) => {
111117
console.error(e.stack || e);

0 commit comments

Comments
 (0)