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

Merge rewrite to main #4

Merged
merged 22 commits into from
Dec 9, 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
2 changes: 0 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
src
test


tsconfig.*
.prettierrc
7 changes: 0 additions & 7 deletions .prettierrc

This file was deleted.

5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Contributing

Feel free to contribute by reporting errors, adding using PRs or reviewing PRs. Please keep it sensible within PR's, we allow jokes and minimal bad language but over the top will be regulated.

However, as always, thanks for contributing!
213 changes: 211 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,213 @@
# CONTRIBUTERS REQUESTED

For anyone interested with supporting this passion project, please check out [Contributing](CONTRIBUTING.md).

# Logmatic

Welcome to logmatic.
Currently, docs are not available and are getting written at the moment. For the time being, use the [tests](./test/es6.mjs) for reference on usage.
An overly complicated yet functional logger.

## Installation

For all systems, please use:
```bash
npm i logmatic --save-exact
```
As logmatic is currently in a very unstable state, many items may change in the future.

## Usage

To get started, import the project into your file and initialise the logger:

```javascript
const { Logger } = require('logmatic');
// OR
// import { Logger } from 'logmatic';

const log = new Logger("name");
```

For the default added levels, use the following:

| Function Call | Format | Colour |
|----|----|----|
|`log.trace()`|`{time} [trace] {name} {...data}`|Cyan|
|`log.debug()`|`{time} [debug] {name} {...data}`|Blue Background|
|`log.info()`|`{time} [info] {name} {...data}`|Blue|
|`log.warn()`|`{time} [warn] {name} {...data}`|Yellow|
|`log.error()`|`{time} [error] {name} {...data}`|Red|
|`log.fatal()`|`{time} [fatal] {name} {...data}`|Red Background|

For your custom levels, please see [Levels](#levels) below

## Options

The following section is expecting you have imported the class. It will then demonstrate how to set the option.

### Console
---
#### Enabled

Whether console logging is enabled

Default: `true`

```javascript
const log = new Logger("name", { console: { enabled: true }})
```
---
#### Log Level

The minimum level to log. This corresponds with the position in the array the level is. See [Levels](#levels).

Default: `1`

```javascript
const log = new Logger("name", { console: { logLevel: 1 }})
```
---
#### Suppress Warnings

Whether to suppress warnings or errors emitted by the logger

Default: `false`

**WARNING:** This option is currently not in use.

```javascript
const log = new Logger("name", { console: { supressWarnings: false }})
```
---
#### Format

Whether to format and colourise any JSON output

Default: `false`

```javascript
const log = new Logger("name", { console: { format: false }})
```
---
#### Indent

Whether to indent any JSON output

Default: `0`

```javascript
const log = new Logger("name", { console: { indent: 0 }})
```
---
### Files

**WARNING:** This option is currently not in use.
*Note:* This module requires that several options are filled in tandem.
---
#### Enabled

Whether file logging is enabled

Default: `false`

```javascript
const log = new Logger("name", { files: { enabled: false }})
```
---
#### Path

The log directory

In-depth: if path = `/path/to/dir/` then logs will be stored as `/path/to/dir/log.txt` etc.

Default `null`

```javascript
const log = new Logger("name", { files: { path: null }})
```
---
#### Naming

How to name the files

Default: `null`

**WARNING:** No example for this option as it is undetermined how it will be parsed.
---
#### File type

The type of file stored

Default: `json`

```javascript
const log = new Logger("name", { files: { type: "json" }})
```
---
### Web
#### Enabled

Whether web (POST) logging is enabled

Default: `false`

```javascript
const log = new Logger("name", { web: { enabled: false }})
```
---
#### URL

The URL to post to

Default: `null`

```javascript
const log = new Logger("name", { web: { url: null }})
```
---
#### Data Type

The data type sent

Default: `json`

```javascript
const log = new Logger("name", { web: { type: "json" }})
```
---
#### Every number

How many logs to store before POSTing to avoid getting ratelimited

Default: `5`

```javascript
const log = new Logger("name", { web: { every: 5 }})
```

---
### Levels

This logger allows you to add your own levels, following out format. Formatted the following:
```javascript
const log = new Logger("name", { levels: { name: "level", colour:"red" }})
// **OR**
const log = new Logger("name", { levels: [{ name: "level", colour:"red" }]})
```

The colour should be derived from the package [console-log-colors](https://www.npmjs.com/package/console-log-colors) or from a slimmed list included in the types.

Also, you are able to overwrite existing functions. For example, you could overwrite the info logger level by redefining it.
---
### Functions

The logger allows you to pass custom functions or callbacks to handle the logs on your own.

```javascript
const function = (level: number, ...data: any[]) => {
return { level, data }
}

const log = new Logger("name", { funcs: function});
// **OR**
const log = new Logger("name", { funcs: [function]});

```
103 changes: 103 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
"files": { "ignoreUnknown": false, "ignore": [] },
"formatter": {
"enabled": true,
"formatWithErrors": true,
"indentStyle": "space",
"indentWidth": 4,
"lineEnding": "lf",
"lineWidth": 80,
"attributePosition": "auto"
},
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"complexity": {
"noExtraBooleanCast": "error",
"noMultipleSpacesInRegularExpressionLiterals": "error",
"noUselessCatch": "error",
"noWith": "error"
},
"correctness": {
"noConstAssign": "error",
"noConstantCondition": "error",
"noEmptyCharacterClassInRegex": "error",
"noEmptyPattern": "error",
"noGlobalObjectCalls": "error",
"noInnerDeclarations": "error",
"noInvalidConstructorSuper": "error",
"noNewSymbol": "error",
"noNonoctalDecimalEscape": "error",
"noPrecisionLoss": "error",
"noSelfAssign": "error",
"noSetterReturn": "error",
"noSwitchDeclarations": "error",
"noUndeclaredVariables": "error",
"noUnreachable": "error",
"noUnreachableSuper": "error",
"noUnsafeFinally": "error",
"noUnsafeOptionalChaining": "error",
"noUnusedLabels": "error",
"noUnusedVariables": "error",
"useIsNan": "error",
"useValidForDirection": "error",
"useYield": "error"
},
"style": {
"noVar": "error",
"useBlockStatements": "error",
"useCollapsedElseIf": "error",
"useConst": "error",
"useNamingConvention": "off"
},
"suspicious": {
"noAssignInExpressions": "error",
"noAsyncPromiseExecutor": "error",
"noCatchAssign": "error",
"noClassAssign": "error",
"noCompareNegZero": "error",
"noControlCharactersInRegex": "error",
"noDebugger": "error",
"noDuplicateCase": "error",
"noDuplicateClassMembers": "error",
"noDuplicateObjectKeys": "error",
"noDuplicateParameters": "error",
"noEmptyBlockStatements": "error",
"noFallthroughSwitchClause": "error",
"noFunctionAssign": "error",
"noGlobalAssign": "error",
"noImportAssign": "error",
"noMisleadingCharacterClass": "error",
"noPrototypeBuiltins": "error",
"noRedeclare": "error",
"noShadowRestrictedNames": "error",
"noSparseArray": "error",
"noUnsafeNegation": "error",
"useGetterReturn": "error",
"useValidTypeof": "error"
}
},
"ignore": ["dist/*"]
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto",
"bracketSpacing": true,
"indentStyle": "tab",
"lineEnding": "lf",
"indentWidth": 4
},
"globals": ["Level"]
}
}
Loading