Skip to content

Commit

Permalink
Merge rewrite to main (#4)
Browse files Browse the repository at this point in the history
* a

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* update the compiling to easier splitting

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* make types.ts to a type declaration

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* update biome to include Level as global variable

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* update typings

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* update imports

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* update enum comment

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* removing unnecessary comments

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* move types

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* finish moving types

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* add module support

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* get options ready

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* Added test

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* Update package.json

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* I wrote it wrong again

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* fix tests

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* type updates and fixing whitespace

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* FINALLY, DOCUMENTATION!!!!

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* small change

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* another small change, last one.

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* I was real sleepy and didnt change the example to match, fixed.

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* update package

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* add contributing

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* add a tiny bit to levels

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>

* add the files and web functions

---------

Signed-off-by: TinnyTerr <168141209+TinnyTerr@users.noreply.github.com>
  • Loading branch information
TinnyTerr authored Dec 9, 2024
1 parent 7c67233 commit b5c00e4
Show file tree
Hide file tree
Showing 14 changed files with 2,646 additions and 389 deletions.
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

0 comments on commit b5c00e4

Please sign in to comment.