Logelas
motivation
When we build large projects using modules and components, it is best to implement a logging abstraction rather than actual loging library bindings and dependecies, we can than aggregate the virtual loggers to log transports available at the installing application.
Here is a small example of a class decorated with LogClass decorator.
; // import logelas; // create a new virtual logger // provide the logger to the decorator
Logger
create a file based logger
new Logger([filename], [debugSymbol])
@LogClass, @Log decorators
use @LogClass
at the top of your class and @Log
for every method you wish to log.
logelas will create a log entry for every call to the method and for every value returned by it. the log file may look like this:
2017-08-25T20:51:58848Z INFO √ 100006 :: 2017-08-25T20:52:02504Z INFO √ 100001 :: Controlleraction1 2017-08-25T20:52:02506Z INFO √ 100001 :: Controlleraction1 a message from inside the method2017-08-25T20:52:02506Z INFO √ 100002 :: Controlleraction2 2017-08-25T20:52:02507Z INFO √ 100002 :: Controlleraction2 a message from inside the method2017-08-25T20:52:02507Z INFO √ 100003 :: Controlleraction3 2017-08-25T20:52:02507Z WARNIN ‼ 100003 :: Controlleraction3 a message from inside the method2017-08-25T20:52:02507Z INFO √ 100004 :: Controlleraction4 2017-08-25T20:52:02507Z DEBUG i 100004 :: Controlleraction4 a message from inside the method2017-08-25T20:52:02507Z INFO √ 100005 :: Controllerthrows 2017-08-25T20:52:02508Z ERROR × 100005 :: Controllerthrows ## my bad Error: my bad at Controller at Controller<anonymous> c:\Git_work\logelas\src\loggerdjs:29:53 at Controller at Controller<anonymous> c:\Git_work\logelas\src\loggerdjs:29:53 at Controller at Controller<anonymous> c:\Git_work\logelas\src\loggerdjs:29:53 at Controller at Controller<anonymous> c:\Git_work\logelas\src\loggerdjs:29:53 at Controller at Controller<anonymous> c:\Git_work\logelas\src\loggerdjs:29:532017-08-25T20:52:02508Z INFO √ 100004 :: Controlleraction4 <= 42017-08-25T20:52:02508Z INFO √ 100003 :: Controlleraction3 <= 82017-08-25T20:52:02508Z INFO √ 100002 :: Controlleraction2 <= 162017-08-25T20:52:02508Z INFO √ 100001 :: Controlleraction1 <= 32
Manual logging
some times we need to log something within the method logic. using the same logger as the @LogClass decorator we can easily emit log messages that will automatically log the class and method names and id.
logger;logger;logger;logger;logger;
truncate()
use logger.truncate()
to clear the log file (useful for testing and development stages)