Skip to content

Commit ee0a230

Browse files
butlerxWardormeur
authored andcommitted
make production logs less noisy (CoderDojo#174)
* make production logs less noicy * check for prod * handle lack of stack trace
1 parent d115f73 commit ee0a230

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
FROM mhart/alpine-node:0.10.48
22
MAINTAINER butlerx <[email protected]>
3+
ENV NODE_ENV=production
34
ARG DEP_VERSION=latest
4-
RUN apk add --update git build-base python postgresql-client
5-
RUN mkdir -p /usr/src/app
5+
RUN apk add --update git build-base python postgresql-client &&\
6+
mkdir -p /usr/src/app
67
WORKDIR /usr/src/app
7-
ADD . /usr/src/app
8+
COPY . /usr/src/app
89
RUN npm install && \
9-
npm install cp-translations@$DEP_VERSION && \
10+
npm install cp-translations@"$DEP_VERSION" && \
1011
apk del build-base python && \
1112
rm -rf /tmp/* /root/.npm /root/.node-gyp
1213
EXPOSE 10306
13-
CMD ["npm", "start"]
14+
CMD ["npm", "start"]

dev.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FROM mhart/alpine-node:0.10.48
22
MAINTAINER butlerx <[email protected]>
3+
ENV NODE_ENV=development
34
RUN apk add --update git build-base python postgresql-client && \
45
mkdir -p /usr/src/app /usr/src/cp-translations
56
COPY docker-entrypoint.sh /usr/src

service.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ var store = require('seneca-postgresql-store');
1212
var dgram = require('dgram');
1313
var service = 'cp-events-service';
1414
var sanitizeHtml = require('sanitize-html');
15-
var log = require('cp-logs-lib')({name: service, level: 'warn'});
15+
var log = require('cp-logs-lib')({ name: service, level: 'warn' });
1616
config.log = log.log;
1717

18-
seneca.log.info('using config', JSON.stringify(config, null, 4));
18+
if (process.env.NODE_ENV !== 'production') {
19+
seneca.log.info('using config', JSON.stringify(config, null, 4));
20+
}
1921
seneca.options(config);
2022
/**
2123
* TextArea fields contains user generated html.
@@ -39,26 +41,33 @@ seneca.options.sanitizeTextArea = {
3941
};
4042
seneca.decorate('customValidatorLogFormatter', require('./lib/custom-validator-log-formatter'));
4143
seneca.use(store, config['postgresql-store']);
42-
seneca.use(require('./lib/cd-events'), {logger: log.logger});
44+
seneca.use(require('./lib/cd-events'), { logger: log.logger });
4345
seneca.use(require('cp-permissions-plugin'), {
4446
config: __dirname + '/config/permissions'
4547
});
4648

4749
seneca.use(require('seneca-queue'));
4850
seneca.use(require('seneca-kue'));
49-
seneca.use(require('./lib/queues'), {config: config.kue});
51+
seneca.use(require('./lib/queues'), { config: config.kue });
52+
5053
process.on('SIGINT', shutdown);
5154
process.on('SIGTERM', shutdown);
5255
process.on('uncaughtException', shutdown);
5356
process.on('SIGUSR2', shutdown);
5457

5558
function shutdown (err) {
56-
var stopQueue = seneca.export('queues/queue')['stopQueue'];
59+
var stopQueue = seneca.export('queues/queue').stopQueue;
5760
stopQueue();
58-
if (err !== void 0 && err.stack !== void 0) {
59-
console.error(new Date().toString() + ' FATAL: UncaughtException, please report: ' + util.inspect(err));
60-
console.error(util.inspect(err.stack));
61-
console.trace();
61+
if (err !== undefined) {
62+
var error = {
63+
date: new Date().toString(),
64+
msg: err.stack !== undefined
65+
? 'FATAL: UncaughtException, please report: ' + util.inspect(err.stack)
66+
: 'FATAL: UncaughtException, no stack trace',
67+
err: util.inspect(err)
68+
};
69+
console.error(JSON.stringify(error));
70+
process.exit(1);
6271
}
6372
process.exit(0);
6473
}
@@ -86,7 +95,11 @@ require('./migrate-psql-db.js')(function (err) {
8695
seneca.wrap('role: entity, cmd: ' + cmd, function filterFields (args, cb) {
8796
try {
8897
['limit$', 'skip$'].forEach(function (field) {
89-
if (args.q[field] && args.q[field] !== 'NULL' && !/^[0-9]+$/g.test(args.q[field] + '')) {
98+
if (
99+
args.q[field] &&
100+
args.q[field] !== 'NULL' &&
101+
!/^[0-9]+$/g.test(args.q[field] + '')
102+
) {
90103
throw new Error('Expect limit$, skip$ to be a number');
91104
}
92105
});

0 commit comments

Comments
 (0)