Simple nano logger service for javascript applications. Logman leverages usage of console object and it's methods to log different your messages into browser's console.
Note: Logman isn't a crash reporter and it will shut up on production by checking NODE_ENV environment variable. Make sure to set NODE_ENV=production when building your Javscript application.
npm install @farskid/logman
importLogmanfrom"logman";constlogger=newLogman("my-logger");logger.log("Log me first");// [[my-logger]] Log me firstlogger.error("Log me as an error");// [[my-logger]] Log me as an errorconstLogman=require("logman");constlogger=newLogman("my-logger");logger.log("Log me first");// [[my-logger]] Log me firstlogger.error("Log me as an error");// [[my-logger]] Log me as an error/* You can create multiple instances of Logman for different namespaces*/constuserLogs=newLogman("user-logs");constexceptionLogs=newLogman("exceptions");userLogs.log("user is logged out");// [user-logs] user is logged outexceptionLogs.error("Caught some http exceptions");// [exceptions] Caught some http exceptions/* You can put logger into sleep temporarily. When logger instance is in sleep mode, it reject any action.*/userLogs.sleep();userLogs.log("This won`t be logged");userLLogs.error("This won`t be logged as well!");/* You can awaken the logger again by using awake() method */userLogs.awake();userLogs.log('ok! I"m back');/* To check whether logger is sleep or not, you can use isSleep prop. isSleep is *false* by default*/userLog.isSleep;// falseuserLog.sleep();userLog.isSleep;// trueuserLog.awake();userLog.isSleep;// false/* You can destroy a Logman instance too! Obviously this is just a soft destory and a one way to make logger inactive forever. If you want the logger to be destroyed permenantly and be garbage collected (memory efficient), you can do one of these: let logger = new Logman('temp-logger'); logger = null; Or if you're using multiple loggers, you can store them in a single object: const loggers = { firstLogger: new Logman('first-logger'), secondLogger: new Logman('second-logger') }; delete loggers.firstLogger; delete loggers.secondLogger;*/userLog.destroy();- Accept custom adapter (default to window.console)
- Automatic logs on common events
- Log timestamps
Logman is published under MIT license.