# @adobe/aio-lib-core-logging

> Logger framework for the Adobe I/O SDK

Latest version **3.0.2** (published 2024-11-14) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @adobe/aio-lib-core-logging
pnpm add @adobe/aio-lib-core-logging
yarn add @adobe/aio-lib-core-logging
bun add @adobe/aio-lib-core-logging
```

## Health

**Score 45/100 (D)** — status: stable.

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

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2024-11-14 |
| First published | 2019-09-24 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18 |
| Dependencies | 2 |
| Unpacked size | 33.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | mhaack, amol-anand, doten, stopp-adobe, dylandepass, djaeggi, adobehalls, fullcolorcoder, marbec, tripod, garthdb, lazd, adobe-admin, patrickfulton, trieloff, shazron, krisnye, dcpfsdk, natebaldwin, devongovett, aspro83, symanovi, dpfister, stefan-guggisberg, korra, rofe, kptdobe |

## Links

- npm: https://www.npmjs.com/package/@adobe/aio-lib-core-logging
- Repository: https://github.com/adobe/aio-lib-core-logging
- Homepage: https://github.com/adobe/aio-lib-core-logging#readme
- Issues: https://github.com/adobe/aio-lib-core-logging/issues
- npm.io page: https://npm.io/package/@adobe/aio-lib-core-logging

## Dependencies (2)

- [debug](https://npm.io/package/debug.md) ^4.1.1
- [winston](https://npm.io/package/winston.md) ^3.2.1

## Recent versions

- 3.0.2 (latest) — 2024-11-14
- 2.0.1-pre.2024-01-08.sha-cbe78b13 (next) — 2024-01-08
- 3.0.1 — 2024-02-12
- 3.0.0 — 2024-01-10
- 2.0.1-pre.2023-07-10.sha-71ccb2c4 — 2023-07-10
- 2.0.1 — 2023-07-06
- 2.0.0 — 2022-08-18
- 1.2.0-pre.2022-07-13.sha-311ded87 — 2022-07-13
- 1.2.0-pre.2022-06-06.af88b7eb — 2022-06-06
- 1.2.0 — 2021-01-11
- 1.1.2 — 2020-10-05
- 1.1.1 — 2020-08-17
- 1.1.0 — 2020-01-15
- 1.0.0 — 2019-10-30
- 0.0.4 — 2019-10-07
- … 3 more at https://npm.io/package/@adobe/aio-lib-core-logging/versions

## README

# aio-lib-core-logging

[![Version](https://img.shields.io/npm/v/@adobe/aio-lib-core-logging.svg)](https://npmjs.org/package/@adobe/aio-lib-core-logging)
[![Downloads/week](https://img.shields.io/npm/dw/@adobe/aio-lib-core-logging.svg)](https://npmjs.org/package/@adobe/aio-lib-core-logging)
![Node.js CI](https://github.com/adobe/aio-lib-core-logging/workflows/Node.js%20CI/badge.svg)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 
[![Codecov Coverage](https://img.shields.io/codecov/c/github/adobe/aio-lib-core-logging/master.svg?style=flat-square)](https://codecov.io/gh/adobe/aio-lib-core-logging/)

Node.js Logger module for use by the Adobe I/O SDK

## Install

`npm install @adobe/aio-lib-core-logging`

## Use

```javascript
let aioLogger = require('@adobe/aio-lib-core-logging')('App')
aioLogger.info('Hello logs')
```

### Output

Above code will log the following
> [App /mynamespace/myaction] info: Hello logs

Where _App_ would be the name of the application/module that is sending the logs.

### Configuration

The logger can be customized by passing a config object at the time of creation.

```javascript
let aioLogger = require('@adobe/aio-lib-core-logging')('App', config)
```

The config object can have one or more of the following keys.

- level (max severity logging level to be logged. can be one of error, warn, info, verbose, debug, silly)
- provider (logging provider. default is winston.)
- logSourceAction (boolean to control whether to include the action name in the log message)
- transports (array of custom winston transports)

The global log level can also be overridden using the env variable AIO_LOG_LEVEL or the env variable LOG_LEVEL.

### Enabling Debug Level Logging on command line
Avoid setting the global env variable by passing the log configuration in front of the aio command and stax flexibel.

To see all logs, do 
```bash
$ DEBUG=* aio app run
```

Once you have figured out what logs you are interrested in, use something more specific, like 
```bash
$ DEBUG=aio-telemetry:telemetry-lib* aio config
```

### Enabling Debug Level Logging programatically

Example of logger configuration:

```javascript
const logger = require('@adobe/aio-lib-core-logging')('MyModuleName', {provider: 'debug'})
logger.info('info')
logger.debug('debug')
```

To see both logs:

```javascript
AIO_LOG_LEVEL = debug
DEBUG = MyModuleName
```

It is possible to set the log level from another environment variable if needed:

```javascript
const logger = require('@adobe/aio-lib-core-logging')('MyModuleName', {provider: 'debug', level: process.env.FOOBAR})
logger.info('info')
logger.debug('debug')
```
### Using custom logger

```javascript
// Winston Logger
let aioLogger = require('@adobe/aio-lib-core-logging')('App', {provider:'winston'})
aioLogger.info('Hello logs')
```

or

```javascript
// Debug Logger
let aioLogger = require('@adobe/aio-lib-core-logging')('App', {provider:'debug'})
```

### Send logs to a file

```javascript
let aioLogger = require('@adobe/aio-lib-core-logging')('App', {transports: './logfile.txt' })
```

### Custom winston transports

```javascript
const winston = require('winston')
let aioLogger = require('@adobe/aio-lib-core-logging')('App', {transports: [new winston.transports.File({ filename: './winstoncustomfilelog.txt' })]})
```

### Creating custom logger
This is currently as simple as creating a new logger class under src with all the log level functions defined

## Explore

`goto` [API](./doc/api.md)

## Contributing

Contributions are welcomed! Read the [Contributing Guide](./.github/CONTRIBUTING.md) for more information.

## Licensing

This project is licensed under the Apache V2 License. See [LICENSE](LICENSE) for more information.

---
_Source: https://npm.io/package/@adobe/aio-lib-core-logging · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
