Skip to content

Enabling access log function like an apache webserver to write user I… #959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"socketCustomEvent": "RTCMultiConnection-Custom-Message",
"port": "9001",
"enableLogs": "false",
"enableAccessLogs": "false",
"autoRebootServerOnFailure": "false",
"isUseHTTPs": "false",
"sslKey": "./fake-keys/privatekey.pem",
Expand Down
28 changes: 17 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@
],
"dependencies": {
"canvas-designer": "latest",
"date-utils": "^1.2.21",
"detectrtc": "latest",
"fbr": "latest",
"getstats": "latest",
"iplocation": "^7.2.0",
"liftoff": "^3.1.0",
"multistreamsmixer": "latest",
"recordrtc": "latest",
"request-ip": "^2.1.3",
"rtcmulticonnection-server": "latest",
"socket.io": "latest",
"webrtc-adapter": "latest"
"webrtc-adapter": "latest",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.0"
},
"analyze": false,
"license": "MIT",
Expand All @@ -69,16 +75,16 @@
"tonicExampleFilename": "npm-test.js",
"_from": "rtcmulticonnection@",
"devDependencies": {
"grunt": "0.4.5",
"grunt-bump": "0.7.0",
"grunt-cli": "0.1.13",
"grunt-contrib-clean": "0.6.0",
"grunt-contrib-concat": "0.5.1",
"grunt-contrib-copy": "0.8.2",
"grunt-contrib-uglify": "0.11.0",
"grunt-contrib-watch": "1.1.0",
"grunt-jsbeautifier": "0.2.10",
"grunt-replace": "0.11.0",
"grunt": "^0.4.5",
"grunt-bump": "^0.7.0",
"grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-uglify": "^0.11.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-jsbeautifier": "^0.2.10",
"grunt-replace": "^0.11.0",
"load-grunt-tasks": "3.4.0"
}
}
33 changes: 33 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const fs = require('fs');
const path = require('path');
const url = require('url');
var httpServer = require('http');
var requestip = require('request-ip');
const winston = require('winston');
require('winston-daily-rotate-file');
require('date-utils');

const ioServer = require('socket.io');
const RTCMultiConnectionServer = require('rtcmulticonnection-server');
Expand Down Expand Up @@ -34,12 +38,41 @@ if(isUseHTTPs === false) {
isUseHTTPs = config.isUseHTTPs;
}

const logger = (() => {
if(config.enableAccessLogs === true) {
return winston.createLogger({
level: 'debug',
transports: [
new winston.transports.DailyRotateFile({
filename : 'access_logs/access_log',
zippedArchive: true,
format: winston.format.printf(
info => `${new Date().toFormat('YYYY-MM-DD HH24:MI:SS')} [${info.level.toUpperCase()}] - ${info.message}`)
}),
new winston.transports.Console({
format: winston.format.printf(
info => `${new Date().toFormat('YYYY-MM-DD HH24:MI:SS')} [${info.level.toUpperCase()}] - ${info.message}`)
})
]
});
} else {
return null;
}
})();

module.exports = logger;

function serverHandler(request, response) {
// to make sure we always get valid info from json file
// even if external codes are overriding it
config = getValuesFromConfigJson(jsonPath);
config = getBashParameters(config, BASH_COLORS_HELPER);

// logs to write access IP of users.
if (config.enableAccessLogs === true && logger != null) {
logger.debug(requestip.getClientIp(request));
}

// HTTP_GET handling code goes below
try {
var uri, filename;
Expand Down