extend logger

This commit is contained in:
Iuri Matias 2019-11-08 17:49:43 -05:00
parent 06a80f86c3
commit 340fbacdee
5 changed files with 12 additions and 4 deletions

View File

@ -89,7 +89,7 @@ export class Engine {
this.debugLog.startSession();
this.events = options.events || this.events || new Events({debugLog: this.debugLog});
this.logger = options.logger || new Logger({context: this.context, logLevel: options.logLevel || this.logLevel || 'info', events: this.events, logFile: this.logFile});
this.logger = options.logger || new Logger({context: this.context, debugLog: this.debugLog, logLevel: options.logLevel || this.logLevel || 'info', events: this.events, logFile: this.logFile});
this.config = new Config({env: this.env, logger: this.logger, debugLog: this.debugLog, events: this.events, context: this.context, webServerConfig: this.webServerConfig, version: this.version, package: this.package});

View File

@ -10,6 +10,7 @@ const LOG_REGEX = new RegExp(/\[(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d:\d\d\d)\] (?:
export class Logger {
constructor(options) {
this.events = options.events || {emit: function(){}};
this.debugLog = options.debugLog;
this.logLevels = Object.keys(Logger.logLevels);
this.logLevel = options.logLevel || 'info';
this._logFunction = options.logFunction || console.log;
@ -91,7 +92,11 @@ Logger.prototype.registerAPICall = function (plugins) {
);
};
Logger.prototype.writeToFile = function (_txt) {
Logger.prototype.writeToFile = function (txt) {
if (this.debugLog) {
this.debugLog.log({parent_id: this.logId, type: "log_info", name: txt});
}
if (!this.logFile) {
return;
}

View File

@ -157,6 +157,7 @@ class EmbarkController {
let runId = engine.debugLog.moduleInit("run_command")
engine.events = engine.debugLog.tagObject(engine.events, runId);
engine.logger = engine.debugLog.tagObject(engine.logger, runId);
engine.registerModuleGroup("coreComponents");
engine.registerModuleGroup("stackComponents");

View File

@ -83,12 +83,14 @@ Plugins.prototype.loadInternalPlugin = function(pluginName, pluginConfig, isPack
let logId = this.debugLog.moduleInit(pluginName);
let events = this.debugLog.tagObject(this.events, logId);
let logger = this.debugLog.tagObject(this.logger, logId);
// let logger = this.logger;
const pluginWrapper = new Plugin({
name: pluginName,
pluginModule: plugin,
pluginConfig: pluginConfig || {},
logger: this.logger,
logger: logger,
debugLog: this.debugLog,
logId: logId,
pluginPath: pluginPath,

View File

@ -4,10 +4,10 @@ class ContractDeployer {
constructor(options) {
// this.events = options.events;
this.logger = options.logger;
this.debugLog = options.debugLog;
this.logId = this.debugLog.moduleInit("ContractDeployer");
this.events = this.debugLog.tagObject(options.events, this.logId);
this.logger = this.debugLog.tagObject(options.logger, this.logId);
this.plugins = options.plugins;
this.deployer = {};