import logger from '../src/logger' let log = {} class LogTest { constructor(opts) { log = logger({ // pretty: {translateTime:true, colorize:true, levelFirst:true } // options for pino pretty printer // env:'', // 'dev' or 'pro' -- can be use to set/override UCI_ENV environment variable // enForce: false, // only used with .evn. if true will override UCI_ENV if it is set, otherwise no // level:'debug', // info is default level, set level to lowest visible // clear: false, // true for log files will clear the current log file on restart // logFileName:'test', // if not supplied log filename will be generated from timestamp // below are BASE properties which are optional and are passed to child logger instance and will be part of json log entry // libraryName: 'UCI', // will be logged as name: can be used to identify logs of related packages, can be set via UCI_LOG_NAME env variable appName:'uci-example-logger', //will be used for logging directory name if supplied and will be logged as well package: '@uci/test', // name of package with scope per package.json // repo: // will use scope-name from package prop if not supplied id: opts.id, // can pass a unique if for easy later search/filtering // file: 'example/example.js', // path (to repo root) of actual file running this logger, default is ./src/.js // class: 'LogTest', // The class that created this logger if any /*---------------- Can pass through additional props for every log by including this `additional` property object should not use any keys above or level,time,msg,pid,hostname, logPath,instanceCreatedHR,instanceCreated as keys in this object will be merged ------------------*/ // additional: {anotherprop:'test'} }) } logit() { log.trace('this is a trace level logged message') log.debug('this is a debug level logged message') log.info({runtimeprop:'somevalue', msg:'this is a info level logged message'}) log.warn('this is a warn level logged message') log.error('this is a error level logged message') log.fatal('this is a fatal level logged message') } } let test = new LogTest({id:'logtest-via-new'}) log.div(`the default log level based on option or UCI_LOG_LEVEL ${log.default}`) test.logit() log.lvlset('fatal') log.div(`now changing log level manually in code to ${log.level}`) test.logit() log.div(`reset level back current default ${log.default}`) log.lvlset() test.logit() log.clear('This call to log.clear could clear the file log when implemented')