Skip to content

Commit

Permalink
log directly to syslog via unix socket
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Jul 27, 2018
1 parent c6dff95 commit 3702613
Show file tree
Hide file tree
Showing 48 changed files with 9,200 additions and 4 deletions.
2 changes: 1 addition & 1 deletion addon_files/redmatic/bin/redmaticLoader
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ RED=$RED_DIR/red.js

SETTINGS=$ADDON_DIR/lib/settings.js

$NODE $RED -s $SETTINGS 2>&1 | logger -p user.info -t node-red
$NODE $RED -s $SETTINGS 2>&1 | logger -p daemon.err -t node-red
2 changes: 1 addition & 1 deletion addon_files/redmatic/etc/default-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"userDir": "/usr/local/addons/redmatic/var",
"httpRoot": "/addons/red",
"logging": {
"console": {
"ain": {
"level": "info",
"metrics": false,
"audit": false
Expand Down
44 changes: 44 additions & 0 deletions addon_files/redmatic/lib/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const Ain = require('ain2');

const ain = new Ain({
tag: 'node-red',
facility: 'daemon',
path: '/dev/log'
});

const allowEmptyLine = false;

ain.setMessageComposer(function (message, severity) {
return new Buffer('<' + (this.facility * 8 + severity) + '>' + this.tag + '[' + process.pid + ']: ' + message);
});

const levelNames = {
10: 'crit', // fatal
20: 'err',
30: 'warn',
40: 'info',
50: 'debug',
60: 'debug', // trace
98: 'debug', // audit
99: 'info' // metric
};

module.exports = {
logging: {
ain: {
handler: () => {
return msg => {
if (msg && typeof msg.msg === 'string') {
const lines = msg.msg.split('\n');
lines.forEach(line => {
if (line || allowEmptyLine) {
const message = (msg.type ? '[' + msg.type + ':' + (msg.name || msg.id) + '] ' : '') + line;
ain.send(message, levelNames[msg.level]);
}
});
}
}
}
}
}
};
36 changes: 34 additions & 2 deletions addon_files/redmatic/lib/settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
const fs = require('fs');

const defaults = require('/usr/local/addons/redmatic/lib/node_modules/node-red/settings.js');
const settings = require('/usr/local/addons/redmatic/etc/settings.json');
const logging = require('/usr/local/addons/redmatic/lib/logger.js');

// Migration
if (settings.logging.console) {
settings.logging.ain = settings.logging.console;
delete settings.logging.console;
fs.writeFileSync('/usr/local/addons/redmatic/etc/settings.json', JSON.stringify(settings, null, ' '));
}

// Credentials encryption key
if (fs.existsSync('/usr/local/addons/redmatic/etc/credentials.key')) {
settings.credentialSecret = fs.readFileSync('/usr/local/addons/redmatic/etc/credentials.key').toString();
}

// Logging
delete defaults.logging.console;
Object.assign(logging.logging.ain, settings.logging.ain);

// https://github.com/hobbyquaker/RedMatic/issues/45
if (!defaults.editorTheme) {
defaults.editorTheme = {};
}
if (!defaults.editorTheme.projects) {
defaults.editorTheme.projects = {};
}
defaults.editorTheme.projects.enabled = false;

module.exports = Object.assign(
require('/usr/local/addons/redmatic/lib/node_modules/node-red/settings.js'),
require('/usr/local/addons/redmatic/etc/settings.json')
defaults,
settings,
logging
);
22 changes: 22 additions & 0 deletions prebuilt/armv6l/lib/node_modules/ain2/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3702613

Please sign in to comment.