4.1.3 • Published 5 years ago

logelas v4.1.3

Weekly downloads
11
License
(MIT OR Apache-2....
Repository
github
Last release
5 years ago

Logelas

Quality Gate Status Bugs Maintainability Rating FOSSA Status

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 { Logger, LogClass } from 'logelas'; // import logelas
const log = new Logger('test.log', 'test'); // create a new virtual logger

@LogClass(log) // provide the logger to the decorator
export class Controller {   
   public action1() {
       log.error(this, 'there is the rror log');
   }
}

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:58.848Z] INFO   √ 100006 :: new Controller() 
[2017-08-25T20:52:02.504Z] INFO   √ 100001 :: Controller.action1 =>  
[2017-08-25T20:52:02.506Z] INFO   √ 100001 :: Controller.action1   a message from inside the method
[2017-08-25T20:52:02.506Z] INFO   √ 100002 :: Controller.action2 =>  
[2017-08-25T20:52:02.507Z] INFO   √ 100002 :: Controller.action2   a message from inside the method
[2017-08-25T20:52:02.507Z] INFO   √ 100003 :: Controller.action3 =>  
[2017-08-25T20:52:02.507Z] WARNIN ‼ 100003 :: Controller.action3   a message from inside the method
[2017-08-25T20:52:02.507Z] INFO   √ 100004 :: Controller.action4 =>  
[2017-08-25T20:52:02.507Z] DEBUG  i 100004 :: Controller.action4   a message from inside the method
[2017-08-25T20:52:02.507Z] INFO   √ 100005 :: Controller.throws =>  
[2017-08-25T20:52:02.508Z] ERROR  × 100005 :: Controller.throws ##  my bad Error: my bad
    at Controller.throws (c:\Git_work\logelas\examples\class-log.js:33:16)
    at Controller.<anonymous> (c:\Git_work\logelas\src\loggerd.js:29:53)
    at Controller.action4 (c:\Git_work\logelas\examples\class-log.js:29:14)
    at Controller.<anonymous> (c:\Git_work\logelas\src\loggerd.js:29:53)
    at Controller.action3 (c:\Git_work\logelas\examples\class-log.js:25:21)
    at Controller.<anonymous> (c:\Git_work\logelas\src\loggerd.js:29:53)
    at Controller.action2 (c:\Git_work\logelas\examples\class-log.js:21:21)
    at Controller.<anonymous> (c:\Git_work\logelas\src\loggerd.js:29:53)
    at Controller.action1 (c:\Git_work\logelas\examples\class-log.js:17:21)
    at Controller.<anonymous> (c:\Git_work\logelas\src\loggerd.js:29:53)
[2017-08-25T20:52:02.508Z] INFO   √ 100004 :: Controller.action4 <=  4
[2017-08-25T20:52:02.508Z] INFO   √ 100003 :: Controller.action3 <=  8
[2017-08-25T20:52:02.508Z] INFO   √ 100002 :: Controller.action2 <=  16
[2017-08-25T20:52:02.508Z] INFO   √ 100001 :: Controller.action1 <=  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.log(this, 'my custom log entry');
logger.debug(this, 'debug this please');
logger.info(this, 'just an info lo entry');
logger.error(this, 'huston we have a problem');
logger.warn(this, 'this is the last warning');

truncate()

use logger.truncate() to clear the log file (useful for testing and development stages)

License

FOSSA Status

4.1.3

5 years ago

4.1.2

5 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.23-beta

5 years ago

4.0.23

5 years ago

4.0.22

5 years ago

4.0.21

5 years ago

4.0.20

5 years ago

4.0.19

5 years ago

4.0.18

5 years ago

4.0.17

5 years ago

4.0.16

5 years ago

4.0.15

5 years ago

4.0.13

5 years ago

4.0.12

5 years ago

4.0.7

5 years ago

4.0.4

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

3.0.14

5 years ago

3.0.11

5 years ago

3.0.10

5 years ago

3.0.8

5 years ago

3.0.7

5 years ago

3.0.6

5 years ago

3.0.5

5 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

2.0.5

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago