smallog 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +60 -0
- package/index.js +39 -0
- package/package.json +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tim
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Node.js Hackathon Project
|
|
2
|
+
|
|
3
|
+
### Reason For Existence
|
|
4
|
+
Regular logging bores me. Stack traces in the terminal are long,
|
|
5
|
+
annoying and the dark grey colour is condescending.
|
|
6
|
+
I wanted to shorten the functions themselves so I can save miliseconds aswell.
|
|
7
|
+
This is just a basic wrapper.
|
|
8
|
+
|
|
9
|
+
### How To Install
|
|
10
|
+
Just run ```npm i smallog```
|
|
11
|
+
|
|
12
|
+
### How To Use
|
|
13
|
+
Put this at the top of your file
|
|
14
|
+
```javascript
|
|
15
|
+
const log = require('smallog');
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Instead of your regular
|
|
19
|
+
```javascript
|
|
20
|
+
console.log("Here is text" === 1);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use this instead
|
|
24
|
+
```javascript
|
|
25
|
+
log("here is text" === 1);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
For successes
|
|
29
|
+
```javascript
|
|
30
|
+
log.win("this will be green with a SUCCESS message to show you did the thing correctly!);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
For bad bigmad
|
|
34
|
+
```javascript
|
|
35
|
+
log.fail("this will be red with a FAIL message and a short two-line stack trace so your whole terminal doesn't clog up.");
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
And a contrived try/ catch
|
|
39
|
+
```javascript
|
|
40
|
+
// example failure in action
|
|
41
|
+
try {
|
|
42
|
+
a == 1 / 0;
|
|
43
|
+
log.win(a);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
log.fail(e);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
How about some grouping
|
|
50
|
+
```javascript
|
|
51
|
+
log("base");
|
|
52
|
+
log.nest("nested");
|
|
53
|
+
log("level 2");
|
|
54
|
+
log.nest("nested");
|
|
55
|
+
log("level 3");
|
|
56
|
+
log.nestEnd();
|
|
57
|
+
log.fail("Something went wrong");
|
|
58
|
+
log.nestEnd();
|
|
59
|
+
log.win("Back to base");
|
|
60
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Globals because I am evil
|
|
2
|
+
|
|
3
|
+
const blue = "\x1b[34m";
|
|
4
|
+
const green = "\x1b[32m";
|
|
5
|
+
const red = "\x1b[31m";
|
|
6
|
+
const magenta = "\x1b[95m";
|
|
7
|
+
|
|
8
|
+
// this is to shorten those lengthy stack traces
|
|
9
|
+
function shortStack() {
|
|
10
|
+
const stack = new Error().stack.split("\n");
|
|
11
|
+
return stack.slice(2, 4).join("\n");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Generic log function
|
|
15
|
+
function log(arg) {
|
|
16
|
+
return console.log(blue + arg);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Success function
|
|
20
|
+
log.win = function (arg) {
|
|
21
|
+
console.log(green + "[-- SUCCESS --] " + "\n" + arg);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// failure log function with short stack trace
|
|
25
|
+
log.fail = function (arg) {
|
|
26
|
+
const trace = shortStack();
|
|
27
|
+
console.error(red + "[-- FAIL --]" + "\n" + arg + "\n" + trace);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// log grouping if you're into that sort of thing
|
|
31
|
+
log.nest = function(arg) {
|
|
32
|
+
console.group(magenta + arg);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
log.nestEnd = function() {
|
|
36
|
+
console.groupEnd();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = log;
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "smallog",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Minimal console formatter",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"start": "node index.js"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/tim-maastricht/nodejs-hackathon-project.git"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"type": "commonjs",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/tim-maastricht/nodejs-hackathon-project/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/tim-maastricht/nodejs-hackathon-project#readme"
|
|
22
|
+
}
|