# erlog

> A simple logging middleware for node.js

Latest version **0.1.7** (published 2013-10-28) · MIT license · 0 weekly downloads

## Install

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

## 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.7 |
| Published | 2013-10-28 |
| First published | 2013-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Author | Michael Keating |
| Maintainers | humanoidanalog |
| Keywords | logging, erlog |

## Links

- npm: https://www.npmjs.com/package/erlog
- Repository: https://github.com/humanoidanalog/erlog.js
- Issues: https://github.com/humanoidanalog/erlog.js/issues
- npm.io page: https://npm.io/package/erlog

## Dependencies (1)

- [moment](https://npm.io/package/moment.md) 2.2.x

## 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
- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K 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

## Recent versions

- 0.1.7 (latest) — 2013-10-28
- 0.1.5 — 2013-10-28
- 0.1.4 — 2013-10-28
- 0.1.3 — 2013-10-28
- 0.1.2 — 2013-10-27
- 0.1.1 — 2013-10-27
- 0.1.0 — 2013-10-27

## README

# Erlog - Reporting in for duty!

A simple logging middleware for [node.js](http://nodejs.org), just install with npm and require where you need it

    $ npm install erlog
```js 
var erlog = require('erlog')
```

## Functions

Erlog has a few simple functions that make logging and troubleshooting a little easier:

### Simple log message

```js
erlog(message)
```

Call this function with any string as an argument and it'll format it with the current date and time.

##### Example

```js
erlog("Hello World")
```

    >> Sun, October 27th 2013, 4:38:44 pm: Hello World

### Inspect object

```js
erlog.inspect(object, options)
```

This will log the contents of any object you pass to it, as well as its children. The options argument is optional, and may include the following options

```js
// give erlog an identifier to tie to the object
options.title = "Descriptor String"

// will log non-enumerable properties if true, defaults to false
options.showHidden = true

// number of times to recurse into object, defaults to null 
// when null erlog will log the entire object's tree
options.depth = 3 

 // if true, erlog will format object with color, defaults to true
options.colors = false
```

##### Example

```js
var myObject = {
    param1: 123904939
  , func: function() {
      return this.param1
    }
  , foo: "bar"
  , child: {
        fizz: 0
      , buzz: 1
      , fizzbuzz: [
            { name: "jen" }
          , { name: "bob" }
        ]
    }
}

erlog.inspect(myObject, { 
    title: "El Fred"
  , showHidden: false
  , depth: 1
  , colors: true 
})
```

    >> Sun, October 27th 2013, 4:38:44pm: Inspection of El Fred
    >> { param1: 123904939,
    >>   func:
    >>    { [Function]
    >>      [length]: 0,
    >>      [name]: '',
    >>      [arguments]: null,
    >>      [caller]: null,
    >>      [prototype]: [Object] },
    >>   foo: 'bar',
    >>   child:
    >>    { fizz: 0,
    >>      buzz: 1,
    >>      fizzbuzz: [Object] } }

Or, to keep things tidy and simple:

```js
erlog.inspect(myObject)
```

    >> Sun, October 27th 2013, 4:38:44pm: Inspection of Object
    >> { param1: 123904939,
    >>   func:
    >>    { [Function]
    >>      [length]: 0,
    >>      [name]: '',
    >>      [arguments]: null,
    >>      [caller]: null,
    >>      [prototype]: { [constructor]: [Circular] } },
    >>   foo: 'bar',
    >>   child:
    >>    { fizz: 0,
    >>      buzz: 1,
    >>      fizzbuzz: 
    >>       [ { name: 'jen' },
    >>         { name: 'bob' },
    >>         [length]: 2 ] } }

### Error Logging

```js
erlog.error(error, options)
```

This was developed with callback errors in mind, which are a common practice in node.js applications. It conveniently returns 0 if there was no error encountered, and returns a nonzero value if errors were passed. The options object accepts the following properties, but is optional:

```js
options.message = "When I was trying to do thing" // a context to give the log entry
options.success = "I was able to do thing" // a message to log if no error was encountered
```

##### Example

For example, when searching through a database with mongoose:

```js
User.find(id, function(err, user) {
  if (erlog.error(err, { message: "I was looking through the users", success: "and there weren't any problems" })) {
    // there was an error
    next(err) 
  } else {
    // good to go! And erlog logs the success message, if there is one!
    req.user = user;
  }
}) 
```

    >> Sun, October 27th 2013, 4:38:44pm: I was looking through the users
    >> Sun, October 27th 2013, 4:38:44pm:: and there weren't any problems

And if you like things a tad more tidy

```js
User.find(id, function(err, user) {
  if (erlog.error(err)) {
    //there was an error
    next(err)
  } else {
    // good to go! nothing is logged by erlog, this time.
    req.user = user;
  } 
})
```

    >> Sun, October 27th 2013, 4:38:44pm: Upon checking for an error
    >> Sun, October 27th 2013, 4:38:44pm:: Successful

## Planned features

- allow for substitution along the lines of erlog('this: %a and that %b', a, b)
- module.export options to change the formatting style of output

## License

### [The MIT License (MIT)](http://opensource.org/licenses/MIT)

*Copyright* © 2013 Michael Keating

    Permission is hereby granted, free of charge, to any person obtaining a copy of
    this software and associated documentation files (the "Software"), to deal in
    the Software without restriction, including without limitation the rights to
    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
    the Software, and to permit persons to whom the Software is furnished to do so,
    subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
    FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
    COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
    IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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