# loggerto

> Allows you to track the registry

Latest version **0.0.5** (published 2021-10-05) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2021-10-05 |
| First published | 2021-10-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 24.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Edu Rafael |
| Maintainers | edu_rafael |
| Keywords | log, logger, trace |

## Links

- npm: https://www.npmjs.com/package/loggerto
- Repository: https://github.com/EduRafael/loggerto
- Homepage: https://github.com/EduRafael/loggerto#readme
- Issues: https://github.com/EduRafael/loggerto/issues
- npm.io page: https://npm.io/package/loggerto

## Dependencies (1)

- [express-http-context](https://npm.io/package/express-http-context.md) ^1.2.4

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

- 0.0.5 (latest) — 2021-10-05
- 0.0.4 — 2021-10-04
- 0.0.3 — 2021-10-04
- 0.0.2 — 2021-10-04
- 0.0.1 — 2021-10-04

## README

<div align-content: center;>
    <img src="./images/node_logo.png"  width="150px" align="right" />
    <img src="./images/npm_logo.png"  width="150px" align="right" />
</div>

# LoggerTo

Este es un módulo genérico que permite disponer de logs de diferentes niveles dentro de la consola de desarrollo. 
Se utiliza principalmente el objeto `console` de javascript y se implementa como wrapper para los distintos 
niveles. Ademas de eso se puede implementar su trazabilidad haciendo uso del contexto de http con express.

| Nivel     |  identificador  | Detalle         |
|---------- |-----------------|-----------------|
|   LOG     |   1000    |   Human understand log for a developer.   |
|   DEBUG   |   1010    |   Designates fine-grained informational events that are most useful to debug an application.  |
|   INFO    |   1020    |   Designates informational messages that highlight the progress of the application at coarse-grained level.   |
|   WARN    |   1030    |   Designates potentially harmful situations.  |
|   ERROR   |   1040    |   Designates error events that might still allow the application to continue running. |
|   TRACE   |   1050    |   Designates finer-grained informational events than the DEBUG.     |

ref: https://www.tutorialspoint.com/log4j/log4j_logging_levels.htm


## Instalación

Para su integración dentro de cualquier desarrollo use npm para instalar.

```bash
console@user:~$ npm install loggerto --save
```

## Configuración

Para poder hacer uso de algunas funcionalidades presentes dentro de la librería puede configurarlo de la siguiente forma

Para cambiar el formato del log entre json o string, puede usar la variable de entorno `JSON_LOG`
```js
//Por default la librería genera log con formato string
export JSON_LOG= true
```
Para mostrar la versión de la api en la que está trabajando puede usar la variable `ACTIVE_VERSION`
```js
export ACTIVE_VERSION= true
```

Si quiere utilizar la trazabilidad del log, se puede usar la librería de express http context dentro del proyecto, de la siguiente forma

```js
//Ej. de un endpoint con usando el framework express agregando un parámetro dentro del header.
const traceId = (req.headers['x-correlation-id'])?req.get('x-correlation-id'):null;

//Si existe el 'x-correlation-id', se setea el valor dentro del contexto.
httpContext.set('traceId',traceId);
```

## Uso

```js
//Importar el modulo
const logger = require("loggerto");

//Primitivas
logger.log('ESTE ES UN LOG DE PRUEBA');
/*{"level":"LOG","code_level":1000,"time":"2021-10-04 19:56:20","message":"ESTE ES UN LOG DE PRUEBA",
"logger":"path: /test.js, on:test()"}*/

//Objetos
logger.debug({message: "Este es un debug de prueba"});
/*{"level":"DEBUG","code_level":1010,"time":"2021-10-04 19:56:20","message":"Este es un debug de prueba",
"logger":"path: /test.js, on:test()"}*/

logger.error({message:'mensaje de error', details: {
    type: "not-found",
    endpoint:"xy/xsxx/xxxx"
}});
/*{"level":"ERROR","code_level":1040,"time":"2021-10-04 19:56:20","message":"mensaje de error",
"details":{"type":"not-found","endpoint":"xy/xsxx/xxxx"},"logger":"path: /test.js, on:test()"}*/

//si se usa el flag JSON_LOG se veria el resultado del log en la consola de la siguiente forma:
{
  level: 'ERROR',
  code_level: 1040,
  time: '2021-10-04 20:13:43',
  message: 'mensaje de error',
  details: { type: 'not-found', endpoint: 'xy/xsxx/xxxx' },
  logger: 'path: /test.js, on:test()'
}
```

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