Added support for writing profiling logs.

For now it supports profiling database queries and
job execution time.
This commit is contained in:
baldo 2016-07-29 12:53:20 +02:00
parent f0830dc359
commit 7921178165
6 changed files with 22 additions and 8 deletions

View file

@ -116,6 +116,7 @@ Dann die `config.json` anpassen nach belieben. Es gibt die folgenden Konfigurati
* **`server.logging.directory`** Verzeichnis unter dem Log-Files abgelegt werden, z. B.: `"$FFFFNG_HOME/logs"`
* **`server.logging.debug`** Gibt an, ob Debug-Output geloggt werden soll (Achtung, viel!), z. B.: `false`
* **`server.logging.profile`** Gibt an, ob Profiling-Output geloggt werden soll (Achtung, viel!), z. B.: `false`
* **`server.logging.logRequests`** Gib an, ob HTTP-Requests geloggt werden sollen (Achtung, Datenschutz!), z. B.: `false`
* **`server.internal.active`** Gibt an, ob interne URLs, wie Admin-Panel und Logging-Interface, erreichbar sein sollen,

View file

@ -9,6 +9,7 @@
"logging": {
"directory": "/tmp/logs",
"debug": false,
"profile": false,
"logRequests": false
},

View file

@ -63,6 +63,7 @@ var defaultConfig = {
logging: {
directory: '/tmp/logs',
debug: false,
profile: false,
logRequests: false
},

View file

@ -91,6 +91,10 @@ module.exports = {
throw error;
}
db.on('profile', function (sql, time) {
Logger.tag('database').profile('[%sms]\t%s', time, sql);
});
applyMigrations(db, function (err) {
if (err) {
Logger.tag('database').error('Error migrating database:', err);

View file

@ -53,6 +53,8 @@ angular.module('ffffng').factory('Scheduler', function ($injector, Logger, confi
task.state = 'running';
job.run(function () {
var now = moment();
Logger.tag('jobs').profile('[%sms]\t%s', now.diff(task.runningSince), task.name);
task.runningSince = false;
task.state = 'idle';
});

View file

@ -18,16 +18,21 @@ var scribe = require('scribe-js')({
rootPath: config.server.logging.directory,
});
if (config.server.logging.debug) {
process.console.addLogger('debug', 'grey', {
logInConsole: false
});
} else {
process.console.debug = function () {
this._reset(); // forget tags, etc. for this logging event
};
function addLogger(name, color, active) {
if (active) {
process.console.addLogger(name, color, {
logInConsole: false
});
} else {
process.console[name] = function () {
this._reset(); // forget tags, etc. for this logging event
};
}
}
addLogger('debug', 'grey', config.server.logging.debug);
addLogger('profile', 'blue', config.server.logging.profile);
angular.module('ffffng').factory('Logger', function (app) {
if (config.server.logging.logRequests) {
app.use(scribe.express.logger());