# ms-iso-logger

> Isomorphic logger

Latest version **0.1.3** (published 2021-02-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install ms-iso-logger
pnpm add ms-iso-logger
yarn add ms-iso-logger
bun add ms-iso-logger
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2021-02-27 |
| First published | 2019-04-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 6.* \|\| 8.* \|\| >= 10.* |
| Dependencies | 1 |
| Unpacked size | 26.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Manuel Spoerer |
| Maintainers | manuel.spoerer |
| Keywords | logger |

## Links

- npm: https://www.npmjs.com/package/ms-iso-logger
- Repository: git@gitlab.com:mspoerer/ms-iso-logger
- npm.io page: https://npm.io/package/ms-iso-logger

## Dependencies (1)

- [winston](https://npm.io/package/winston.md) ^3.3.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

- 0.1.3 (latest) — 2021-02-27
- 0.1.2 — 2021-02-27
- 0.1.1 — 2021-02-27
- 0.1.0 — 2021-02-25
- 0.0.4 — 2021-02-22
- 0.0.3 — 2021-02-22
- 0.0.2 — 2019-07-02
- 0.0.1 — 2019-04-23

## README

ms-iso-logger
==============

Isomorphic logger that works in client and server scope.

## Install

    yarn add ms-iso-logger

## How it works
This package utilizes a webpack feature which looks at the `browser` field in `package.json` and uses that when bundling. When running on server side, node.js `require` looks at the `main` field, which points to another file. That way the interface looks the same but uses two different pieces of code behind the scenes. Check [`index-server.js`](./index-server.js) and [`index-client.js`](./index-client.js) for details.

## Usage
To access the `Logger`, simply import it from `ms-iso-logger` and use it.

```js
import { createLogger } from 'ms-iso-logger';

// create Logger and set context of logging instance (defaults to empty string)
const logger = createLogger('MyContext');

// log at different levels
logger.log('This is a message with level=INFO');
logger.debug('This is a message with level=DEBUG');

// change context of logging instance
logger.setContext('MyOtherComponent');

// log message with additional fields
logger.log({ message: 'This is a message', moreData: 'additional info' });

```

## API
The module returns a single factory method that can be called to create a new `Logger` instance for the current environment. The Logger offers a set of public methods. NOTE: Due to the isomorphic nature the code behind the scenes still uses CJS instead of ES6 modules, so it is not possible to use named imports to e.g. import the Logger directly.

### createLogger([contextId:string]):Logger
Factory method that creates a new `Logger` instance.

### Logger.setContext(contextId:string)
Set logging context for this single Logger instance using the `contextId` parameter. This is added to the log output and should be used to identify the log origin. The `reporter` argument my be used to set a different reporter. This defaults to

### Logger.info(message:any)
Log a message with level `INFO`. Message can be any primitive value or an object with additional fields which get passed as payload.

### Logger.log(message:any)
Alias for `Logger.info` to comply with `window.console` naming.

### Logger.debug(message:any)
Log a message with level `DEBUG`.

### Logger.warn(message:any)
Log a message with level `WARN`.

### Logger.error(message:any)
Log a message with level `ERROR`.

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