# @huz-com/logger

> Logger with environment based severity and separation of concerns

Latest version **1.0.14** (published 2021-11-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install @huz-com/logger
pnpm add @huz-com/logger
yarn add @huz-com/logger
bun add @huz-com/logger
```

## 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 | 1.0.14 |
| Published | 2021-11-29 |
| First published | 2021-02-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 25.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mustafa Yelmer |
| Maintainers | demiremrece, mustafayelmer, e.buyuk |
| Keywords | Logger, Log Driven Development, LDD |

## Links

- npm: https://www.npmjs.com/package/@huz-com/logger
- Repository: git@gitlab.azerdev.com:huz.byorbit/be/component/logger
- npm.io page: https://npm.io/package/@huz-com/logger

## Dependencies (2)

- [@huz-com/types](https://npm.io/package/@huz-com/types.md) ^1.0.3
- [@huz-com/config](https://npm.io/package/@huz-com/config.md) ^1.0.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

- 1.0.14 (latest) — 2021-11-29
- 1.0.13 — 2021-11-29
- 1.0.12 — 2021-09-15
- 1.0.11 — 2021-09-13
- 1.0.10 — 2021-09-13
- 1.0.9 — 2021-09-13
- 1.0.8 — 2021-09-10
- 1.0.7 — 2021-09-10
- 1.0.6 — 2021-09-09
- 1.0.5 — 2021-03-12
- 1.0.4 — 2021-02-22
- 1.0.3 — 2021-02-22
- 1.0.2 — 2021-02-22
- 1.0.1 — 2021-02-21

## README

# Huz.Com > Component > Logger

- Logger with environment based severity and separation of concerns

## Standards
- Language: `TS`
- Eslint: `Yes`
- Static Code Analysis: `Yes` *IntelliJ Code Inspections*
- DDD - Document Driven: `Yes`
- EDD - Exception Driven: `Yes`
- TDD - Test Driven: `Yes` [go to test folder](./test/Logger.spec.ts)
- Standards Complied: [Huz Standards](https://gitlab.azerdev.com/huz.byorbit/be/documentation/standards)

## Commands
- ``npm run clear`` *// clears "dist" folder*
- ``npm run lint`` *// runs eslint for static code analysis*
- ``npm run test`` *// runs test files in "test" folder*
- ``npm run build`` *// builds JS files at "dist" folder*
- ``npm publish`` *or* ``npm run publix`` *// publishes "dist" folder to npm*

## Install
``npm i @huz-com/logger``

## Structure
- logger.`severity`(...names: Array<string>).`concern`(data: unknown);

- severity:
    - `ifLocal`
    - `ifDevelopment`
    - `ifTesting`
    - `ifStaging`
    - `ifProduction`
    - `ifPriorityOk`
    - `ifEnvironmentOk`

- concern:
    - `error`
    - `endpoint`
    - `info`
    - `request`
    - `response`

## SEVERITY / PRIORITY
`````typescript
//environments: prod, stage, test, dev
//priorities: prod:0, stage: 1, test:2, dev: 3, isLocal:4

const {logger} = require('@huz-com/logger');

// --- EASY

// runs if registry.isLocal:true (not important environment)
logger.ifLocal('your description', 'sub-description');

// runs if registry.environment is dev
logger.ifDevelopment('your description', 'sub-description');

// runs if registry.environment istest or dev
logger.ifTesting('your description', 'sub-description');

// runs if registry.environment is stage or test or dev
logger.ifStaging('your description', 'sub-description');

// runs in all conditions
logger.ifProduction('your description', 'sub-description');

// --- DYNAMIC

// runs if given environment is fixed current environment
logger.ifEnvironmentOk('dev', 'your description', 'sub-description');

// runs if given priority is fixed current environment's priority
logger.ifPriorityOk(3, 'your description', 'sub-description');


`````

## SEPARATION OF CONCERNS
`````typescript
//error, endpoint, info, request, response

const {logger} = require('@huz-com/logger');

// --- error
// To log errors
try {
    // ...
} catch (e) {
    // it logs if registry.isLocal, else ignore it
    logger.ifLocal('your description', 'sub-description')
        .error(e);
}

// --- info
// to log any general data

// it logs if registry.environment is dev or test
logger.ifTesting('some log')
    .info('any data with any type');

// --- endpoint
// to log endpoint calls

// it logs if registry.environment is dev
logger.ifDevelopment('game get')
    .endpoint({
        method: 'GET', // optional, httpMethodEnum
        url: '/v1/games/4555', // string.Folder
        duration: 34 // optional, Integer
    });
    

// --- request
// to log remote api requesting (ie: before axios call)

// it logs if registry.environment is stage, test, dev
logger.ifStaging('call some api')
    .request({
        method: 'GET', // optional, httpMethodEnum
        url: 'https://domain.com/v1/some-path', // optional, url of api
        query: {key1: 'value1'}, // optional, query parameters
        headers: {key1: 'value1'}, // optional, outgoing headers
        payload: 'any content or json object', // optional, outgoing payload
        config: {}, // optional, other request configs
    }); 


// --- response
// to log remote api responsed successively (ie: after axios call)

// it logs if registry.environment is stage, test, dev, prod
logger.ifProduction('response of an api')
    .response({
        status: 200, // optional, incoming http status
        body: 'any content or json object', // optional, incoming body
        headers: {key1: 'value1'}, // optional, incoming headers
    }); 

`````

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