Repository: ptkdev/ptkdev-logger Branch: master Commit: 684417b17ec0 Files: 30 Total size: 69.1 KB Directory structure: gitextract_8eo_ertk/ ├── .all-contributorsrc ├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .github/ │ ├── FUNDING.yml │ └── ISSUE_TEMPLATE/ │ ├── bug_report.md │ ├── feature_request.md │ └── question.md ├── .gitignore ├── .gitmodules ├── .npmignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── examples/ │ ├── example-json.js │ └── example.js ├── jsconfig.json ├── modules/ │ ├── logger.d.ts │ ├── logger.js │ └── types.js ├── package.json ├── translations/ │ ├── de.js │ ├── en.js │ ├── es.js │ ├── fr.js │ ├── it.js │ ├── pl.js │ ├── pt.js │ └── ru.js └── tsconfig.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .all-contributorsrc ================================================ { "projectName": "ptkdev-logger", "projectOwner": "ptkdev", "repoType": "github", "repoHost": "https://github.com", "files": [ "README.md" ], "imageSize": 100, "commit": true, "contributors": [ { "login": "ptkdev", "name": "Patryk Rzucidło", "avatar_url": "https://avatars1.githubusercontent.com/u/442844?v=4", "profile": "https://ptk.dev", "contributions": [ "code", "translation", "doc", "bug" ] }, { "login": "agoalofalife", "name": "Ilua Chubarov", "avatar_url": "https://avatars1.githubusercontent.com/u/15719824?v=4", "profile": "https://github.com/agoalofalife", "contributions": [ "code" ] }, { "login": "Bruck1701", "name": "Bruno Kümmel", "avatar_url": "https://avatars2.githubusercontent.com/u/17711277?v=4", "profile": "https://github.com/Bruck1701", "contributions": [ "code", "translation" ] }, { "login": "alinaosv", "name": "Alina Osv", "avatar_url": "https://avatars3.githubusercontent.com/u/60554247?v=4", "profile": "https://github.com/alinaosv", "contributions": [ "translation" ] }, { "login": "Syltech", "name": "Sylvain Téchené", "avatar_url": "https://avatars1.githubusercontent.com/u/3882925?v=4", "profile": "https://github.com/Syltech", "contributions": [ "translation" ] }, { "login": "GiovanniCardamone", "name": "Giovanni Cardamone", "profile": "https://github.com/giovannicardamone", "avatar_url": "https://avatars1.githubusercontent.com/u/5117748?v=4", "contributions": [ "code" ] } ], "contributorsPerLine": 6, "commitConvention": "none" } ================================================ FILE: .editorconfig ================================================ # EditorConfig is awesome: https://EditorConfig.org root = true [*] charset = utf-8 end_of_line = lf insert_final_newline = false trim_trailing_whitespace = true indent_style = tab indent_size = 4 [*.py] indent_style = space indent_size = 4 ================================================ FILE: .eslintrc.json ================================================ { "env": { "browser": true, "es6": true, "node": true, "jest/globals": true }, "extends": "eslint:recommended", "parserOptions": { "sourceType": "module", "ecmaVersion": 2019 }, "plugins": [ "jsdoc", "jest" ], "settings": { "jsdoc": { "tagNamePreference": { "returns": "return" } } }, "rules": { "no-multi-spaces": ["error", { "ignoreEOLComments": true, "exceptions": { "VariableDeclarator": true } }], "block-spacing": ["error", "always"], "array-bracket-spacing": ["error", "never"], "space-in-parens": ["error", "never"], "comma-spacing": ["error", { "before": false, "after": true }], "key-spacing": ["error", { "afterColon": true, "beforeColon": false }], "indent": ["error", "tab", { "SwitchCase": 1 }], "quotes": ["error","double", { "avoidEscape": true, "allowTemplateLiterals": true}], "semi": ["error", "always"], "no-console": ["warn"], "no-constant-condition": ["warn"], "curly": ["error", "all"], "brace-style": ["error", "1tbs", { "allowSingleLine": false }], "keyword-spacing": ["error", { "before": true, "after": true }], "object-curly-spacing": ["error", "never"], "no-mixed-spaces-and-tabs": ["error", "smart-tabs"], "spaced-comment": [2, "always"], "space-before-blocks": ["error", "always"], "space-before-function-paren": ["error", "never"], "prefer-template": "error", "no-useless-concat": "error", "prefer-arrow-callback": ["error", { "allowNamedFunctions": true }], "linebreak-style": ["error", "unix"], "template-curly-spacing": ["error", "never"], "no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0 }], "jest/no-disabled-tests": "warn", "jest/no-focused-tests": "error", "jest/no-identical-title": "error", "jest/prefer-to-have-length": "warn", "jest/valid-expect": "error", "jsdoc/require-param": 1, "jsdoc/require-param-description": 1, "jsdoc/require-param-name": 1, "jsdoc/require-param-type": 1, "jsdoc/require-returns": 1, "jsdoc/require-returns-description": 1, "jsdoc/require-returns-type": 1, "jsdoc/require-returns-check": 1, "jsdoc/require-hyphen-before-param-description": 1 } } ================================================ FILE: .gitattributes ================================================ ## AUTO-DETECT * text=auto ## SOURCE CODE *.bat text eol=crlf *.css text eol=lf *.html text diff=html eol=lf *.ini text eol=crlf *.js text eol=lf *.json text eol=lf *.php text diff=php eol=lf *.py text diff=python eol=lf *.rb text diff=ruby *.sass text eol=lf *.scss text eol=lf *.sh text eol=lf *.sql text eol=lf *.ts text eol=lf *.vue text eol=lf *.xml text eol=lf *.xhtml text diff=html eol=lf ## DOCKER *.dockerignore text eol=lf Dockerfile text eol=lf ## DOCUMENTATION *.md text eol=lf *.txt text eol=lf AUTHORS text eol=lf CHANGELOG text eol=lf CHANGES text eol=lf CONTRIBUTING text eol=lf COPYING text eol=lf INSTALL text eol=lf license text eol=lf LICENSE text eol=lf NEWS text eol=lf README text eol=lf TODO text eol=lf ## TEMPLATES *.dot text eol=lf *.tpl text eol=lf *.twig text eol=lf ## LINTERS .csslintrc text eol=lf .eslintrc text eol=lf .htmlhintrc text eol=lf .jscsrc text eol=lf .jshintrc text eol=lf .jshintignore text eol=lf .stylelintrc text eol=lf .npmignore text eol=lf ## CONFIGS *.bowerrc text eol=lf *.cnf text eol=lf *.conf text eol=lf *.config text eol=lf .babelrc text eol=lf .browserslistrc text eol=lf .editorconfig text eol=lf .env text eol=lf .gitattributes text eol=lf .gitconfig text eol=lf .htaccess text eol=lf *.lock text eol=lf *.npmignore text eol=lf *.yaml text eol=lf *.yml text eol=lf browserslist text eol=lf Makefile text eol=lf makefile text eol=lf ## GRAPHICS *.ai binary *.bmp binary *.eps binary *.gif binary *.ico binary *.jng binary *.jp2 binary *.jpg binary *.jpeg binary *.jpx binary *.jxr binary *.pdf binary *.png binary *.psb binary *.psd binary *.svg text *.svgz binary *.tif binary *.tiff binary *.wbmp binary *.webp binary ## AUDIO *.kar binary *.m4a binary *.mid binary *.midi binary *.mp3 binary *.ogg binary *.ra binary ## VIDEO *.3gpp binary *.3gp binary *.as binary *.asf binary *.asx binary *.fla binary *.flv binary *.m4v binary *.mng binary *.mov binary *.mp4 binary *.mpeg binary *.mpg binary *.ogv binary *.swc binary *.swf binary *.webm binary ## ARCHIVES *.7z binary *.gz binary *.jar binary *.rar binary *.tar binary *.zip binary ## FONTS *.ttf binary *.eot binary *.otf binary *.woff binary *.woff2 binary ## EXECUTABLES *.exe binary *.pyc binary ================================================ FILE: .github/FUNDING.yml ================================================ github: [ptkdev] patreon: ptkdev ko_fi: ptkdev ================================================ FILE: .github/ISSUE_TEMPLATE/bug_report.md ================================================ --- name: 🐛 Bug report about: Create a report to help us improve --- ### Versions - **Logger Version:** v1.0.0 - **Node Version:** v13.0.0 - **Operating System:** Windows 10 - **Terminal:** Windows Powershell ### Expected Behavior ### Actual Behavior ### Steps to Reproduce 1. ... 2. ... 3. ... ### Screenshots (Optional) ================================================ FILE: .github/ISSUE_TEMPLATE/feature_request.md ================================================ --- name: 💫 Feature request about: Suggest an idea for this project --- ### Feature description ### Feature motivation ================================================ FILE: .github/ISSUE_TEMPLATE/question.md ================================================ --- name: 🗨 Question about: Ask a question --- ### Question ================================================ FILE: .gitignore ================================================ ###################################################################################### # License: MIT - http://opensource.org/licenses/MIT # # Author: Patryk Rzucidło (@ptkdev) https://ptk.dev # # Original: octocat - https://github.com/octocat # # Latest version: https://github.com/ptkdev/dotfiles # ###################################################################################### # Compiled source # ################### *.com *.class *.dll *.exe *.o *.so # Packages # ############ *.7z *.dmg *.gz *.iso *.jar *.rar *.tar *.zip # Eclipse # ########### .classpath .project .settings .idea .idea/ .metadata *.iml *.ipr proguard/ # Logs and databases # ###################### logs/*.log logs/screenshots/*.png logs/screenshots/*.jpg examples/*.log examples/*.json databases/*.db databases/*.sql databases/*.json *.log *.sql *.sqlite *.lock *.vscode yarn-debug.log yarn-error.log # OS generated files # ###################### .DS_Store .DS_Store? ._* .Spotlight-V100 .Trashes ehthumbs.db Thumbs.db # Python # ########## *.pyc *.pyo # KDE/Linux generated files # ############################# .directory # Backup generated files # ########################## *~ *.swp *.bak *# # Android # ########### *.apk *.ap_ *.dex bin/ gen/ .gradle/ build/ local.properties # Vagrant # ########### /.vagrant # PHP # ####### ./config.php phpunit.xml /vendor composer.phar /bower_components # Runtime data # ################ pids *.pid *.seed *.pid.lock *.eslintcache # NodeJS # ########## npm-debug.log /node_modules # App # ####### plugins/*/ config.js config/*.js configs/*.js loginpin.txt configs/loginpin.txt ================================================ FILE: .gitmodules ================================================ ================================================ FILE: .npmignore ================================================ # App # ####### config/*.js configs/*.js configs/loginpin.txt .github databases/ tests/ docs/ logs/ examples/ docker/ Dockerfile Dockerfile.* loginpin.txt .gitmodules .jshintrc .gitattributes .eslintrc.json .editorconfig .pm2-process.json .all-contributorsrc .eslintcache jsconfig.js ================================================ FILE: CHANGELOG.md ================================================ # v1.8.0 (August 30, 2021) - Fix: lowdb esm [![](https://img.shields.io/badge/donate-paypal-005EA6.svg?logo=paypal)](https://www.paypal.me/ptkdev) [![](https://img.shields.io/badge/donate-patreon-F87668.svg?logo=patreon)](https://www.patreon.com/ptkdev) [![](https://img.shields.io/badge/donate-sponsors-ea4aaa.svg?logo=github)](https://github.com/sponsors/ptkdev/) [![](https://img.shields.io/badge/donate-ko--fi-29abe0.svg?logo=ko-fi)](https://ko-fi.com/ptkdev) # v1.7.2 (August 19, 2020) - Fix: Typescript export module # v1.7.1 (August 19, 2020) - Fix: Typescript typization issues (#7) # v1.7.0 (August 05, 2020) - Feature: typescript typization (Thanks: Giovanni Cardamone) # v1.6.0 (May 24, 2020) - Fix: info color (default palette) changed from #2ECC71 to #4CAF50 - Fix: docs url with custom pallette - Fix: stackoverflow url with custom pallette # v1.5.0 (May 20, 2020) - Feature: logrotate - Feature: palette: customize colors # v1.4.0 (May 11, 2020) - Translations: 🇫🇷 (Thanks: Sylvain Téchené) # v1.3.0 (May 07, 2020) - Translations: 🇷🇺 🇩🇪 (Thanks: Alina Osv) # v1.2.0 (May 06, 2020) - Fix: security patch - Translations: 🇪🇸 🇵🇹 (Thanks: Bruno Kummel) # v1.1.2 (March 28, 2020) - Fix: security patch # v1.1.1 (March 08, 2020) - Fix: default `option.type` value # v1.1.0 (March 08, 2020) - Fix: misprint of `errors` in options and docs, renamed to `error` - Fix: errors logs output moved to `stderr` - Feature: new formats of logs files, available log (text) or (json) - Compatibility: the JSON logs format is compatible with [pinojs](https://github.com/pinojs/pino) output # v1.0.0 (March 08, 2020) - First Release. ================================================ FILE: LICENSE.md ================================================ ## MIT License > Code and Contributions Copyright (c) 2020 Patryk Rzucidło (PTKDev) 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. ##### https://choosealicense.com/licenses/mit/ ## Creative Commons BY-NC 4.0 License > Images, assets and logos Copyleft (c) 2020 Patryk Rzucidło (PTKDev) #### You are free to: - Share — copy and redistribute the material in any medium or format - Adapt — remix, transform, and build upon the material The licensor cannot revoke these freedoms as long as you follow the license terms. #### Under the following terms: - Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that - suggests the licensor endorses you or your use. - NonCommercial — You may not use the material for commercial purposes. No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. ##### https://creativecommons.org/licenses/by-nc/4.0/ ## Creative Commons BY 4.0 License > Documentation and Translations Copyleft (c) 2020 Patryk Rzucidło (PTKDev) #### You are free to: - Share — copy and redistribute the material in any medium or format - Adapt — remix, transform, and build upon the material for any purpose, even commercially. The licensor cannot revoke these freedoms as long as you follow the license terms. #### Under the following terms: - Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. ##### https://creativecommons.org/licenses/by/4.0/ ================================================ FILE: README.md ================================================ [![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 [![](https://img.shields.io/badge/version-v1.8.0-lightgrey.svg)](https://github.com/ptkdev/ptkdev-logger/releases) [![](https://img.shields.io/npm/v/@ptkdev/logger.svg)](https://www.npmjs.com/package/@ptkdev/logger) [![](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/ptkdev/ptkdev-logger/blob/master/LICENSE.md) [![](https://img.shields.io/badge/ES-9-F7DF1E.svg)](https://wikipedia.org/wiki/ECMAScript) [![](https://snyk.io/test/github/ptkdev/ptkdev-logger/badge.svg)](https://snyk.io/test/github/ptkdev/ptkdev-logger) [![](https://discordapp.com/api/guilds/383373985666301975/embed.png)](http://discord.ptkdev.io) > The best alternative to the console.log statement ## 🎁 Support: Donate > This project is **free**, **open source** and I try to provide excellent **free support**. Why donate? I work on this project several hours in my spare time and try to keep it up to date and working. **THANK YOU!** [![](https://img.shields.io/badge/donate-paypal-005EA6.svg?logo=paypal)](https://www.paypal.me/ptkdev) [![](https://img.shields.io/badge/donate-patreon-F87668.svg?logo=patreon)](https://www.patreon.com/ptkdev) [![](https://img.shields.io/badge/donate-sponsors-ea4aaa.svg?logo=github)](https://github.com/sponsors/ptkdev/) [![](https://img.shields.io/badge/donate-ko--fi-29abe0.svg?logo=ko-fi)](https://ko-fi.com/ptkdev) ![](https://img.shields.io/badge/bitcoin-35jQmZCy4nsxoMM3QPFrnZePDVhdKaHMRH-E38B29.svg?logo=bitcoin) ![](https://img.shields.io/badge/ethereum-0x8b8171661bEb032828e82baBb0B5B98Ba8fBEBFc-4E8EE9.svg?logo=ethereum) ## 📎 Menu - 💡 [Features](#-features) - 👔 [Screenshot](#-screenshot) - 🚀 [How to use](#-installation) - 📚 [Documentation](#-documentation) - - 🧰 [Options](#-options) - - 🔌 [Methods](#-methods) - - 🎨 [Palette](#-palette) - - 🤹‍♂️ [LogRotate](#-logrotate) - 👨‍💻 [Contributing](#-contributing) - 🐛 [Known Bugs](https://github.com/ptkdev/ptkdev-logger/issues?q=is%3Aopen+is%3Aissue+label%3Abug) - 🍻 Community: - [Discord](http://discord.ptkdev.io) ([🇬🇧 English Channel](https://discord.gg/tWtqt4B) | [🇮🇹 Italian Channel](https://discord.gg/q29uZnm) | [🇵🇱 Polish Channel](https://discord.gg/akjuWJX)) ## 💡 Features - [✔️] Easy to use - [✔️] MIT License - [✔️] Palette (🎨 Customize colors) - [✔️] Logrotate 🤹‍♂️ - [✔️] Typescript support - [✔️] 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", rotate: { size: "10M", encoding: "utf8", }, path: { // remember: add string *.log to .gitignore debug_log: "./debug.log", error_log: "./errors.log", }, }; const logger = new Logger(options); logger.info("message"); ``` See folder `examples`, run with `node example.js`. Below is available a description of `options` values. ## 🧰 Options | Parameter | Description | Values | Default value | Available since | | --------- | ------------------------------------------------------- | ------------------------------------- | ----------------------------------------------------------- | --------------- | | language | Set language of log type | en / it / pl / es / pt / de / ru / fr | en | **v1.0.0** | | colors | Enable colors in terminal | true / enabled / false / disabled | true | **v1.0.0** | | debug | Enable all logs with method debug | true / enabled / false / disabled | true | **v1.0.0** | | info | Enable all logs with method info | true / enabled / false / disabled | true | **v1.0.0** | | warning | Enable all logs with method warning | true / enabled / false / disabled | true | **v1.0.0** | | error | Enable all logs with method errors | true / enabled / false / disabled | true | **v1.0.0** | | sponsor | Enable all logs with method sponsor | true / enabled / false / disabled | true | **v1.0.0** | | write | Write the logs into a file, you need set path values | true / enabled / false / disabled | false | **v1.0.0** | | type | Format of logs in files | log / json | log | **v1.0.0** | | rotate | Rotates the log files when size exceeds this value | `10B` / `10K` / `10M` / `10G` | `"rotate": {"size": "10M"}` | **v1.5.0** | | palette | Change palette with hexcode colors | [Object](#-palette) | default palette | **v1.5.0** | | path | If write is true, the library writes the logs to a path | Object | `{"debug_log": "./debug.log", "error_log": "./errors.log"}` | **v1.0.0** | ## 🔌 Methods | Method | Description | Parameters | | --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------- | | **debug**(`message`, `tag`) | `message`: Display debug log message
`tag`: prefix of message | `message`: string (mandatory)
`tag`: string (optional) | | **info**(`message`, `tag`) | `message`: Display info log message
`tag`: prefix of message | `message`: string (mandatory)
`tag`: string (optional) | | **warning**(`message`, `tag`) | `message`: Display warning log message
`tag`: prefix of message | `message`: string (mandatory)
`tag`: string (optional) | | **error**(`message`, `tag`) | `message`: Display errors log message
`tag`: prefix of message | `message`: string (mandatory)
`tag`: string (optional) | | **sponsor**(`message`, `tag`) | `message`: Display sponsor log message
`tag`: prefix of message | `message`: string (mandatory)
`tag`: string (optional) | | **stackoverflow**(`message`, `tag`, `error_string`) | `message`: Display stackoverflow log message
`tag`: prefix of message
`error_string`: query for stackoverflow, if empty we use message param | `message`: string (mandatory)
`tag`: string (optional)
`error_string`: string (optional) | | **docs**(`message`, `url`, `tag`) | `message`: Display docs log message
`url`: link of documentation
`tag`: prefix of message | `message`: string (mandatory)
`url`: string (optional)
`tag`: string (optional) | ## 🎨 Palette [![Beautiful Logger for Node.js](https://raw.githubusercontent.com/ptkdev/ptkdev-logger/nightly/.github/assets/screenshot/ptkdev-logger-palette.png)](https://raw.githubusercontent.com/ptkdev/ptkdev-logger/nightly/.github/assets/screenshot/ptkdev-logger-palette.png) You can customize palette colors with Object `palette` and with hexcode values. - `label` is text on left (INFORMATION / ERROR / DOCS, etc..) - `text` is message of log on right - `background` is background color on left side ```javascript { ... "palette": { "info": { // method name "label": "#ffffff", // label on left "text": "#4CAF50", // log message "background": "#4CAF50" // background }, "warning": { "label": "#ffffff", "text": "#FF9800", "background": "#FF9800" }, "error": { "label": "#ffffff", "text": "#FF5252", "background": "#FF5252" }, "stackoverflow": { "label": "#ffffff", "text": "#9C27B0", "background": "#9C27B0" }, "docs": { "label": "#ffffff", "text": "#FF4081", "background": "#FF4081" }, "debug": { "label": "#ffffff", "text": "#1976D2", "background": "#1976D2" }, "sponsor": { "label": "#ffffff", "text": "#607D8B", "background": "#607D8B" }, "time": { "label": "#ffffff", "background": "#795548" } } ... } ``` See folder `examples`, run with `node example.js`. ## 🤹‍♂️ LogRotate Rotates the file when size exceeds 10 megabytes (optional, default 10M - values: 10B (byte) / 10K (kilobyte)/ 10M (megabyte)/ 10G (gigabyte)) ```javascript ... "rotate": { "size": "10M", "encoding": "utf8" }, ... ``` ## 📚 Documentation Run `npm run docs` ## 👑 Sponsors Support this project by becoming a sponsor. 🙏 Become a sponsor on [patreon](https://www.patreon.com/join/ptkdev) or become top3 sponsor on [ko-fi](https://ko-fi.com/ptkdev). Your logo will show up here with a link to your website. [![](https://api.ptkdev.io/backers/sponsor1.png)](https://api.ptkdev.io/backers/sponsor1.html) [![](https://api.ptkdev.io/backers/sponsor2.png)](https://api.ptkdev.io/backers/sponsor2.html) [![](https://api.ptkdev.io/backers/sponsor-kofi1.png)](https://api.ptkdev.io/backers/sponsor-kofi1.html) [![](https://api.ptkdev.io/backers/sponsor-kofi2.png)](https://api.ptkdev.io/backers/sponsor-kofi2.html) [![](https://api.ptkdev.io/backers/sponsor-kofi3.png)](https://api.ptkdev.io/backers/sponsor-kofi3.html) [![](https://api.ptkdev.io/backers/sponsor3.png)](https://api.ptkdev.io/backers/sponsor3.html) [![](https://api.ptkdev.io/backers/sponsor4.png)](https://api.ptkdev.io/backers/sponsor4.html) [![](https://api.ptkdev.io/backers/sponsor5.png)](https://api.ptkdev.io/backers/sponsor5.html) [![](https://api.ptkdev.io/backers/sponsor6.png)](https://api.ptkdev.io/backers/sponsor6.html) [![](https://api.ptkdev.io/backers/sponsor7.png)](https://api.ptkdev.io/backers/sponsor7.html) [![](https://api.ptkdev.io/backers/sponsor8.png)](https://api.ptkdev.io/backers/sponsor8.html) [![](https://api.ptkdev.io/backers/sponsor9.png)](https://api.ptkdev.io/backers/sponsor9.html) [![](https://api.ptkdev.io/backers/sponsor10.png)](https://api.ptkdev.io/backers/sponsor10.html) [![](https://api.ptkdev.io/backers/sponsor11.png)](https://api.ptkdev.io/backers/sponsor11.html) [![](https://api.ptkdev.io/backers/sponsor12.png)](https://api.ptkdev.io/backers/sponsor12.html) [![](https://api.ptkdev.io/backers/sponsor13.png)](https://api.ptkdev.io/backers/sponsor13.html) [![](https://api.ptkdev.io/backers/sponsor14.png)](https://api.ptkdev.io/backers/sponsor14.html) [![](https://api.ptkdev.io/backers/sponsor15.png)](https://api.ptkdev.io/backers/sponsor15.html) ## 🦄 Backers Thank you to all our backers! 🙏 Become a backer on [patreon](https://www.patreon.com/join/ptkdev). [![](https://api.ptkdev.io/backers/backer1.png)](https://api.ptkdev.io/backers/backer1.html) [![](https://api.ptkdev.io/backers/backer2.png)](https://api.ptkdev.io/backers/backer2.html) [![](https://api.ptkdev.io/backers/backer3.png)](https://api.ptkdev.io/backers/backer3.html) [![](https://api.ptkdev.io/backers/backer4.png)](https://api.ptkdev.io/backers/backer4.html) [![](https://api.ptkdev.io/backers/backer5.png)](https://api.ptkdev.io/backers/backer5.html) [![](https://api.ptkdev.io/backers/backer6.png)](https://api.ptkdev.io/backers/backer6.html) [![](https://api.ptkdev.io/backers/backer7.png)](https://api.ptkdev.io/backers/backer7.html) [![](https://api.ptkdev.io/backers/backer8.png)](https://api.ptkdev.io/backers/backer8.html) [![](https://api.ptkdev.io/backers/backer9.png)](https://api.ptkdev.io/backers/backer9.html) [![](https://api.ptkdev.io/backers/backer10.png)](https://api.ptkdev.io/backers/backer10.html) [![](https://api.ptkdev.io/backers/backer11.png)](https://api.ptkdev.io/backers/backer11.html) [![](https://api.ptkdev.io/backers/backer12.png)](https://api.ptkdev.io/backers/backer12.html) [![](https://api.ptkdev.io/backers/backer13.png)](https://api.ptkdev.io/backers/backer13.html) [![](https://api.ptkdev.io/backers/backer14.png)](https://api.ptkdev.io/backers/backer14.html) [![](https://api.ptkdev.io/backers/backer15.png)](https://api.ptkdev.io/backers/backer15.html) ## 👨‍💻 Contributing I ❤️ contributions! I will happily accept your pull request! Translations, grammatical corrections (GrammarNazi you are welcome! Yes my English is bad, sorry), etc... Do not be afraid, if the code is not perfect we will work together 👯 and remember to insert your name in `.all-contributorsrc` and `package.json` file. Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

