You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//somewhere in your init script/classconstlog4bro=require("log4bro");constoptions={"productionMode": true,//switches loglevel between DEBUG and WARN"logDir": "logs",//relative directory to write log file to"silence": false,//silences logger"loggerName": "dev",//ignore"dockerMode": true,//disables output to logfile"varKey": "LOG"//name of global variable};constlogger=newlog4bro(options);//in any other script/class//- logger becomes a global objectLOG.trace("bla");LOG.debug("bla");LOG.info("bla");LOG.warn("bla");LOG.error("bla");LOG.fatal("bla");//thats all there is to it..
different example show text & json output
(just run npm start to run example locally)
varlog4bro=require("log4bro");varoptions={"productionMode": false,"logDir": "logs","skipEnhance": true,"namespace": "","silence": false,"loggerName": "dev","dockerMode": false,"varKey": "MLOG"};varlogger=newlog4bro(options);varmsg="ich mache mir sorgen, ob der logger denn noch funktioniert.";MLOG.trace(msg);MLOG.debug(msg);MLOG.info(msg);MLOG.warn(msg);MLOG.error(msg);MLOG.fatal(msg);MLOG.info(options);console.log("");/* json style */varoptions2={"productionMode": true,"logDir": "logs","skipEnhance": true,"namespace": "","silence": false,"loggerName": "dev","dockerMode": true,"varKey": "JLOG","logFieldOptions": {"log_type": "application","application_type": "service","service": "bro-service"}};varlogger2=newlog4bro(options2);JLOG.trace(msg);JLOG.debug(msg);JLOG.info(msg);JLOG.warn(msg);JLOG.error(msg);JLOG.fatal(msg);JLOG.error(options2);
auto express.js access log logging
varexpress=require("express");varlog4bro=require("./../../index.js");varoptions={"productionMode": false,"logDir": "logs","skipEnhance": true,"namespace": "","silence": false,"loggerName": "dev","dockerMode": true,"varKey": "MLOG","level": "DEBUG","serviceName": "cool-service"};varlogger=newlog4bro(options);varapp=express();// log an elk formatted access log to coutlogger.applyMiddlewareAccessLog(app);//log an elk formatted access log to a filelogger.applyMiddlewareAccessLogFile(app,"./access_log.json");
enjoy.. need help? contact me.. @krystianity or on twitter: @silentleave