Skip to content

Commit 3129d7d

Browse files
committed
add log to file
1 parent 943ea85 commit 3129d7d

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ RUN set -ex \
2020
FROM node:14-alpine AS final
2121
WORKDIR /app
2222
COPY --from=build /app /app
23+
RUN mkdir /app/logs
24+
RUN chown 1000 /app/logs
2325
ENV HTTP_PORT=8080 HTTPS_PORT=8443
2426
EXPOSE $HTTP_PORT $HTTPS_PORT
2527
USER 1000

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ var concat = require('concat-stream');
99
const { promisify } = require('util');
1010
const sleep = promisify(setTimeout);
1111

12+
var fs = require('fs');
13+
var util = require('util');
14+
var log_file = fs.createWriteStream(__dirname + '/logs/debug.log', {flags : 'w'});
15+
var log_stdout = process.stdout;
16+
17+
// write to a logfile besides the console
18+
console.log = function(d) { //
19+
log_file.write(util.format(d) + '\n');
20+
log_stdout.write(util.format(d) + '\n');
21+
};
22+
1223
app.set('json spaces', 2);
1324
app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']);
1425

0 commit comments

Comments
 (0)