Skip to content

Commit ccdf0dd

Browse files
nichtichrubensworks
authored andcommitted
Extend logging
Support logging to STDOUT via setting `logging.file` to `false` and customization of log format with `logging.format`. The default value `null` falls back to default format. Custom format is required for proper logging behind a reverse proxy to log the remote IP from HTTP header `X-Forwarded-For` instead of the proxy IP.
1 parent a1e7dbe commit ccdf0dd

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

bin/ldf-server

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,13 @@ else {
158158
if (loggingSettings.enabled) {
159159
var accesslog = require('access-log');
160160
config.accesslogger = function (request, response) {
161-
accesslog(request, response, null, function (logEntry) {
162-
fs.appendFile(loggingSettings.file, logEntry + '\n', function (error) {
163-
error && process.stderr.write('Error when writing to access log file: ' + error);
164-
});
161+
accesslog(request, response, loggingSettings.format, function (logEntry) {
162+
if (loggingSettings.file) {
163+
fs.appendFile(loggingSettings.file, logEntry + '\n', function (error) {
164+
error && process.stderr.write('Error when writing to access log file: ' + error);
165+
});
166+
}
167+
else console.log(logEntry);
165168
});
166169
};
167170
}

config/config-defaults.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,9 @@
5555
}
5656
},
5757

58-
"logging": { "enabled": false, "file": "access.log" }
58+
"logging": {
59+
"enabled": false,
60+
"file": "access.log",
61+
"format": null
62+
}
5963
}

0 commit comments

Comments
 (0)