# logtopus

> Powerful logger for Node.js

Latest version **1.2.6** (published 2023-11-21) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.6 |
| Published | 2023-11-21 |
| First published | 2015-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 39 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Andi Heinkelein |
| Maintainers | andifeind, kippis, firetux |
| Keywords | log, logger, logtopus, logging, logs, filelogger, consolelogger, console, timer |

## Links

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

## Dependencies (7)

- [colorfy](https://npm.io/package/colorfy.md) ^2.2.0
- [gen-uid](https://npm.io/package/gen-uid.md) 0.0.2
- [superconf](https://npm.io/package/superconf.md) ^1.3.1
- [supertime](https://npm.io/package/supertime.md) ^1.0.0
- [superimport](https://npm.io/package/superimport.md) ^1.4.1
- [logtopus-file-logger](https://npm.io/package/logtopus-file-logger.md) ^1.0.2
- [logtopus-console-logger](https://npm.io/package/logtopus-console-logger.md) ^1.1.3

## 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.2.6 (latest) — 2023-11-21
- 1.2.5 — 2023-11-21
- 1.2.4 — 2023-11-21
- 1.2.3 — 2023-11-20
- 1.2.2 — 2023-10-06
- 1.2.1 — 2023-10-06
- 1.2.0 — 2022-10-28
- 1.1.5 — 2022-04-01
- 1.1.4 — 2020-10-19
- 1.1.3 — 2019-06-25
- 1.0.2 — 2018-01-25
- 1.0.1 — 2017-10-31
- 1.0.0 — 2017-10-27
- 0.3.0 — 2016-07-24
- 0.2.1 — 2016-05-26
- … 4 more at https://npm.io/package/logtopus/versions

## README

Logtopus
========

[![Build Status](https://travis-ci.org/Andifeind/logtopus-console-logger.svg?branch=develop)](https://travis-ci.org/Andifeind/logtopus)

Logtopus is a powerful logger for Node.js with different transports

![Logtopus Logger](https://static.noname-media.com/logtopus/logtopus.gif)

Built in logger:
* Console logger using [logtopus-console-logger](https://npmjs.org/packages/logtopus-console-logger)
* File logger using [logtopus-file-logger](https://npmjs.org/packages/logtopus-file-logger)

Additional logger:
* Redis logger see [logtopus-redis-logger](https://npmjs.org/packages/logtopus-redis-logger)
* InfluxDB logger use [logtopus-influx-logger](https://npmjs.org/packages/logtopus-influx-logger)
* MongoDB logger use [logtopus-mongo-logger](https://npmjs.org/packages/logtopus-mongo-logger)

## Usage

```js
const log = require('logtopus').getLogger('mylogger');
log.setLevel('sys');

log.warn('My beer is nearly finish!');
```

### Log levels

    debug    development  Logs debugging informations
    info     development  Helpful during development
    res      staging      Logs requests
    req      staging      Logs responses
    sys      production   Logs application states
    warn     production   Logs warnings
    error    production   Logs errors

For example, setting log level to `req` includes these log levels: `req`, `sys`, `warn`, `error`
Setting log level to `debug` means all log levels are activated
log level `error` logs errors only.

Example:

```js
log.setLevel('res');        // To be ignored in this log level
log.debug('Log example:');  // To be ignored in this log level
log.info('This would not be logged');
log.res('POST /account');
log.req('200 OK');
log.sys('Request done!');
log.warn('Request was unauthorized!');
log.error('An error has been occurred!');

// prints

res: POST /account
req: 200 OK
sys: Request done!
warn: Request was unauthorized!
error: An error has been occurred!
```

### Express logger

Logtopus comes with a logger for Express/Connect.

`logtopus.express()` returns a middleware for Express/Connect. It acepts an optional options object

```js
let express = require('express');
let logtopus = require('../logtopus');

let app = express();

app.use(logtopus.express({
  logLevel: 'debug'
}));
```

#### Options

`logLevel` Sets current log level


### Koa logger

Logtopus also supports Koa

`logtopus.koa()` returns a middleware for Koa. It acepts an optional options object

```js
let koa = require('koa');
let logtopus = require('../logtopus');

let app = koa();

app.use(logtopus.koa({
  logLevel: 'debug'
}));
```

#### Options

`logLevel` Sets current log level

### Adding custom loggers

Logtopus was designed as an extensible logger. You can add a custom logger by creating a logger class and load it into logtopus. The example below shows a minimal logger class.

```js
class LogtopusLogger {
  constructor(conf) {
    // conf contains the logger conf
  }

  log(logmsg) {
    const date = logmsg.time.toISOString()
    console.log(`[${date}] ${logmsg.msg}`)
  }
}

module.exports = LogtopusLogger
```

The logger class requires a log method. It takes one argument which contains a log object. The first argument of a log call is the log message, all other arguments are log data.

```js
logmsg: {
  type: 'info', // The logtype eg: debug, info, error, sys
  msg: 'Log message string', // Log message, but without CLI color codes
  cmsg: 'Colorized log message', // Log message with CLI color codes
  time: new Date(), // Current date
  uptime: process.uptime(), // Process uptime in ms
  data: [] // All other arguments as an array
}
```

Now, the class has to be load into logtopus. You can do it by using the .addLogger() method if your logger is a priveate logger. Otherwis publish it on npm by using our logger name conventions. `logtopus-${loggername}-logger`
Add a new config block into the logtopus config by using `loggername` as namespace and logtopus tries to load the logger.

```js
const log = logtopus.getLogger('mylogger')
log.addLogger('loggerName', loggerClass)
```

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