diff --git a/src/cloudron.js b/src/cloudron.js index b0871e0b9..ebcf74c20 100644 --- a/src/cloudron.js +++ b/src/cloudron.js @@ -34,6 +34,7 @@ var assert = require('assert'), platform = require('./platform.js'), progress = require('./progress.js'), reverseProxy = require('./reverseproxy.js'), + safe = require('safetydance'), settings = require('./settings.js'), shell = require('./shell.js'), spawn = require('child_process').spawn, @@ -343,25 +344,49 @@ function getLogs(unit, options, callback) { debug('Getting logs for %s as %s', unit, format); - var args = [ '--lines=' + lines ]; - if (follow) args.push('--follow'); - args.push(path.join(paths.LOG_DIR, unit, 'app.log')); + var cp, transformStream; + if (unit === 'box') { + let args = [ '--no-pager', `--lines=${lines}` ]; + if (format === 'short') args.push('--output=short', '-a'); else args.push('--output=json'); + if (follow) args.push('--follow'); + args.push('--unit=box'); + args.push('--unit=cloudron-updater'); + cp = spawn('/bin/journalctl', args); - var cp = spawn('/usr/bin/tail', args); + transformStream = split(function mapper(line) { + if (format !== 'json') return line + '\n'; - var transformStream = split(function mapper(line) { - if (format !== 'json') return line + '\n'; + var obj = safe.JSON.parse(line); + if (!obj) return undefined; - var data = line.split(' '); // logs are - var timestamp = (new Date(data[0])).getTime(); - if (isNaN(timestamp)) timestamp = 0; + return JSON.stringify({ + realtimeTimestamp: obj.__REALTIME_TIMESTAMP, + monotonicTimestamp: obj.__MONOTONIC_TIMESTAMP, + message: obj.MESSAGE, + source: obj.SYSLOG_IDENTIFIER || '' + }) + '\n'; + }); + } else { // mail, mongodb, mysql, postgresql + let args = [ '--lines=' + lines ]; + if (follow) args.push('--follow'); + args.push(path.join(paths.LOG_DIR, unit, 'app.log')); - return JSON.stringify({ - realtimeTimestamp: timestamp * 1000, - message: line.slice(data[0].length+1), - source: unit - }) + '\n'; - }); + cp = spawn('/usr/bin/tail', args); + + transformStream = split(function mapper(line) { + if (format !== 'json') return line + '\n'; + + var data = line.split(' '); // logs are + var timestamp = (new Date(data[0])).getTime(); + if (isNaN(timestamp)) timestamp = 0; + + return JSON.stringify({ + realtimeTimestamp: timestamp * 1000, + message: line.slice(data[0].length+1), + source: unit + }) + '\n'; + }); + } transformStream.close = cp.kill.bind(cp, 'SIGKILL'); // closing stream kills the child process