'use strict';

var config = require('./config');


// Hack to allow proper logging of Error.
Object.defineProperty(Error.prototype, 'message', {
    configurable: true,
    enumerable: true
});
Object.defineProperty(Error.prototype, 'stack', {
    configurable: true,
    enumerable: true
});


var scribe = require('scribe-js')({
    rootPath: config.server.logging.directory,
});

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());
    }
    if (config.server.internal.active) {
        var prefix = config.server.rootPath === '/' ? '' : config.server.rootPath;
        app.use(prefix + '/internal/logs', scribe.webPanel());
    }

    return process.console;
});

module.exports = process.console;

@@ -1145,16 +1145,492 @@
 %0A    %7D%0A%0A
+    // Hack to allow correct logging of node.js Error objects.%0A    // See: https://github.com/bluejamesbond/Scribe.js/issues/70%0A    Object.defineProperty(Error.prototype, 'toJSON', %7B%0A        configurable: true,%0A        value: function () %7B%0A            var alt = %7B%7D;%0A            var storeKey = function (key) %7B%0A                alt%5Bkey%5D = this%5Bkey%5D;%0A            %7D;%0A            Object.getOwnPropertyNames(this).forEach(storeKey, this);%0A            return alt;%0A        %7D%0A    %7D);%0A%0A
     retu

Allow proper logging of node.js Error objects.