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.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.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.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, * **`server.internal.active`** Gibt an, ob interne URLs, wie Admin-Panel und Logging-Interface, erreichbar sein sollen,

View file

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

View file

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

View file

@ -91,6 +91,10 @@ module.exports = {
throw error; throw error;
} }
db.on('profile', function (sql, time) {
Logger.tag('database').profile('[%sms]\t%s', time, sql);
});
applyMigrations(db, function (err) { applyMigrations(db, function (err) {
if (err) { if (err) {
Logger.tag('database').error('Error migrating database:', 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'; task.state = 'running';
job.run(function () { job.run(function () {
var now = moment();
Logger.tag('jobs').profile('[%sms]\t%s', now.diff(task.runningSince), task.name);
task.runningSince = false; task.runningSince = false;
task.state = 'idle'; task.state = 'idle';
}); });

View file

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