# ut-log

> UT log module

Latest version **6.11.3** (published 2023-06-22) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install ut-log
pnpm add ut-log
yarn add ut-log
bun add ut-log
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 6.11.3 |
| Published | 2023-06-22 |
| First published | 2016-08-12 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 86.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | kalin.krustev |

## Links

- npm: https://www.npmjs.com/package/ut-log
- Repository: https://github.com/softwaregroup-bg/ut-log
- Homepage: https://github.com/softwaregroup-bg/ut-log#readme
- Issues: https://github.com/softwaregroup-bg/ut-log/issues
- npm.io page: https://npm.io/package/ut-log

## Dependencies (9)

- [uuid](https://npm.io/package/uuid.md) 8.3.2
- [bunyan](https://npm.io/package/bunyan.md) 1.8.12
- [@sentry/node](https://npm.io/package/@sentry/node.md) 5.24.2
- [fluent-logger](https://npm.io/package/fluent-logger.md) 3.4.1
- [readable-stream](https://npm.io/package/readable-stream.md) 2.3.3
- [lodash.defaultsdeep](https://npm.io/package/lodash.defaultsdeep.md) 4.6.1
- [stream-file-archive](https://npm.io/package/stream-file-archive.md) 1.1.4
- [lodash.clonedeepwith](https://npm.io/package/lodash.clonedeepwith.md) 4.5.0
- [ut-function.console-table](https://npm.io/package/ut-function.console-table.md) ^1.1.1

## Recent versions

- 6.11.3 (latest) — 2023-06-22
- 6.4.0-rc-godfather.7 (rc-godfather) — 2018-12-21
- 6.2.3 (rc-6.2.0-1) — 2018-07-12
- 6.3.0-rc-einstein.2 (rc-einstein) — 2018-07-09
- 6.2.0-rc-cubalibre.0 (rc-cubalibre) — 2018-06-11
- 6.1.0-rc-bahur.6 (rc-bahur) — 2018-02-19
- 5.11.1 (updateLeveldown) — 2018-02-02
- 6.0.0-ut6.11 (ut6) — 2017-12-06
- 5.12.0-rc-acapulco.1 (rc-acapulco) — 2017-11-22
- 5.12.0-rc-acapulco.0 (ci) — 2017-10-31
- 6.11.2 — 2023-02-22
- 6.11.1 — 2023-02-21
- 6.11.0 — 2023-02-21
- 6.10.5 — 2022-11-28
- 6.10.4 — 2022-05-12
- … 100 more at https://npm.io/package/ut-log/versions

## README

# ut-log

'ut-log' is a module aimed to provide logging functionality for the UT5 implementations.
A basic log instance can be obtained with the following code:

```js
var utLog = require('ut-log');
var utLogConfig = {
    type: 'bunyan',
    streams: [
        {
            level: 'trace',
            stream: 'process.stdout'
        }
    ]
};
var logFactory = new utLog(utLogConfig);
var log = logFactory.createLog('info', {name: 'a', context: 'b'});
```

- **ut-log** module exposes a constructor for creating logFactory objects

- The configuration object that the **ut-log** constructor accepts as an
  argument has to have properties **type** and **streams** (for bunyan) or
  **transports** (for winston) where:
  - **type** is a string specifying which vendor node module will be used for
  logging. The possible values are:
  [bunyan](https://github.com/trentm/node-bunyan) or
  [winston](https://github.com/winstonjs/winston)
  - **streams** (for bunyan) is an array of objects where each object specifies
  a single logging stream or **transports** (for winston) is an object of transports.
  For more information visit
  [bunyan streams](https://github.com/trentm/node-bunyan#streams) and
  [winston transports](https://github.com/winstonjs/winston#working-with-transports)

- The logFactory object has a single method (**createLog**) which has to be
  called in order for a log instance to get obtained. logFactory.createLog
  method has 2 arguments: **level** and **params**
  - **level** is a string specifying the minimum logging level the logger will
  be able to log to.  The possible values for this argument are:
  `trace`, `debug`, `info`, `warn`, `error`, `fatal`.

  Each log level has a weight and the priority of the levels is as listed above.

Once having the **log** instantiated it can be used to log data across all
specified streams simultaneously (in this case only the NodeJS console through
*process.stdout*). Logging itself happens by calling one of the log's methods
(logFactory.createLog returns an object with each logging level assigned
as a method). In our case, because we set 'info' as a minimum logging level,
the 'log' object will be equipped with 4 methods:

- log.info
- log.warn
- log.error
- log.fatal

To log something, pass the data that needs to be log as an argument to some of
the functions listed above. E.g:

```js
log.info('log message');
```

Doing so will log the data to all specified streams with a minimum level equal
to 'info' or higher. For optimal performance all log method calls should always
be verified before being called so that changing the global logFactory object's
minimum log level should not break the code and high volume log data will not
occupy memory. I.e. logging should always happen like:

```js
log.info && log.info('log message');
```

Multiple streams example:

```js
var utLog = require('ut-log');
var level = require('level');
var path = require('path');
// stream constructors
var SocketStream = require('ut-log/socketStream');
var LevelDBStream = require('ut-log/leveldbStream');
var SentryStream = require('ut-log/sentryStream');
var LogRotateStream = require('ut-log/logRotateStream');

var utLogConfig = {
    type: 'bunyan',
    transformData: {
        // which field should be (hidden/overwritten with *) value from log
        id: 'hide'
    },
    streams: [
        {
            level: 'trace',
            stream: 'process.stdout'
        },
        {
            level: 'trace',
            stream: new SocketStream({
                host: '127.0.0.1',
                port: '30001',
                objectMode: true
            }),
            type: 'raw'
        },
        {
            level: 'trace',
            stream: new LevelDBStream({
                dbPath: './leveldbLogs'
            }),
            type: 'raw'
        },
        {
            level: 'error',
            stream: new SentryStream({
                dsn : 'http://b62b47864e93466cbb16a2b4a1d749b1:05968d770cdf4f8f8f09985d95ea9911@sentry.softwaregroup.com:49161/2',
                patchGlobal: true,
                logger: 'impl-test'
            }),
            type: 'raw'
        },
        {
            level: 'trace',
            stream: new LogRotateStream({
                path : path.join('logs', 'ut5_%Y-%m-%d.log'),
                symlink: path.join('logs', 'ut5.log'),
                compress: true
            })
        }
    ]
};
var logFactory = new utLog(utLogConfig);
var log = logFactory.createLog('info', {name: 'a', context: 'b'});
```

## LogRotateStream options

### path

A string file path with any of the below options to define rotation schedule:

e.g. `./logs/ut5-%Y-%m-%d.log` would result in logs like `./logs/ut5-2015-07-06.log`

- %Y 4-digit year e.g. 2013
- %m month (01..12)
- %d day of month (01..31)
- %x iso8601 date portion (e.g. 2012-09-24)
- %h hour (00..23)
- %M minute (00..59)
- %S second (00..61)
- %X iso8601 time portion to the second (e.g.: 15:12:47)
- %I iso8601 date/time to the second (e.g. 2012-09-24T15:12:47)

## symlink

A path to a symlink that will be maintained to point at the current log file.

## compress

Boolean value, whether to gzip the files once they aren't being written to.

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