Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/atlassubbed/atlas-basic-logger


https://github.com/atlassubbed/atlas-basic-logger

Last synced: 21 days ago
JSON representation

Awesome Lists containing this project

README

        

# atlas-basic-logger

A very simple debug logger.

[![Travis](https://img.shields.io/travis/atlassubbed/atlas-basic-logger.svg)](https://travis-ci.org/atlassubbed/atlas-basic-logger)

---

## install

```
npm install --save atlas-basic-logger
```

## why

I just need a simple error-first `Logger` which lets me avoid using `console.log` (for testability), while making my business logic cleaner and more concise.

## examples

Both debug and concise mode can be used to do error-first logging. If an error is passed to the logger, it'll print it (or just the `message` in concise mode), otherwise it'll attempt to print the second argument.

#### debug mode

This will print the error to stderr, if it exists, otherwise it will print the full result to stdout, if it exists.

```javascript
const Logger = require("atlas-basic-logger");
const isDebug = true;
const log = Logger(isDebug)
reddit.deleteAccount("atlassubbed", (err, res) => {
log(err, res)
})
// or, in fewer lines
reddit.deleteAccount("atlassubbed", log)
```

#### concise mode

This will print the error's `message` to stderr, if it exists, otherwise it will print the full result to stdout, if it exists.

```javascript
const log = require("atlas-basic-logger")();
reddit.deleteAccount("atlassubbed", (err, res) => {
log(err, res)
})
// or, in fewer lines
reddit.deleteAccount("atlassubbed", log)
```