Skip to content

Commit

Permalink
feat: Formatted error logging in developer mode
Browse files Browse the repository at this point in the history
  • Loading branch information
paveltiunov committed Apr 11, 2019
1 parent bc09eba commit 3376a50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/cubejs-api-gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class ApiGateway {
} else {
this.log(req, {
type: 'Invalid Token',
token: auth,
error: e.stack || e.toString()
});
return next && next();
Expand Down
38 changes: 22 additions & 16 deletions packages/cubejs-server-core/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ class CubejsServerCore {
this.apiSecret = options.apiSecret;
this.schemaPath = options.schemaPath || 'schema';
this.dbType = options.dbType;
this.logger = options.logger || ((msg, params) => { console.log(`${msg}: ${JSON.stringify(params)}`); });
this.logger = options.logger || ((msg, params) => {
const { error, ...restParams } = params;
if (process.env.NODE_ENV !== 'production') {
console.log(`${msg}: ${JSON.stringify(restParams)}${error ? `\n${error}` : ''}`);
} else {
console.log(JSON.stringify({ message: msg, ...params }));
}
});
this.repository = new FileRepository(this.schemaPath);

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

if (this.options.devServer) {
this.devServer = new DevServer(this);
if (!options.logger) {
this.logger = ((msg, params) => {
if (
msg === 'Load Request' ||
msg === 'Load Request Success' ||
msg === 'Orchestrator error' ||
msg === 'Internal Server Error' ||
msg === 'User Error' ||
msg === 'Compiling schema'
) {
this.event(msg, { error: params.error });
}
console.log(`${msg}: ${JSON.stringify(params)}`);
});
}
const oldLogger = this.logger;
this.logger = ((msg, params) => {
if (
msg === 'Load Request' ||
msg === 'Load Request Success' ||
msg === 'Orchestrator error' ||
msg === 'Internal Server Error' ||
msg === 'User Error' ||
msg === 'Compiling schema'
) {
this.event(msg, { error: params.error });
}
oldLogger(msg, params);
});
let causeErrorPromise;
process.on('uncaughtException', async (e) => {
console.error(e.stack || e);
Expand Down

0 comments on commit 3376a50

Please sign in to comment.