Patryk Rzucidło

💻 🌍 📖 🐛

Ilua Chubarov

💻

Bruno Kümmel

💻 🌍

Alina Osv

🌍

Sylvain Téchené

🌍

Giovanni Cardamone

💻
> 💰 In the future, if the donations allow it, I would like to share some of the success with those who helped me the most. For me open source is share of code, share development knowledges and share donations! ## 📲 Tools [![](https://img.shields.io/badge/portfolio-ptkdev-000000.svg)](https://ptk.dev/) [![](https://img.shields.io/badge/app-meingifs-E1215B.svg)](https://meingifs.pics/) [![](https://img.shields.io/badge/stickers-ptkdev-128C7E.svg)](https://stickers.ptkdev.io/) [![](https://img.shields.io/badge/app-social%20manager%20tools-ff7f19.svg)](http://logger.ptkdev.io/) [![](https://img.shields.io/badge/api-instagram%20bot-895a4d.svg)](https://github.com/ptkdev/ptkdev-logger) [![](https://img.shields.io/badge/api-twitter%20bot-21B7F4.svg)](https://github.com/social-manager-tools/socialmanagertools-twbot) [![](https://img.shields.io/badge/api-facebook%20bot-3b5998.svg)](https://github.com/social-manager-tools/socialmanagertools-fbbot) [![](https://img.shields.io/badge/telegram%20bot-feed%20rss%20for%20wordpress%20&%20medium-00AB6C.svg)](https://github.com/social-manager-tools/socialmanagertools-tgbot) ## 🐍 Sorry for snake_case I love snake_case syntax sorry for this 😭 don't hate me. ## 💫 License - Code and Contributions have **MIT License** - Images and logos have **CC BY-NC 4.0 License** ([Freepik](https://it.freepik.com/) Premium License) - Documentations and Translations have **CC BY 4.0 License** ###### Copyleft (c) 2020 [Patryk Rzucidło](https://ptk.dev) ([@PTKDev](https://twitter.com/ptkdev)) <[support@ptkdev.io](mailto:support@ptkdev.io)> ================================================ FILE: examples/example-json.js ================================================ /** * Logger: example (json output) * ===================== * * @contributors: Patryk Rzucidło [@ptkdev] (https://ptk.dev) * * @license: MIT License * */ const Logger = require("./../modules/logger"); // in your project use: require("@ptkdev/logger"); const options = { "language": "en", // set language of log type, NOTE: please help with translations! (optional, default en - values: en|it|pl|es|pt|de|ru) "colors": true, // enable/disable colors in terminal (optional, default enabled - values: true|enabled or false|disabled) "debug": true, // enable/disable all logs with method debug (optional, default enabled - values: true|enabled or false|disabled) "info": true, // enable/disable all logs with method info (optional, default enabled - values: true|enabled or false|disabled) "warning": true, // enable/disable all logs with method warning (optional, default enabled - values: true|enabled or false|disabled) "error": true, // enable/disable all logs with method errors (optional, default enabled - values: true|enabled or false|disabled) "sponsor": true, // enable/disable all logs with method sponsor (optional, default enabled - values: true|enabled or false|disabled) "write": true, // write the logs into a file, you need set path values (optional, default disabled - values: true|enabled or false|disabled) "type": "json", // format of logs in files (optional, default log - values: log|json) "path": { // if write is true, the library writes the logs to a path "debug_log": "./debug.json", // all logs "error_log": "./errors.json", // only errors logs } }; const logger = new Logger(options); logger.info("your info message", "your tag"); logger.warning("your warning message", "your tag"); logger.error("your error message", "your tag"); logger.debug("your debug message", "your tag"); logger.sponsor("your sponsor message", "your tag"); logger.stackoverflow("your stackoverflow message", "your tag"); logger.docs("your docs message", "https://docs.yoursite.com", "your tag"); ================================================ FILE: examples/example.js ================================================ /** * Logger: example * ===================== * * @contributors: Patryk Rzucidło [@ptkdev] (https://ptk.dev) * * @license: MIT License * */ const Logger = require("./../modules/logger"); // in your project use: require("@ptkdev/logger"); const options = { "language": "en", // set language of log type, NOTE: please help with translations! (optional, default en - values: en|it|pl|es|pt|de|ru) "colors": true, // enable/disable colors in terminal (optional, default enabled - values: true|enabled or false|disabled) "debug": true, // enable/disable all logs with method debug (optional, default enabled - values: true|enabled or false|disabled) "info": true, // enable/disable all logs with method info (optional, default enabled - values: true|enabled or false|disabled) "warning": true, // enable/disable all logs with method warning (optional, default enabled - values: true|enabled or false|disabled) "error": true, // enable/disable all logs with method errors (optional, default enabled - values: true|enabled or false|disabled) "sponsor": true, // enable/disable all logs with method sponsor (optional, default enabled - values: true|enabled or false|disabled) "write": true, // write the logs into a file, you need set path values (optional, default disabled - values: true|enabled or false|disabled) "type": "log", // format of logs in files (optional, default log - values: log|json) "rotate": { "size": "10M", // Rotates the file when size exceeds 10 megabytes (optional, default 10M - values: 10B (byte) / 10K (kilobyte)/ 10M (megabyte)/ 10G (gigabyte)) "encoding": "utf8" }, "path": { // if write is true, the library writes the logs to a path "debug_log": "./debug.log", // all logs "error_log": "./errors.log", // only errors logs }, "palette": { "info": { "label": "#ffffff", // label on left "text": "#2ECC71", // log message "background": "#2ECC71" // background }, "warning": { "label": "#ffffff", "text": "#FF9800", "background": "#FF9800" }, "error": { "label": "#ffffff", "text": "#FF5252", "background": "#FF5252" }, "stackoverflow": { "label": "#ffffff", "text": "#9C27B0", "background": "#9C27B0" }, "docs": { "label": "#ffffff", "text": "#FF4081", "background": "#FF4081" }, "debug": { "label": "#ffffff", "text": "#1976D2", "background": "#1976D2" }, "sponsor": { "label": "#ffffff", "text": "#607D8B", "background": "#607D8B" }, "time": { "label": "#ffffff", "background": "#795548" } } }; const logger = new Logger(options); logger.info("your info message", "your tag"); logger.warning("your warning message", "your tag"); logger.error("your error message", "your tag"); logger.debug("your debug message", "your tag"); logger.sponsor("your sponsor message", "your tag"); logger.stackoverflow("your stackoverflow message", "your tag"); logger.docs("your docs message", "https://docs.yoursite.com", "your tag"); ================================================ FILE: jsconfig.json ================================================ { "exclude": [ "node_modules" ], "include": [ "**/*.js" ] } ================================================ FILE: modules/logger.d.ts ================================================ declare module "@ptkdev/logger" { interface RotateType { size: "10B" | "10K" | "10M" | "10G"; encoding?: string; } interface PaletteElement { label: string; text: string; background: string; } interface PaletteType { info?: PaletteElement; warning?: PaletteElement; error?: PaletteElement; stackoverflow?: PaletteElement; docs?: PaletteElement; debug?: PaletteElement; sponsor?: PaletteElement; time?: Omit; } interface PathType { debug_log: string; error_log: string; } interface LoggerOptions { language?: "de" | "en" | "es" | "fr" | "it" | "pl" | "pt" | "ru"; colors?: boolean; debug?: boolean; info?: boolean; warning?: boolean; error?: boolean; sponsor?: boolean; write?: boolean; type?: "log" | "json"; rotate?: RotateType; palette?: PaletteType; path?: PathType; } export default class Logger { constructor(options?: LoggerOptions); /** * Logging of the debug message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} tag - func unique tag (optional) * */ debug(message: string, tag?: string): void; /** * Logging of the info message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} tag - func unique tag (optional) * */ info(message: string, tag?: string): void; /** * Logging of the warning message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} tag - func unique tag (optional) * */ warning(message: string, tag?: string): void; /** * Logging of the error message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} tag - func unique tag (optional) * */ error(message: string, tag?: string): void; /** * Logging of the sponsor message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} tag - func unique tag (optional) * */ sponsor(message: string, tag?: string): void; /** * Logging of the stackoverflow message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} tag - func unique tag (optional) * @param {string} error_message - error message to stackoverflow (optional) * */ stackoverflow( message: string, tag?: string, error_message?: string ): void; /** * Logging of the docs message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} url - url of documentation (optional) * @param {string} tag - func unique tag (optional) * * */ docs(message: string, url?: string, tag?: string): void; } } ================================================ FILE: modules/logger.js ================================================ /** * Logger: write log * ===================== * * @contributors: Patryk Rzucidło [@ptkdev] (https://ptk.dev) * Ilya Chubarov [@agoalofalife] * * @license: MIT License * */ const path = require("path"); const fse = require("fs-extra"); const chalk = require("chalk"); const ansi = require("strip-ansi"); const rfs = require("rotating-file-stream"); const lowdb = require("lowdb"); const FileSync = require("lowdb/adapters/FileSync"); const languages = { de: require("../translations/de"), en: require("../translations/en"), es: require("../translations/es"), fr: require("../translations/fr"), it: require("../translations/it"), pl: require("../translations/pl"), pt: require("../translations/pt"), ru: require("../translations/ru") }; const logger = console; let Types = require("./types"); class Log { constructor(options = new Object) { if (typeof options.language === "undefined" || options.language === null) { options.language = "en"; } Types.INFO.label = languages[options.language]["INFO"]; Types.WARNING.label = languages[options.language]["WARNING"]; Types.ERROR.label = languages[options.language]["ERROR"]; Types.DEBUG.label = languages[options.language]["DEBUG"]; Types.DOCS.label = languages[options.language]["DOCS"]; Types.STACKOVERFLOW.label = languages[options.language]["STACKOVERFLOW"]; Types.SPONSOR.label = languages[options.language]["SPONSOR"]; if (typeof options.palette === "undefined" || options.palette === null) { options.palette = null; } else { if (typeof options.palette.info !== "undefined" && options.palette.info !== null) { Types.INFO.bgcolor = (typeof options.palette.info.background === "undefined" || options.palette.info.background === null) ? Types.INFO.bgcolor : chalk.bgHex(options.palette.info.background).hex(options.palette.info.label); Types.INFO.color = (typeof options.palette.info.text === "undefined" || options.palette.info.text === null) ? Types.INFO.color : chalk.hex(options.palette.info.text); } if (typeof options.palette.warning !== "undefined" && options.palette.warning !== null) { Types.WARNING.bgcolor = (typeof options.palette.warning.background === "undefined" || options.palette.warning.background === null) ? Types.WARNING.bgcolor : chalk.bgHex(options.palette.warning.background).hex(options.palette.warning.label); Types.WARNING.color = (typeof options.palette.warning.text === "undefined" || options.palette.warning.text === null) ? Types.WARNING.color : chalk.hex(options.palette.warning.text); } if (typeof options.palette.error !== "undefined" && options.palette.error !== null) { Types.ERROR.bgcolor = (typeof options.palette.error.background === "undefined" || options.palette.error.background === null) ? Types.ERROR.bgcolor : chalk.bgHex(options.palette.error.background).hex(options.palette.error.label); Types.ERROR.color = (typeof options.palette.error.text === "undefined" || options.palette.error.text === null) ? Types.ERROR.color : chalk.hex(options.palette.error.text); } if (typeof options.palette.debug !== "undefined" && options.palette.debug !== null) { Types.DEBUG.bgcolor = (typeof options.palette.debug.background === "undefined" || options.palette.debug.background === null) ? Types.DEBUG.bgcolor : chalk.bgHex(options.palette.debug.background).hex(options.palette.debug.label); Types.DEBUG.color = (typeof options.palette.debug.text === "undefined" || options.palette.debug.text === null) ? Types.DEBUG.color : chalk.hex(options.palette.debug.text); } if (typeof options.palette.docs !== "undefined" && options.palette.docs !== null) { Types.DOCS.bgcolor = (typeof options.palette.docs.background === "undefined" || options.palette.docs.background === null) ? Types.DOCS.bgcolor : chalk.bgHex(options.palette.docs.background).hex(options.palette.docs.label); Types.DOCS.color = (typeof options.palette.docs.text === "undefined" || options.palette.docs.text === null) ? Types.DOCS.color : chalk.hex(options.palette.docs.text); } if (typeof options.palette.stackoverflow !== "undefined" && options.palette.stackoverflow !== null) { Types.STACKOVERFLOW.bgcolor = (typeof options.palette.stackoverflow.background === "undefined" || options.palette.stackoverflow.background === null) ? Types.STACKOVERFLOW.bgcolor : chalk.bgHex(options.palette.stackoverflow.background).hex(options.palette.stackoverflow.label); Types.STACKOVERFLOW.color = (typeof options.palette.stackoverflow.text === "undefined" || options.palette.stackoverflow.text === null) ? Types.STACKOVERFLOW.color : chalk.hex(options.palette.stackoverflow.text); } if (typeof options.palette.sponsor !== "undefined" && options.palette.sponsor !== null) { Types.SPONSOR.bgcolor = (typeof options.palette.sponsor.background === "undefined" || options.palette.sponsor.background === null) ? Types.SPONSOR.bgcolor : chalk.bgHex(options.palette.sponsor.background).hex(options.palette.sponsor.label); Types.SPONSOR.color = (typeof options.palette.sponsor.text === "undefined" || options.palette.sponsor.text === null) ? Types.SPONSOR.color : chalk.hex(options.palette.sponsor.text); } if (typeof options.palette.time !== "undefined" && options.palette.time !== null) { Types.TIME.bgcolor = (typeof options.palette.time.background === "undefined" || options.palette.time.background === null) ? Types.TIME.bgcolor : chalk.bgHex(options.palette.time.background).hex(options.palette.time.label); Types.TIME.color = (typeof options.palette.time.text === "undefined" || options.palette.time.text === null) ? Types.TIME.color : chalk.hex(options.palette.time.text); } } if (typeof options.colors === "undefined" || options.colors === null) { options.colors = true; } if (typeof options.debug === "undefined" || options.debug === null) { options.debug = true; } if (typeof options.info === "undefined" || options.info === null) { options.info = true; } if (typeof options.warning === "undefined" || options.warning === null) { options.warning = true; } if (typeof options.error === "undefined" || options.error === null) { options.error = true; } if (typeof options.type === "undefined" || options.type === null) { options.type = "log"; } if (typeof options.write === "undefined" || options.write === null) { options.write = false; } else if (typeof options.path === "undefined" || options.path === null) { if (typeof options.debug_log === "undefined" || options.debug_log === null) { options.debug_log = "./debug.log"; } if (typeof options.error_log === "undefined" || options.error_log === null) { options.error_log = "./errors.log"; } } if (typeof options.rotate === "undefined" || options.rotate === null) { options.rotate = { size: "10M", encoding: "utf8" }; } this.config = options; if (this.config.write === "enabled" || this.config.write === true) { const pad = num => (num > 9 ? "" : "0") + num; rfs.createStream((time, index) => { if (!time) { return this.config.path.debug_log; } return `${path.parse(this.config.path.debug_log).base.split(".")[0]}.${time.getFullYear()}${pad(time.getMonth() + 1)}${pad(time.getDate())}-${index}.${path.parse(this.config.path.debug_log).base.split(".")[1]}`; }, this.config.rotate); rfs.createStream((time, index) => { if (!time) { return this.config.path.error_log; } return `${path.parse(this.config.path.error_log).base.split(".")[0]}.${time.getFullYear()}${pad(time.getMonth() + 1)}${pad(time.getDate())}-${index}.${path.parse(this.config.path.error_log).base.split(".")[1]}`; }, this.config.rotate); } this.TYPES_LOG = Types; } /** * Date now * ===================== * Current (now) date and time for prefix of logs. Timezone is supported. * * @param {string} format - format of date: json, timestamp or string (optional, deafult: string) * @return {string} time - current Date.now() * */ currentTime(format = "string") { let tz_offset = (new Date()).getTimezoneOffset() * 60000; if (format === "json") { return (new Date(Date.now() - tz_offset)).toISOString(); } if (format === "timestamp") { return (new Date(Date.now() - tz_offset)).getTime(); } return (new Date(Date.now() - tz_offset)).toISOString().slice(0, -5).replace("T", " "); } /** * Write the output of console.log() to file * ===================== * Write messages to debug.log and error.log in /logs folder * * @param {string} type - example: INFO/WARNING/ERROR/DEBUG or other valid type string (see ./types.js) (mandatory) * @param {string} message - description of issue (mandatory) * @param {string} tag - func unique tag (optional) * */ appendFile(type = "INFO", tag = "", message = "") { if (this.config.write === "enabled" || this.config.write === true) { if (this.config.type === "log") { if (tag !== "") { tag = `${tag}: `; } let log_text = `[${this.currentTime()}] [${type.id}] ${tag}${message}\n`; fse.appendFile(this.config.path.debug_log, ansi(log_text), (err) => { if (err) { logger.log(err); } }); if (type.id === "ERROR") { fse.appendFile(this.config.path.error_log, ansi(log_text), (err) => { if (err) { logger.err(err); } }); } } else { const debug_adapter = new FileSync(this.config.path.debug_log); const debug_db = lowdb(debug_adapter); const error_adapter = new FileSync(this.config.path.error_log); const error_db = lowdb(error_adapter); let level = 0; switch (type.id) { case "ERROR": level = 1; break; case "WARNING": level = 2; break; case "INFO": level = 3; break; case "DEBUG": level = 4; break; default: level = 5; break; } debug_db.defaults({logs: []}).write(); error_db.defaults({logs: []}).write(); debug_db.get("logs").push({level: level, time: this.currentTime("timestamp"), date: this.currentTime("json"), msg: ansi(message), tag: ansi(tag), v: 1}).write(); if (type.id === "ERROR") { error_db.get("logs").push({level: level, time: this.currentTime("timestamp"), date: this.currentTime("json"), msg: ansi(message), tag: ansi(tag), v: 1}).write(); } } } } /** * Write to stdout * ===================== * Stdout manager - don't use this directly. Use info() error() debug() warning() * * @param {string} type - example: INFO/WARNING/ERROR/DEBUG or other valid type string (see ./types.js) (mandatory) * @param {string} tag - func unique tag (optional) * @param {string} message - error, warning or info description (mandatory) * */ stdout(type = "INFO", tag = "", message = "") { let time = this.TYPES_LOG.TIME; if (tag !== "") { tag = ` ${tag}:`; } if (this.config.colors === "enabled" || this.config.colors === true) { logger.log(chalk`${type.bgcolor(type.label)}${time.bgcolor(` ${this.currentTime()} `)}${type.bgcolor(" ")}${type.color(tag)} ${type.color(message)}`); } else { logger.log(ansi(chalk`${type.bgcolor(type.label)}${time.bgcolor(` ${this.currentTime()} `)}${type.bgcolor(" ")}${type.color(tag)} ${type.color(message)}`)); } } /** * Write to stderr * ===================== * Stderr manager - don't use this directly. Use info() error() debug() warning() * * @param {string} type - example: INFO/WARNING/ERROR/DEBUG or other valid type string (see ./types.js) (mandatory) * @param {string} tag - func unique tag (optional) * @param {string} message - error, warning or info description (mandatory) * */ stderr(type = "ERROR", tag = "", message = "") { let time = this.TYPES_LOG.TIME; if (tag !== "") { tag = ` ${tag}:`; } if (this.config.colors === "enabled" || this.config.colors === true) { logger.error(chalk`${type.bgcolor(type.label)}${time.bgcolor(` ${this.currentTime()} `)}${type.bgcolor(" ")}${type.color(tag)} ${type.color(message)}`); } else { logger.error(ansi(chalk`${type.bgcolor(type.label)}${time.bgcolor(` ${this.currentTime()} `)}${type.bgcolor(" ")}${type.color(tag)} ${type.color(message)}`)); } } /** * Logging of the info message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} tag - func unique tag (optional) * */ info(message = "", tag = "") { if (this.config.info === "enabled" || this.config.info === true) { this.stdout(this.TYPES_LOG.INFO, tag, `${message}`); this.appendFile(this.TYPES_LOG.INFO, tag, message); } } /** * Logging of the warning message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} tag - func unique tag (optional) * */ warning(message = "", tag = "") { if (this.config.warning === "enabled" || this.config.warning === true) { this.stdout(this.TYPES_LOG.WARNING, tag, `${message}`); this.appendFile(this.TYPES_LOG.WARNING, tag, message); } } /** * Logging of the error message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} tag - func unique tag (optional) * */ error(message = "", tag = "") { if (this.config.error === "enabled" || this.config.error === true) { this.stderr(this.TYPES_LOG.ERROR, tag, `${message}`); this.appendFile(this.TYPES_LOG.ERROR, tag, message); } } /** * Logging of the debug message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} tag - func unique tag (optional) * */ debug(message = "", tag = "") { if (this.config.debug === "enabled" || this.config.debug === true) { this.stdout(this.TYPES_LOG.DEBUG, tag, `${message}`); this.appendFile(this.TYPES_LOG.DEBUG, tag, message); } } /** * Logging of the docs message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} url - url of documentation (optional) * @param {string} tag - func unique tag (optional) * */ docs(message = "", url = "", tag = "") { let docs = this.TYPES_LOG.DOCS; this.stdout(this.TYPES_LOG.DOCS, tag, `${message} - ${docs.color.underline.italic(url)}`); this.appendFile(this.TYPES_LOG.DOCS, tag, `${message} - ${docs.color.underline.italic(url)}`); } /** * Logging of the stackoverflow message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} tag - func unique tag (optional) * @param {string} error_message - error message to stackoverflow (optional) * */ stackoverflow(message = "", tag = "", error_message = null) { if (typeof error_message === "undefined" || error_message === null) { error_message = message; } let stackoverflow = this.TYPES_LOG.STACKOVERFLOW; let url = `https://stackoverflow.com/search?q=${encodeURI(error_message)}`; this.stdout(this.TYPES_LOG.STACKOVERFLOW, tag, `${message} - ${stackoverflow.color.underline.italic(url)}`); this.appendFile(this.TYPES_LOG.STACKOVERFLOW, tag, `${message} - ${stackoverflow.color.underline.italic(url)}`); } /** * Logging of the sponsor message * ===================== * This method show message on terminal and/or write message on file/json * * @param {string} message - description of issue (mandatory) * @param {string} tag - func unique tag (optional) * */ sponsor(message = "", tag = "") { this.stdout(this.TYPES_LOG.SPONSOR, tag, message); this.appendFile(this.TYPES_LOG.SPONSOR, tag, message); } } module.exports = Log; module.exports.default = Log; ================================================ FILE: modules/types.js ================================================ /** * Types * ===================== * Color and tags of debug and log message * * @contributors: Patryk Rzucidło [@ptkdev] (https://ptk.dev) * Ilya Chubarov [@agoalofalife] * * @license: MIT License * */ const chalk = require("chalk"); module.exports = { DEBUG: { bgcolor: chalk.bgRgb(155, 89, 182).white.bold, color: chalk.rgb(155, 89, 182), id: "DEBUG", label: " | INFORMATION " }, DOCS: { bgcolor: chalk.bgRgb(236, 135, 191).white.bold, color: chalk.rgb(236, 135, 191), id: "DOCS", label: " | DOCUMENTATION " }, ERROR: { bgcolor: chalk.bgRgb(192, 57, 43).white.bold, color: chalk.rgb(192, 57, 43), id: "ERROR", label: " | ERROR " }, INFO: { bgcolor: chalk.bgRgb(76, 175, 80).white.bold, color: chalk.rgb(76, 175, 80), id: "INFO", label: " | INFORMATION " }, SPONSOR: { bgcolor: chalk.bgRgb(22, 160, 133).white.bold, color: chalk.rgb(22, 160, 133), id: "SPONSOR", label: " | SPONSOR " }, STACKOVERFLOW: { bgcolor: chalk.bgRgb(41, 128, 185).white.bold, color: chalk.rgb(41, 128, 185), id: "STACKOVERFLOW", label: " | STACKOVERFLOW " }, TIME: { bgcolor: chalk.bgRgb(44, 62, 80).white.bold, color: chalk.rgb(44, 62, 80), id: "TIME", label: " | TIME " }, WARNING: { bgcolor: chalk.bgRgb(243, 156, 18).white.bold, color: chalk.rgb(243, 156, 18), id: "WARNING", label: " | WARNING " } }; ================================================ FILE: package.json ================================================ { "name": "@ptkdev/logger", "description": "Beautiful Logger for Node.js: the best alternative to the console.log statement", "version": "1.8.0", "main": "modules/logger.js", "author": "Patryk Rzucidło [@ptkdev] (https://ptk.dev)", "license": "MIT", "license-docs": "CC BY 4.0", "license-translations": "CC BY 4.0", "license-images": "CC BY-NC 4.0", "homepage": "https://logger.ptkdev.io", "docs": "https://docs.logger.ptkdev.io", "repository": { "type": "git", "url": "https://github.com/ptkdev/ptkdev-logger.git" }, "bugs": { "url": "https://github.com/ptkdev/ptkdev-logger/issues" }, "scripts": { "example": "cd examples && node examples/example.js", "clean": "rm -rf node_modules package-lock.json && npm install", "update": "rm -f package-lock.json && npm update", "lint": "eslint ./ --cache --ignore-pattern .gitignore", "lint-fix": "eslint ./ --cache --ignore-pattern .gitignore --fix", "git-set-upstream": "git remote add upstream git@github.com:ptkdev/ptkdev-logger.git && git fetch upstream", "git-pull-upstream": "git pull upstream master && git pull upstream beta && git pull upstream nightly", "git-pull": "git pull --recursive", "git-ignore-reset": "git rm -r --cached . && git add . && git commit -m \"[Fix] Removing all files in .gitignore\"", "npm-publish-master": "git checkout master && npm publish", "npm-publish-beta": "git checkout beta && npm publish --tag beta", "npm-publish-nightly": "git checkout nightly && npm publish --tag nightly", "docs": "git submodule update --recursive && markserv ./README.md", "test": "jest", "contributors-generate": "all-contributors generate", "pkg-upgrade": "npx npm-check-updates -u && npm install && husky install" }, "husky": { "hooks": { "pre-commit": "npm run lint && npm run contributors-generate" } }, "keywords": [ "ptkdev", "logger", "log", "logging", "console.log", "pinojs", "pino-logger", "pino", "typescript" ], "engines": { "node": ">=10.0.0" }, "dependencies": { "rotating-file-stream": "^2.1.5", "chalk": "^4.1.2", "lowdb": "^1.0.0", "fs-extra": "^10.0.0", "strip-ansi": "^6.0.0" }, "devDependencies": { "@ptkdev/all-shields-cli": "^2.0.2", "eslint": "^7.32.0", "eslint-plugin-jsdoc": "^36.0.8", "eslint-plugin-jest": "^24.4.0", "all-contributors-cli": "^6.20.0", "pm2": "^5.1.1", "json": "^11.0.0", "jest": "^27.1.0", "husky": "^7.0.2", "yargs": "^17.1.1", "markserv": "^1.17.4" }, "contributors": [ "Ilua Chubarov [@Ilya] (https://github.com/agoalofalife)", "Bruno Kummel [@Bruck1701] (https://github.com/Bruck1701)", "Alina Osv [@alinaosv] (https://github.com/alinaosv)", "Sylvain Téchené [@syltech] (https://github.com/Syltech)", "Giovanni Cardamone [@GiovanniCardamone] (https://github.com/GiovanniCardamone)" ] } ================================================ FILE: translations/de.js ================================================ /** * Translation: Portuguese * ===================== * How translate: * Chalk: chalk is npm plugin to colorize text in terminal, example: {white.bold.bgRgb(46, 204, 113) TEXT_TEXT_TEXT } * don't translate white.bold.bgRgb but translate TEXT_TEXT_TEXT before of } * * Keys: don't translate keywords on left, example: {"done":"done"} * word on left side is keyword, ever in English. Translate only phrases on right side of two dots * * Param: don't translate words between ## ##, example: ##ciao## * * @contributors: Alina Osv [@alinaosv] (https://github.com/alinaosv) * * @license: CC BY 4.0 License * */ module.exports = { INFO: " | INFORMATION ", WARNING: " | WARNUNG ", ERROR: " | FEHLER ", DEBUG: " | DEBUG ", DOCS: " | DOKUMENTATION ", STACKOVERFLOW: " | STACKOVERFLOW ", SPONSOR: " | SPONSOR " }; ================================================ FILE: translations/en.js ================================================ /** * Translation: English * ===================== * How translate: * Chalk: chalk is npm plugin to colorize text in terminal, example: {italic.bold.rgb(46, 204, 113) TEXT_TEXT_TEXT } * don't translate italic.bold.rgb but translate TEXT_TEXT_TEXT before of } * * Keys: don't translate keywords on left, example: {"done":"i'm here"} * word on left side is keyword, ever in English. Translate only phrases on right side of two dots * * Param: don't translate words between ## ##, example: ##ciao## * * @contributors: Patryk Rzucidło [@ptkdev] (https://ptk.dev) * * @license: CC BY 4.0 License * */ module.exports = { INFO: " | INFORMATION ", WARNING: " | WARNING ", ERROR: " | ERROR ", DEBUG: " | DEBUG ", DOCS: " | DOCUMENTATION ", STACKOVERFLOW: " | STACKOVERFLOW ", SPONSOR: " | SPONSOR " }; ================================================ FILE: translations/es.js ================================================ /** * Translation: Spanish * ===================== * How translate: * Chalk: chalk is npm plugin to colorize text in terminal, example: {white.bold.bgRgb(46, 204, 113) TEXT_TEXT_TEXT } * don't translate white.bold.bgRgb but translate TEXT_TEXT_TEXT before of } * * Keys: don't translate keywords on left, example: {"done":"done"} * word on left side is keyword, ever in English. Translate only phrases on right side of two dots * * Param: don't translate words between ## ##, example: ##ciao## * * @contributors: Bruno Kummel [@Bruck1701] (https://github.com/Bruck1701) * * @license: CC BY 4.0 License * */ module.exports = { INFO: " | INFORMACIÓN ", WARNING: " | ADVERTENCIA ", ERROR: " | ERROR ", DEBUG: " | DEBUG ", DOCS: " | DOCUMENTACIÓN ", STACKOVERFLOW: " | STACKOVERFLOW ", SPONSOR: " | SPONSOR " }; ================================================ FILE: translations/fr.js ================================================ /** * Translation: English * ===================== * How translate: * Chalk: chalk is npm plugin to colorize text in terminal, example: {italic.bold.rgb(46, 204, 113) TEXT_TEXT_TEXT } * don't translate italic.bold.rgb but translate TEXT_TEXT_TEXT before of } * * Keys: don't translate keywords on left, example: {"done":"i'm here"} * word on left side is keyword, ever in English. Translate only phrases on right side of two dots * * Param: don't translate words between ## ##, example: ##ciao## * * @contributors: Sylvain Téchené [@Syltech] (https://github.com/Syltech) * * @license: CC BY 4.0 License * */ module.exports = { INFO: " | INFORMATION ", WARNING: " | ALERTE ", ERROR: " | ERREUR ", DEBUG: " | DEBUG ", DOCS: " | DOCUMENTATION ", STACKOVERFLOW: " | STACKOVERFLOW ", SPONSOR: " | SPONSOR " }; ================================================ FILE: translations/it.js ================================================ /** * Translation: Italian * ===================== * How translate: * Chalk: chalk is npm plugin to colorize text in terminal, example: {white.bold.bgRgb(46, 204, 113) TEXT_TEXT_TEXT } * don't translate white.bold.bgRgb but translate TEXT_TEXT_TEXT before of } * * Keys: don't translate keywords on left, example: {"done":"done"} * word on left side is keyword, ever in English. Translate only phrases on right side of two dots * * Param: don't translate words between ## ##, example: ##ciao## * * @contributors: Patryk Rzucidło [@ptkdev] (https://ptk.dev) * * @license: CC BY 4.0 License * */ module.exports = { INFO: " | INFORMAZIONI ", WARNING: " | ATTENZIONE ", ERROR: " | ERRORE ", DEBUG: " | DEBUG ", DOCS: " | DOCUMENTAZIONE ", STACKOVERFLOW: " | STACKOVERFLOW ", SPONSOR: " | SPONSOR " }; ================================================ FILE: translations/pl.js ================================================ /** * Translation: Polski * ===================== * How translate: * Chalk: chalk is npm plugin to colorize text in terminal, example: {white.bold.bgRgb(46, 204, 113) TEXT_TEXT_TEXT } * don't translate white.bold.bgRgb but translate TEXT_TEXT_TEXT before of } * * Keys: don't translate keywords on left, example: {"done":"done"} * word on left side is keyword, ever in English. Translate only phrases on right side of two dots * * Param: don't translate words between ## ##, example: ##ciao## * * @contributors: Patryk Rzucidło [@ptkdev] (https://ptk.dev) * * @license: CC BY 4.0 License * */ module.exports = { INFO: " | INFORMACJA ", WARNING: " | UWAGA ", ERROR: " | BŁĄD ", DEBUG: " | DEBUG ", DOCS: " | DOKUMENTACJA ", STACKOVERFLOW: " | STACKOVERFLOW ", SPONSOR: " | SPONSOR " }; ================================================ FILE: translations/pt.js ================================================ /** * Translation: Portuguese * ===================== * How translate: * Chalk: chalk is npm plugin to colorize text in terminal, example: {white.bold.bgRgb(46, 204, 113) TEXT_TEXT_TEXT } * don't translate white.bold.bgRgb but translate TEXT_TEXT_TEXT before of } * * Keys: don't translate keywords on left, example: {"done":"done"} * word on left side is keyword, ever in English. Translate only phrases on right side of two dots * * Param: don't translate words between ## ##, example: ##ciao## * * @contributors: Bruno Kummel [@Bruck1701] (https://github.com/Bruck1701) / Joel Emanoel [@joelemanoel] (https://github.com/joelemanoel) * * @license: CC BY 4.0 License * */ module.exports = { INFO: " | INFORMAÇÃO ", WARNING: " | AVISO ", ERROR: " | ERRO ", DEBUG: " | DEBUG ", DOCS: " | DOCUMENTAÇÃO ", STACKOVERFLOW: " | STACKOVERFLOW ", SPONSOR: " | PATROCINADOR " }; ================================================ FILE: translations/ru.js ================================================ /** * Translation: Portuguese * ===================== * How translate: * Chalk: chalk is npm plugin to colorize text in terminal, example: {white.bold.bgRgb(46, 204, 113) TEXT_TEXT_TEXT } * don't translate white.bold.bgRgb but translate TEXT_TEXT_TEXT before of } * * Keys: don't translate keywords on left, example: {"done":"done"} * word on left side is keyword, ever in English. Translate only phrases on right side of two dots * * Param: don't translate words between ## ##, example: ##ciao## * * @contributors: Alina Osv [@alinaosv] (https://github.com/alinaosv) * * @license: CC BY 4.0 License * */ module.exports = { INFO: " | ИНФОРМАЦИЯ ", WARNING: " | ПРЕДУПРЕЖДЕНИЕ ", ERROR: " | ОШИБКА ", DEBUG: " | ОТЛАДКА ", DOCS: " | ДОКУМЕНТАЦИЯ ", STACKOVERFLOW: " | STACKOVERFLOW ", SPONSOR: " | СПОНСОР " }; ================================================ FILE: tsconfig.json ================================================ { "compilerOptions": { "module": "commonjs", "lib": ["es6"], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true }, "files": ["modules/logger.d.ts"] }