Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2.0.0-alpha.1: Customize Everything #4

Merged
merged 10 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build/**/*
build/**/*
*.js
26 changes: 16 additions & 10 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{
"rules": {
"@typescript-eslint/ban-ts-ignore": ["off"],
"@typescript-eslint/explicit-function-return-type": ["error"],
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/interface-name-prefix": ["off"],
"@typescript-eslint/no-explicit-any": ["off"],
"@typescript-eslint/no-unused-expressions": ["error"],
"@typescript-eslint/no-explicit-any": ["off", { "fixToUnknown": true, "ignoreRestArgs": true }],
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-var-requires": ["off"],
"@typescript-eslint/no-use-before-define": ["error"],
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-non-null-assertion": ["off"],
"@typescript-eslint/no-duplicate-enum-values": "off",
"array-bracket-spacing": ["warn", "never"],
"capIsNew": ["off"],
"comma-dangle": ["error", "always-multiline"],
"computed-property-spacing": "warn",
"deprecation/deprecation": "warn",
"default-case": ["error", { "commentPattern": "^no default$" }],
"eol-last": ["error", "always"],
"indent": ["warn", 2, {"SwitchCase": 1}],
Expand All @@ -25,7 +29,7 @@
"max-len": [
"warn",
{
"code": 180,
"code": 250,
"ignoreComments": true,
"ignoreUrls": true
}
Expand All @@ -40,7 +44,8 @@
"no-template-curly-in-string": "error",
"no-unsafe-negation": "error",
"no-undef": ["error"],
"no-unused-vars": 1,
"no-unused-vars": "off",
"no-unused-expressions": "off",
"no-empty": [
"error",
{
Expand All @@ -50,7 +55,7 @@
"no-console": "off",
"no-multi-spaces": "warn",
"no-use-before-define": [
2,
"off",
{
"functions": false,
"classes": false,
Expand Down Expand Up @@ -88,8 +93,9 @@
"globals": {},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.json" // <-- Point to your project's "tsconfig.json" or create a new one.
},
"plugins": ["prettier", "@typescript-eslint"]
"plugins": ["deprecation", "@typescript-eslint"]
}
Binary file modified .github/assets/LoggerExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 18 additions & 3 deletions .github/workflows/packagePublish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish API to NPM
name: Publish to NPM

on:
push:
Expand Down Expand Up @@ -45,8 +45,23 @@ jobs:
- name: Prepare to publish
run: npm run pdeploy

- name: Publish to npm
- name: Publish to npm (alpha)
if: ${{ contains(steps.current_version.outputs.version, '-alpha') }}
working-directory: ./build
run: npm publish --access=public
run: npm publish --provenance --access=public --tag alpha
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish to npm (beta)
if: ${{ contains(steps.current_version.outputs.version, '-beta') }}
working-directory: ./build
run: npm publish --provenance --access=public --tag beta
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish to npm (latest)
if: ${{ !contains(steps.current_version.outputs.version, '-alpha') && !contains(steps.current_version.outputs.version, '-beta') }}
working-directory: ./build
run: npm publish --provenance --access=public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ dist

# Typescript compiled files
build/
.directory
7 changes: 0 additions & 7 deletions .prettierignore

This file was deleted.

6 changes: 0 additions & 6 deletions .prettierrc.json

This file was deleted.

36 changes: 35 additions & 1 deletion CHANGELOG.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
# v2.0.0-ALPHA.1: Customize Everything (patch)
- [BACKWARDS COMPATIBILITY] Automatically register the console engine if no engine is provided and you try to log something.

- [NEW] Strings with highlightable words separated by `/` and `\` will be highlighted.

# v2.0.0-ALPHA.0: Customize Everything
- [BREAKING] Full rewrite of the constructor and the way the logger works, logging methods however remain the same.

- [BREAKING] Removed the `fileProperties` parameter from the constructor, use instead new FileStorageEngine class for file logging.

- [BREAKING] Removed the ability to log using html format.

- [BREAKING] `logFolderPath` is now a required parameter for the FileStorageEngine class and will throw an error if not provided.

- [BREAKING] Removed automatic terminal logging, use the new ConsoleEngine class for terminal logging.

- [BREAKING] AutoLogEnd is now a singleton class that should be instantiated apart from the Logger class.

- [NEW] Added support for string substitution patterns.

- [NEW] Added support for multiple loggers with different configurations to log to the same Engine.

- [NEW] Added support for a logger to output to multiple engines of same or different kind.

- [NEW] Added coloring to primitive types and certain keywords.

- [NEW] Added the ability to a logger to use different color settings, including custom ones.

- [NEW] Added support custom single, multi, or dynamic colored backgrounds and text colors for prefixes.

- [NEW] Added support for template literals to the logging.

- [NEW] AutoLogEnd now has the capacity of running deconstructor functions on application exit.

# v1.1.1: Saving Everything (patch)
- [FIXED] Fixed a bug that caused logs that passed arguments to log the same thing twice

Expand Down Expand Up @@ -36,7 +70,7 @@

- [NEW] Added support to log objects, arrays and etc. Like the default `console.log` function.

- [BREAKING] Changed the export of AutoLogEnd now importing the package will return the `Logger` class and a object named `AutoLogEnd` with the `activate` and `deactivate` functions.
- [BREAKING] Changed the export of AutoLogEnd. Now, importing the package will return the `Logger` class and a object named `AutoLogEnd` with the `activate` and `deactivate` functions.

- [NEW] AutoLogEnd `activate` function now accepts a `Logger` instance as 2º parameter. If not passed it will create a new instance of `Logger` with the default parameters. otherwise it will use the passed instance.

Expand Down
73 changes: 48 additions & 25 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
#

<h2 align="center">📖 About</h2>
&nbsp;&nbsp;&nbsp;&nbsp;This is a simple logger for NodeJS, made in TypeScript, with the objective of make beautiful and easy to read logs.
&nbsp;&nbsp;&nbsp;&nbsp;A simple to use but powerful logger library for NodeJS, made with TypeScript, capable of making beautiful and well organized logs automagically.

<br>

&nbsp;&nbsp;&nbsp;&nbsp;Originally made for [twitch.js](https://github.com/PromisePending/twitch.js), we decided to make it in a separate package, so that it can be used in other projects without the need to install the entire twitch.js package or copy and maintain the code.
&nbsp;&nbsp;&nbsp;&nbsp;Originally a small util for [twitch.js](https://github.com/PromisePending/twitch.js), Logger.js quickly expanded to other projects and started gaining more features, and now it stands as a standalone package to be used by anyone.

<br>

<h2 align="center">📦 Installing</h2>
&nbsp;&nbsp;&nbsp;&nbsp;To install Logger.JS in your project, you need first to have NodeJS installed, then run the following command in your terminal:
&nbsp;&nbsp;&nbsp;&nbsp;To install Logger.JS in your project, you need first to have NodeJS installed (version 20 is recommended), then use the following command to install Logger.js as a dependency on your project:

<br>

Expand All @@ -45,38 +45,61 @@ yarn add @promisepending/logger.js

<br>

<h2 align="center">⌨ Use example</h2>
&nbsp;&nbsp;&nbsp;&nbsp;To use Logger.JS in your project, you need to import the logger class, then create an instance of that class, passing as parameter your logger configurations as an object, or nothing if you want to use the default configurations.
<h2 align="center">⌨ Usage example</h2>
&nbsp;&nbsp;&nbsp;&nbsp;To use Logger.JS in your project, first import the Logger Class as well as the Engines that you will be using, then create instances of those classes, passing as parameter your configurations as an object.

<br>

The instanciation order doesn't matter since both the Logger class as well as the Engine classes provide methods to dynamically add or remove connections.

<br>

```js
const { Logger } = require('@promisepending/logger.js');
// or
import { Logger } from '@promisepending/logger.js';
import { Logger, ConsoleEngine } from '@promisepending/logger.js';

const logger = new Logger({
prefix: 'Logger.JS', // This will be the prefix of all logs (default: null)
disableFatalCrash: true, // If true, the logger will not crash the process when a fatal error occurs (default: false)
allLineColored: true, // If true, the whole line will be colored instead of only the prefix (default: false)
coloredBackground: false, // If true, the background of the lines will be colored instead of the text (default: false)
debug: false, // If true, the logger will log debug messages (default: false)
fileProperties: { // This is the configuration of the log files
enable: true, // If true, the logger will log to files (default: false) [NOTE: If false all below options will be ignored]
logFolderPath: './logs', // This is the path of the folder where the log files will be saved (default: './logs')
enableLatestLog: true, // If true, the logger will save the latest log in a file (default: true)
enableDebugLog: true, // If true, the logger will save the debug logs in a file (default: false)
enableErrorLog: true, // If true, the logger will save the error logs in a file (default: false)
enableFatalLog: true, // If true, the logger will save the fatal logs in a file (default: true)
generateHTMLLog: true, // If true, the logger will generate a HTML file with the logs otherwise a .log file (default: false)
compressLogFilesAfterNewExecution: true, // If true, the logger will compress the log files to zip after a new execution (default: true)
},
// Adds a basic string prefix
prefixes: ['Logger.JS',
// And a complex prefix
{
// Prefix text
content: 'This prefix has complex colors',
/* This function sets the color of the prefix text, the txt parameter is the content value and it must return a array whos size is equal to the amount of letters in the content value.
NOTE: color doesn't need to be a function, it can be a array, or a string! If it is an array then its size must match the amount of letters of the content value, however, if it is a string then the hex code will be used to paint the whole text */
color: (txt) => {
// In this example we set a list of hex colors and repeat it to match the amount of letters
const colors = ['#ff5555', '#55ff55', '#5555ff'];
return txt.split('').map((_, i) => {
return colors[i % colors.length];
});
},
// Background color follows the same logic as color, it can be a function, an array or a string
backgroundColor: '#000033',
}
],
// Disables fatal crashing, so that fatal logs won't immediatly end the process
disableFatalCrash: true,
// Makes the message of the log also be colored
allLineColored: true,
});
```

<br>

&nbsp;&nbsp;&nbsp;&nbsp;After creating the logger instance, you can use the methods to log your messages, as shown below:
Then either before or after the Logger instanciation, instaciate the Engine(s).

```js
// Creates and registers a ConsoleEngine, all logs will now be displayed on the terminal
logger.registerListener(new ConsoleEngine({
debug: true,
}));
```

Note that we are using `logger.registerListener` however it is possible to just pass `logger` as a second parameter in the constructor of `ConsoleEngine`, but also call the `registerLogger` method of the Engine allowing you to create the Engine before the logger, or even dynamically add loggers to the Engine.

<br>

You can use the methods of the `logger` object we just create to log your messages, as shown below:

<br>

Expand All @@ -90,7 +113,7 @@ logger.fatal('This is a fatal message');

### Results:

<img alt="The result of the above logs in a windows command prompt" src="https://raw.githubusercontent.com/PromisePending/logger.js/release/.github/assets/LoggerExample.png">
<img alt="The result of the above logs in a Konsole terminal" src="https://raw.githubusercontent.com/PromisePending/logger.js/release/.github/assets/LoggerExample.png">

<br>

Expand Down
Loading