# console_extension

> A lib to change default default of the console object, in order to do extended logs.

Latest version **1.0.1** (published 2017-09-04) · 0 weekly downloads

## Install

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

## 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.0.1 |
| Published | 2017-09-04 |
| First published | 2017-08-22 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.3.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | szanata |
| Keywords | log, console, metric |

## Links

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

## Dependencies (1)

- [stack-trace](https://npm.io/package/stack-trace.md) 0.0.10

## 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.0.1 (latest) — 2017-09-04
- 1.0.0 — 2017-09-01
- 0.4.0 — 2017-08-30
- 0.3.2 — 2017-08-28
- 0.3.1 — 2017-08-28
- 0.3.0 — 2017-08-25
- 0.2.0 — 2017-08-25
- 0.1.0 — 2017-08-22

## README

Adding some features over console methods to log objects.

## To log INFO|WARN|DEBUG|ERROR objects use:



### Logging some message:

Use common log methods to log different levels of information.

```js
console.info( 'Foo' );
//or
console.info( { message: 'Foo' } );
```

Output will be this a stringified object like this:
```js
{
  "message": "Foo",
  "system": "Your system name",
  "service": "your service name",
  "hostname": "Machine name",
  "type": "log",
  "level": "INFO",
  "timestamp": "2017-09-01T02:34:53.134Z"
}
```
## Using different log levels

The `level` prop varies according to the method called:

```js
console.info(); // level: INFO
console.warn(); // level: WARN
console.debug(); // level: DEBUG
console.error(); // level: ERROR
```

### Logging properties:

You can add any props to the output object, simple logging a object with those

```js
console.info( { message: 'Foo', custom_field: 'customize', another_field: 'more_values' } );
```

Outputs:
```js
{
  "message": "Foo",
  "custom_field": "customize",
  "another_field": "more_values",
  "system": "Your system name",
  "service": "your service name",
  "hostname": "Machine name",
  "type": "log",
  "level": "INFO",
  "timestamp": "2017-09-01T02:34:53.134Z"
}
```
*Note that you cannot overwrite the default props*

## To log metrics

Use V8 native method table to log a metric object.

```js
console.table( { custom_field: 'bar', another_field: 'bar' } );
```

Is almost the same object:

```js
{
  "custom_field": "bar",
  "another_field": "bar",
  "system": "Your system name",
  "service": "your service name",
  "hostname": "Machine name",
  "type": "metric",
  "timestamp": "2017-09-01T02:34:53.134Z"
}
```
*Note that you do not have a level anymore, nor a message*

## Automatic fields:

These are the fields added by default by the lib (an their values):

- **system**: Read from `process.env.SYSTEM_NAME`
- **service**: Read from `process.env.SERVICE_NAME`
- **hostname**: Read from `require('os').hostname()`
- **type**: Automatic set for 'log' or 'metric'
- **level**: *Log only*. Set after the method called
- **timestamp**: Current date in ISO-8601 format

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