# @hacker-und-koch/eventbus

> * [Creating a Logger](#creating-a-logger) * [Log Levels](#log-levels) * [Line Formatting](#line-formatting) * [`LoggerBuilder`](#loggerbuilder)

Latest version **0.2.1** (published 2021-07-14) · LGPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install @hacker-und-koch/eventbus
pnpm add @hacker-und-koch/eventbus
yarn add @hacker-und-koch/eventbus
bun add @hacker-und-koch/eventbus
```

## Health

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

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

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2021-07-14 |
| First published | 2020-04-29 |
| Weekly downloads | 0 |
| License | LGPL-3.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 12.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | hacker-und-koch |

## Links

- npm: https://www.npmjs.com/package/@hacker-und-koch/eventbus
- Repository: https://github.com/hacker-und-koch/ts-node-additions
- Homepage: https://github.com/hacker-und-koch/ts-node-additions#readme
- Issues: https://github.com/hacker-und-koch/ts-node-additions/issues
- npm.io page: https://npm.io/package/@hacker-und-koch/eventbus

## Dependencies (3)

- [rxjs](https://npm.io/package/rxjs.md) ^6.5.5
- [@hacker-und-koch/di](https://npm.io/package/@hacker-und-koch/di.md) 0.2.1
- [@hacker-und-koch/logger](https://npm.io/package/@hacker-und-koch/logger.md) 0.2.1

## Recent versions

- 0.2.1 (latest) — 2021-07-14
- 0.2.0 — 2021-07-14
- 0.1.14 — 2021-07-14
- 0.1.13 — 2021-07-14
- 0.1.8 — 2021-07-13
- 0.0.7 — 2020-05-31
- 0.0.6 — 2020-05-21
- 0.0.5 — 2020-04-29

## README

# @hacker-und-koch/logger
## Table Of Content
* [Creating a Logger](#creating-a-logger)
* [Log Levels](#log-levels)
* [Line Formatting](#line-formatting)
* [`LoggerBuilder`](#loggerbuilder)

## Creating a Logger
### Builder pattern
```typescript
const loggerBuilder: LoggerBuilder = Logger.build();

loggerBuilder.className('MyClass');  // manditory!

const logger: Logger = loggerBuilder.create();

logger.log('lorem ipsum');
```
### Via Dependency Injection
```typescript
import { Injectable } from '@hacker-und-koch/di';
import { Logger } from '@hacker-und-koch/logger';

@Injectable()
class MyClass {
    constructor(private logger: Logger) {
        this.logger.log('lorem ipsum');
    }
}
```
## Log Levels
### Order Of Significance
Highest to lowest:
* error
* warning
* log
* info
* spam

### Calling logger by level
```typescript
logger.spam('lorem');
logger.info('ipsum');
logger.log('dolor');
logger.warn('sit');
logger.error('amet');
```


## Line Formatting
### Default formatting ([example](./src/examples/basic-logger.ts))
Above examples will print
```log
2020-01-02T03:04:50.001Z  -  MyClass: lorem
2020-01-02T03:04:50.002Z (i) MyClass: ipsum
2020-01-02T03:04:50.003Z     MyClass: dolor
2020-01-02T03:04:50.004Z [x] MyClass: sit
2020-01-02T03:04:50.005Z !!! MyClass: amet
```
### Overwriting FormatFunction
```typescript
const formatFunction: FormatFunction = (pkg: LoggerPackage): Buffer | string => {
    const argsAsString = pkg.parts
        .map(arg => arg.toString())
        .join('+++');
    return `[${pkg.class}] ${argsAsString}\n`;
}

const logger: Logger = Logger.build()
    .className('MyClass')
    .format(formatFunction)
    .create();

logger.log('lorem', 'ipsum');
```
prints
```log
[MyClass] lorem+++ipsum
```

## `LoggerBuilder`
### 

### `className(className: string): this`
Set class name to be used when formatting log output.
(( manditory! ))


@param {`string`:} className    Class name used when formatting log output.

### `create(): Logger`
Calling this function will finish the building process.
A new instance of `Logger` will be created and configured
according to the `LoggerBuilder`'s state.

### `id(id: string): this`
Set ID of instance. Is utilized by di package.


@param `id`:    ID of instance to be used when
             formatting log output.


### `level(level: Loglevel): this`
Set threshold level for Logger. Only logs with level of
 equal or greater importance to this value will be printed.


@param `level`:     Threshold level for Logger

### `format(format: FormatFunction): this`
Set Logger's `FormatFunction`.


@param `format`:    Mapping function to format log lines

### `stdout(stream: NodeJS.WriteStream): this`
`WriteStream` used for levels `'spam'`, `'info'` and `'log'`.


@param `stream`:    stdout stream

### `stderr(stream: NodeJS.WriteStream): this`
`WriteStream` used for levels `'warning'` and `'error'`.


@param `stream`:    stdout stream

### `noTimestamp(): this`
If called: Logger's formating function will not include a timestamp

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