# tvc.logger

> Logging utility for the MEAN stack, logs out to console, file or MongoDB using mongoose.

Latest version **1.2.1** (published 2015-07-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install tvc.logger
pnpm add tvc.logger
yarn add tvc.logger
bun add tvc.logger
```

## 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.2.1 |
| Published | 2015-07-24 |
| First published | 2015-06-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Bill Brady |
| Maintainers | thevikingcoder |
| Keywords | MEAN, MongoDB, Mongoose, NodeJS, Log, Logger, Logging |

## Links

- npm: https://www.npmjs.com/package/tvc.logger
- Repository: https://github.com/thevikingcoder/tvc.logger
- Homepage: https://github.com/thevikingcoder/tvc.logger#readme
- Issues: https://github.com/thevikingcoder/tvc.logger/issues
- npm.io page: https://npm.io/package/tvc.logger

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ^3.10.0
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [moment](https://npm.io/package/moment.md) ^2.10.3
- [jsonfile](https://npm.io/package/jsonfile.md) ^2.2.1

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.2.1 (latest) — 2015-07-24
- 1.2.0 — 2015-07-23
- 1.1.2 — 2015-07-23
- 1.1.1 — 2015-07-23
- 1.1.0 — 2015-07-19
- 1.0.5 — 2015-06-30
- 1.0.4 — 2015-06-30
- 1.0.3 — 2015-06-30
- 1.0.2 — 2015-06-30
- 1.0.1 — 2015-06-30
- 1.0.0 — 2015-06-30

## README

# tvc.logger
Logging utility for the MEAN stack, logs out to console, file or MongoDB using mongoose.

## What is this repository for? ##
* Logging of any event through simple methods
* Current Version : 1.2.0

## Installation ##
```
$ npm install tvc.logger
```

## Usage ##

```js
// Require the module
var log = require("tvc.logger");
```

**Update v1.2.0**

Added OOP method

```js
var logger = require("tvc.logger/oop");
var log = new logger();
var log2 = new logger();

// Gets independent configuration options
log.config({"tsFormat": "HH:mm:ss.SSS"});
log2.config({"tsFormat": "MM-DD HH:mm:ss"});
```

## Logging Methods ##
```js

/**
 * Standard log message
 * @param _message {string|object} - Log message (will stringify objects)
 * @param _function {string=} - Function name (can be used for passing any string for logging purposes)
 * @param _console {boolean=} [_console=true] - Output to console
 * @param _status {number=} - HTTP status code
 */
log.info(_message, _function, _console, _status);

/**
 * Custom log message
 * @param _type {string} - Type of log entry
 * @param _message {string|object} - Log message (will stringify objects)
 * @param _function {string=} - Function name (can be used for passing any string for logging purposes)
 * @param _console {boolean=} [_console=true] - Output to console
 * @param _status {number=} - HTTP status code
 */
log.custom(_type, _message, _function, _console, _status);
```

### File Logging ###
File logging will attempt to create a directory to contain log files and will name files using MomentJS notation.

```js
// Basic
log.config({"toFile": true});
// CSV
log.config({"toFile": true, "logFormat": "csv"});
// TSV
log.config({"toFile": true, "logFormat": "csv", "extension": "tsv", "logSeparator": "\t"});
// JSON
log.config({"toFile": true, "logFormat": "json"});
```

### DB Logging ###
```js
// Default model name of 'tvc.logs.prime'
log.config({"toMongo": true});
// Change the model name to anything you'd like
log.config({"toMongo": true, "logModel": "my.log"});
```

## Configuration ##
### General & Console ###
| Parameter | Data Type | Default | Description | Valid Parameters |
| :-------- | :-------- | :------ | :---------- | :--------------- |
| console | boolean | true | Output log entries to console | true : false |
| logSeparator | string | " - " | Parameter separator for file / console logging | :any |
| padding | number | 8 | Used to make log types even for readability | :any |
| tsFormat | string | timestamp | MomentJS timestamp  | :any |

### File Logging ###
| Parameter | Data Type | Default | Description | Valid Parameters |
| :-------- | :-------- | :------ | :---------- | :--------------- |
| toFile | boolean | false | To write log entries to a file | true : false |
| extension | string | "txt" | File extension to use when creating file | :any |
| logFormat | string | "text" | Logfile format | text : json : csv |
| logSeparator | string | "," | logFormat "csv" and not specifiying a character | :any |
| tsFormat | string | timestamp | When using logFormat "csv" | :any |
| customPath | string | "logs" | Define custom log path relative to application path | :any |
| filenameFormat | string | "YYYY-MM-DD" | MomentJS full date | :any |

### Database Logging ###
To use database logging, an active mongoose connection must be established

| Parameter | Data Type | Default | Description | Valid Parameters |
| :-------- | :-------- | :------ | :---------- | :--------------- |
| toMongo | boolean | false | To write log entries to database | true : false |
| logModel | string | "tvc.logs.prime" | Collection name | :any |

## Examples ##
```js
log.debug('Debug message');
// 2015-07-19 15:07:14.569 - DEBUG    - Debug Message
log.info("Info message");
// 2015-07-19 15:07:14.567 - INFO     - Info Message
log.warning('Warning message');
// 2015-07-19 15:07:14.570 - WARNING  - Warning message
log.error('Error message');
// 2015-07-19 15:07:14.570 - ERROR    - Error message
log.critical('Critical message');
// 2015-07-19 15:07:14.570 - CRITICAL - Critical message
log.fatal('Fatal message');
// 2015-07-19 15:07:14.571 - FATAL    - Fatal message
log.custom('custom', 'Custom message');
// 2015-07-19 15:07:14.571 - CUSTOM   - Custom message
```

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