Skip to content

Commit b9b14c4

Browse files
committed
v1.0.0
Initial release
0 parents  commit b9b14c4

14 files changed

Lines changed: 1562 additions & 0 deletions

.eslintrc.json

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"root": true,
3+
"env": {
4+
"browser": true,
5+
"commonjs": true,
6+
"es2021": true,
7+
"node": true
8+
},
9+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
10+
"parser": "@typescript-eslint/parser",
11+
"parserOptions": {
12+
"ecmaVersion": 12
13+
},
14+
"plugins": ["@typescript-eslint"],
15+
"rules": {
16+
"@typescript-eslint/naming-convention": [
17+
"warn",
18+
{
19+
"selector": "function",
20+
"format": ["camelCase"]
21+
}
22+
],
23+
"@typescript-eslint/no-unused-vars": "off",
24+
"@typescript-eslint/semi": "warn",
25+
"getter-return": "warn",
26+
"no-dupe-args": "warn",
27+
"no-dupe-else-if": "warn",
28+
"no-dupe-keys": "warn",
29+
"no-duplicate-case": "warn",
30+
"no-empty": "warn",
31+
"accessor-pairs": "warn",
32+
"array-callback-return": "warn",
33+
"block-scoped-var": "warn",
34+
"class-methods-use-this": "off",
35+
"complexity": "warn",
36+
"consistent-return": "warn",
37+
"curly": "warn",
38+
"default-case": "warn",
39+
"default-case-last": "warn",
40+
"default-param-last": "warn",
41+
"dot-location": "off",
42+
"dot-notation": "warn",
43+
"eqeqeq": "warn",
44+
"grouped-accessor-pairs": "warn",
45+
"guard-for-in": "off",
46+
"max-classes-per-file": ["warn", 2],
47+
"no-alert": "warn",
48+
"no-caller": "warn",
49+
"no-case-declarations": "off",
50+
"no-constructor-return": "warn",
51+
"no-div-regex": "warn",
52+
"no-else-return": "warn",
53+
"no-empty-function": "warn",
54+
"no-empty-pattern": "warn",
55+
"no-eq-null": "warn",
56+
"no-eval": "warn",
57+
"no-extend-native": "off",
58+
"no-extra-bind": "warn",
59+
"no-extra-label": "warn",
60+
"no-fallthrough": "warn",
61+
"no-floating-decimal": "warn",
62+
"no-global-assign": "warn",
63+
"no-implicit-coercion": "warn",
64+
"no-implicit-globals": "warn",
65+
"no-implied-eval": "warn",
66+
"no-invalid-this": "off",
67+
"no-iterator": "warn",
68+
"no-labels": "warn",
69+
"no-lone-blocks": "warn",
70+
"no-loop-func": "warn",
71+
"no-magic-numbers": "off",
72+
"no-mixed-spaces-and-tabs": [ "warn", "smart-tabs" ],
73+
"no-multi-spaces": "warn",
74+
"no-multi-str": "warn",
75+
"no-new": "warn",
76+
"no-new-func": "warn",
77+
"no-new-wrappers": "warn",
78+
"no-octal": "warn",
79+
"no-octal-escape": "warn",
80+
"no-param-reassign": "warn",
81+
"no-proto": "warn",
82+
"no-redeclare": "off",
83+
"no-restricted-properties": "warn",
84+
"no-return-assign": "warn",
85+
"no-return-await": "warn",
86+
"no-script-url": "warn",
87+
"no-self-assign": "warn",
88+
"no-self-compare": "warn",
89+
"no-sequences": "warn",
90+
"no-throw-literal": "warn",
91+
"no-unmodified-loop-condition": "warn",
92+
"no-unused-expressions": "warn",
93+
"no-unused-labels": "warn",
94+
"no-useless-call": "warn",
95+
"no-useless-catch": "warn",
96+
"no-useless-concat": "warn",
97+
"no-useless-escape": "warn",
98+
"no-useless-return": "warn",
99+
"no-void": "warn",
100+
"no-warning-comments": "warn",
101+
"no-with": "warn",
102+
"prefer-named-capture-group": "warn",
103+
"prefer-promise-reject-errors": "off",
104+
"prefer-regex-literals": "warn",
105+
"radix": "warn",
106+
"require-await": "warn",
107+
"require-unicode-regexp": "off",
108+
"vars-on-top": "warn",
109+
"wrap-iife": "warn"
110+
}
111+
}

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.github/FUNDING.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github: [TopMarksDevelopment]
2+
custom: ['https://www.paypal.com/donate?hosted_button_id=5UFB62RB4AWNL']

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Compiled project
2+
lib/
3+
4+
# Dependency directories
5+
node_modules/
6+
7+
# TypeScript cache
8+
*.tsbuildinfo
9+
10+
# Optional npm cache directory
11+
.npm
12+
13+
# Optional eslint cache
14+
.eslintcache

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"printWidth": 120,
3+
"trailingComma": "all",
4+
"singleQuote": true,
5+
"useTabs": true,
6+
"tabWidth": 4
7+
}

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!--
2+
Guiding Principles
3+
- Changelogs are for humans, not machines.
4+
- There should be an entry for every single version.
5+
- The same types of changes should be grouped.
6+
- Versions and sections should be linkable.
7+
- The latest version comes first.
8+
- The release date of each version is displayed.
9+
- Mention whether you follow Semantic Versioning.
10+
11+
Types of changes
12+
- Added for new features.
13+
- Changed for changes in existing functionality.
14+
- Deprecated for soon-to-be removed features.
15+
- Removed for now removed features.
16+
- Fixed for any bug fixes.
17+
- Security in case of vulnerabilities.
18+
- Breaking changes for break in new revision
19+
- Other for notable changes that do not
20+
-->
21+
22+
# Changelog
23+
24+
All notable changes to this project will be documented in this file.
25+
26+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
27+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
28+
29+
## [1.0.0] - 2022-05-12
30+
31+
**This was the first release**
32+
33+
[1.0.0]: https://github.com/topmarksdevelopment/Javascript.Logger/release/tag/v1.0.0

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Glenn
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# JavaScript Logger
2+
3+
A custom package to log steps/errors throughout your package. There is also a static field that you can use to serialize `catch` errors.
4+
5+
### Links
6+
- [Change log](./CHANGELOG.md)
7+
- [License (MIT)](./LICENSE)
8+
9+
## Usage
10+
11+
Import the package and create a class that extends the `JavascriptLogger` class.
12+
Then provide the body for the two functions and also the 'type' for the `extraDetails` argument (as shown below). _If you don't want a 'type' then just use `object`._
13+
14+
```TS
15+
interface ExtraInfo {
16+
error?: unknown
17+
}
18+
19+
class MyLogger extends JavascriptLogger<ExtraInfo> {
20+
logLevel = (): LogLevel => LogLevel.warn;
21+
22+
logIt = (logLevel: LogLevel, title: string, message?: string | string[], extraDetails: ExtraInfo): void => {
23+
// consume the information and do stuff
24+
};
25+
}
26+
27+
const logger = new MyLogger();
28+
29+
// Some code, somewhere
30+
function thisWillAlwaysWork() {
31+
try
32+
{
33+
throw new Error("Whoops, guess not!");
34+
}
35+
catch (err)
36+
{
37+
logger.logCritical(
38+
"0x100001 - Critical 1",
39+
[
40+
"Oh no, there was a critical error in my program!",
41+
"The hex above can assist in identifying the location"
42+
],
43+
{
44+
// Log the error, rather than use properties from it
45+
error: JSON.parse(JavascriptLogger.convertToJson(err))
46+
}
47+
)
48+
}
49+
}
50+
```
51+
52+
## Functions
53+
54+
### `logLevel`
55+
56+
This specifies the log level to start outputting the messages
57+
58+
**Arguments:** _NONE_
59+
**Output:** `LogLevel` (_`critical`, `error`, `warn`, `info`, `debug`, `trace`_)
60+
61+
### `logIt`
62+
63+
This is the function that is called when a log occurs that meets the minimum log level specified by `logLevel`
64+
65+
**Arguments:** logLevel: `LogLevel`, title: `string`, message?: `string | string[]`, extraDetails: `T`_(custom type)_
66+
**Output:** _NONE_
67+
68+
## Built in components
69+
70+
### `JavascriptLogger.convertToJson(object)`
71+
This built in function will convert an object to a JSON string. This feature exists primarily to help with outputting an `Error` (as shown above).
72+
73+
### `ConsoleJavascriptLogger`
74+
This built in class will output straight to the console. You set the log level with it's constructor (as shown below).
75+
76+
```TS
77+
var consoleLogger = new ConsoleJavascriptLogger(LogLevel.info);
78+
```
79+
80+
## Other ideas
81+
**Log to your server:** rather than JS errors being lost to the cosmos with no idea they're happening. Use the logger to send the data to your server! Just remember to secure the access point 😁
82+
83+
**Store the logs:** implement a storage solution that saves all the logs and only outputs certain instances. Then you can have a custom function/command that can process them all to your will at any point! Maybe in a plugin that you can include all the logs when the user wants to raise a GitHub issue 🤷‍♂️

0 commit comments

Comments
 (0)