# logelas

Latest version **4.1.3** (published 2019-08-04) · (MIT OR Apache-2.0) license · 0 weekly downloads

## Install

```sh
npm install logelas
pnpm add logelas
yarn add logelas
bun add logelas
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.1.3 |
| Published | 2019-08-04 |
| First published | 2017-08-12 |
| Weekly downloads | 0 |
| License | (MIT OR Apache-2.0) |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 347.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | nodulusteam |
| Maintainers | nodulus |
| Keywords | nodulus, logelas, logs, logging |

## Links

- npm: https://www.npmjs.com/package/logelas
- Repository: https://github.com/nodulusteam/logelas
- Homepage: https://nodulusteam.github.io/logelas/
- Issues: https://github.com/nodulusteam/logelas/issues
- npm.io page: https://npm.io/package/logelas

## Dependencies (2)

- [debug](https://npm.io/package/debug.md) ^3.0.1
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.12

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 4.1.3 (latest) — 2019-08-04
- 4.1.2 — 2019-07-24
- 4.1.1 — 2019-07-23
- 4.1.0 — 2019-07-23
- 4.0.23-beta — 2019-07-22
- 4.0.23 — 2019-06-19
- 4.0.22 — 2019-06-15
- 4.0.21 — 2019-06-05
- 4.0.20 — 2019-06-02
- 4.0.19 — 2019-06-02
- 4.0.18 — 2019-05-20
- 4.0.17 — 2019-05-20
- 4.0.16 — 2019-05-17
- 4.0.15 — 2019-05-16
- 4.0.13 — 2019-05-16
- … 31 more at https://npm.io/package/logelas/versions

## README

# Logelas

<a href="https://travis-ci.org/nodulusteam/logelas">
<img src="./logelas.png" alt="Drawing" style="max-width: 150px!important;"/>
</a>

[<img src="https://travis-ci.org/nodulusteam/logelas.svg?branch=master">](https://travis-ci.org/nodulusteam/logelas) 
 [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nodulusteam_logelas&metric=alert_status)](https://sonarcloud.io/dashboard?id=nodulusteam_logelas)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=nodulusteam_logelas&metric=bugs)](https://sonarcloud.io/dashboard?id=nodulusteam_logelas)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=nodulusteam_logelas&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=nodulusteam_logelas)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fnodulusteam%2Flogelas.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fnodulusteam%2Flogelas?ref=badge_shield)


### 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.

 ```typescript
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:
```javascript
[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.

```javascript

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](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fnodulusteam%2Flogelas.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fnodulusteam%2Flogelas?ref=badge_large)

---
_Source: https://npm.io/package/logelas · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
