# The best alternative to the console.log statement

[![Beautiful Logger for Node.js: the best alternative to the console.log statement](https://raw.githubusercontent.com/ptkdev/ptkdev-logger/nightly/.github/assets/ptkdev-logger-logo.png)](https://www.npmjs.com/package/@ptkdev/logger)

# 🦒 Beautiful Logger for Node.js
> The best alternative to the console.log statement

I love using `console.log` but it is difficult to record all the log information. I have implemented a small colored variant with tags, colors, messages of various errors and write to file logs in .json / txt format.

Resources: [[NPM](https://www.npmjs.com/package/@ptkdev/logger)] [[GITHUB](https://github.com/ptkdev/ptkdev-logger)]

## 💡 Features
* [✔️] Easy to use
* [✔️] MIT License
* [✔️] The best alternative to the console.log statement
* [✔️] Write stdout logs to file (supported format: text/log and json)
* [✔️] The JSON logs format is compatible with [pinojs](https://github.com/pinojs/pino)
* [✔️] Translations: 🇬🇧 🇮🇹 🇵🇱 (Help me ❤️)

## 👔 Screenshot
[![Beautiful Logger for Node.js](https://raw.githubusercontent.com/ptkdev/ptkdev-logger/nightly/.github/assets/screenshot/ptkdev-logger-screen1.png)](https://raw.githubusercontent.com/ptkdev/ptkdev-logger/nightly/.github/assets/screenshot/ptkdev-logger-screen1.png)

## 🚀 Installation
1. In your node project run: `npm install @ptkdev/logger --save`
2. Usage:
```javascript
const Logger = require("@ptkdev/logger");
const logger = new Logger();
logger.info("message");
```

You can set `options` to `new Logger(options);` example:
```javascript
const Logger = require("@ptkdev/logger");

const options = {
	"language": "en",
	"colors": true,
	"debug": true,
	"info": true,
	"warning": true,
	"error": true,
	"sponsor": true,
	"write": true,
	"type": "log",
	"path": {
		"debug_log": "./debug.log",
		"error_log": "./errors.log",
	}
};

const logger = new Logger(options);
logger.info("message");
```

## Options

| Parameter | Description | Values | Default value |
| --- | --- | --- | --- |
| language | Set language of log type | en/it/pl | en |
| colors | Enable colors in terminal | true/enabled/false/disabled | true |
| debug | Enable all logs with method debug | true/enabled/false/disabled | true |
| info | Enable all logs with method info | true/enabled/false/disabled | true |
| warning | Enable all logs with method warning | true/enabled/false/disabled | true |
| error | Enable all logs with method errors | true/enabled/false/disabled | true |
| sponsor | Enable all logs with method sponsor | true/enabled/false/disabled | true |
| write | Write the logs into a file, you need set path values | true/enabled/false/disabled | false |
| type | Format of logs in files | log/json | log |
| path | If write is true, the library writes the logs to a path | Object | `{"debug_log": "./debug.log", "error_log": "./errors.log"}` |

## Methods

| Method | Description | Parameters |
| --- | --- | --- |
| **debug**(__message__, __tag__) | `message`: Display debug log message <br> `tag`: prefix of message | `message`: string (mandatory) <br> `tag`: string (optional) |
| **info**(__message__, __tag__) | `message`: Display info log message <br> `tag`: prefix of message | `message`: string (mandatory) <br> `tag`: string (optional) |
| **warning**(__message__, __tag__) | `message`: Display warning log message <br> `tag`: prefix of message | `message`: string (mandatory) <br> `tag`: string (optional) |
| **error**(__message__, __tag__) | `message`: Display errors log message <br> `tag`: prefix of message | `message`: string (mandatory) <br> `tag`: string (optional) |
| **sponsor**(__message__, __tag__) | `message`: Display sponsor log message <br> `tag`: prefix of message | `message`: string (mandatory) <br> `tag`: string (optional) |
| **stackoverflow**(__message__, __tag__, __error_string__) | `message`: Display stackoverflow log message <br> `tag`: prefix of message <br> `error_string`: query for stackoverflow, if empty we use message param | `message`: string (mandatory) <br> `tag`: string (optional) <br> `error_string`: string (optional) |
| **docs**(__message__, __url__, __tag__) | `message`: Display docs log message <br> `url`: link of documentation <br> `tag`: prefix of message | `message`: string (mandatory) <br> `url`: string (optional) <br> `tag`: string (optional) |

## 💫 License
* Code and Contributions have **MIT License**
* Images and logos have **CC BY-NC 4.0 License** 
* Documentations and Translations have **CC BY 4.0 License**


# ❤️ Thanks! Leave a feedback!
