Compare commits

...

8 Commits

Author SHA1 Message Date
Johannes Zellner
2da0ae6dc0 Bump version 2018-06-14 13:21:26 +02:00
Johannes Zellner
bdb9ae36ce Ensure we add a newline to every log message 2018-06-14 13:19:44 +02:00
Johannes Zellner
3357b14ef1 Remove potential line breaks from log lines 2018-06-14 12:10:33 +02:00
Girish Ramakrishnan
2c440d58c2 lockfile 2018-06-11 22:54:15 -07:00
Girish Ramakrishnan
043fc9d1af Parse args 2018-06-11 22:51:40 -07:00
Girish Ramakrishnan
f36f221213 Bump version 2018-06-11 22:41:12 -07:00
Girish Ramakrishnan
5e8a6fdb11 Version 1.0.1 2018-06-11 22:15:02 -07:00
Girish Ramakrishnan
2845790459 Move systemd script and install to box repo 2018-06-11 22:14:11 -07:00
4 changed files with 16 additions and 24 deletions

View File

@@ -1,14 +0,0 @@
[Unit]
Description=Cloudron Syslog
After=network.target
[Service]
ExecStart=/usr/bin/node index.js
WorkingDirectory=/usr/local/cloudron-syslog
Environment="NODE_ENV=production"
Restart=always
User=yellowtent
Group=yellowtent
[Install]
WantedBy=multi-user.target

View File

@@ -8,14 +8,17 @@ var dgram = require('dgram'),
mkdirp = require('mkdirp'),
parser = require('nsyslog-parser');
const LOG_FILE_FOLDER = '/home/yellowtent/platformdata/logs';
const LOG_FILE_NAME = 'app.log';
const PORT = 2514; // syslog is 514 so we prefix with 2
const argv = require('yargs')
.default('port', 2514, 'The port to listen on') // syslog is 514 so we prefix with 2
.default('logdir', '/tmp/logs', 'The root log directory')
.argv;
const argv = require('yargs').argv;
const LOG_FILE_FOLDER = argv.logdir;
const LOG_FILE_NAME = 'app.log';
const PORT = argv.port;
if (argv.version) {
console.log('1.0.0');
console.log('1.0.1');
process.exit(0);
}
@@ -41,12 +44,16 @@ server.on('error', function (error) {
if (!info || !info.appName) return console.log('Ignore unknown app log:', msg.toString());
// remove line breaks to avoid holes in the log file
// we do not ignore empty log lines, to allow gaps for potential ease of readability
const message = info.message.replace(/\n/g, '');
const filePath = path.join(LOG_FILE_FOLDER, info.appName);
const fileName = path.join(filePath, LOG_FILE_NAME);
try {
mkdirp.sync(filePath);
fs.appendFileSync(fileName, info.ts.toISOString() + ' ' + info.message);
fs.appendFileSync(fileName, info.ts.toISOString() + ' ' + message + '\n');
} catch (error) {
console.error(error);
}

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "cloudron-syslog",
"version": "1.0.0",
"version": "1.0.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,11 +1,10 @@
{
"name": "cloudron-syslog",
"version": "1.0.0",
"version": "1.0.2",
"description": "Cloudron Syslog Daemon listening on port 2514",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "cp cloudron-syslog.service /etc/systemd/system/ || true"
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"cloudron-syslog": "./index.js"