Compare commits
8 Commits
syslog-v1.
...
syslog-v1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2da0ae6dc0 | ||
|
|
bdb9ae36ce | ||
|
|
3357b14ef1 | ||
|
|
2c440d58c2 | ||
|
|
043fc9d1af | ||
|
|
f36f221213 | ||
|
|
5e8a6fdb11 | ||
|
|
2845790459 |
@@ -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
|
||||
19
index.js
19
index.js
@@ -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
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cloudron-syslog",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.2",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user