rslog 0.1.0 → 1.0.0-beta.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 +107 -0
- package/dist/es/index.js +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/types/index.d.ts +11 -6
- package/package.json +2 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
|
|
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
CHANGED
|
@@ -1 +1,108 @@
|
|
|
1
1
|
# Rslog
|
|
2
|
+
|
|
3
|
+
A tiny, intuitive, type-friendly logger for Node.js.
|
|
4
|
+
|
|
5
|
+
- **Tiny**. 1.5kB gzipped.
|
|
6
|
+
- **Clean**. Zero dependencies.
|
|
7
|
+
- **Intuitive**. Clear log prefix.
|
|
8
|
+
- **Type-friendly**. Written in TypeScript.
|
|
9
|
+
|
|
10
|
+
## Preview
|
|
11
|
+
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# with npm
|
|
18
|
+
npm add rslog
|
|
19
|
+
|
|
20
|
+
# with yarn
|
|
21
|
+
yarn add rslog
|
|
22
|
+
|
|
23
|
+
# with pnpm
|
|
24
|
+
pnpm add rslog
|
|
25
|
+
|
|
26
|
+
# with bun
|
|
27
|
+
bun add rslog
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
- Require:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
// with require
|
|
36
|
+
const { logger } = require('rslog');
|
|
37
|
+
|
|
38
|
+
// with import
|
|
39
|
+
import { logger } from 'rslog';
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- Log:
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
// A gradient welcome log
|
|
46
|
+
logger.greet(`\n➜ Rslog v1.0.0\n`);
|
|
47
|
+
|
|
48
|
+
// Info
|
|
49
|
+
logger.info('This is a info message');
|
|
50
|
+
|
|
51
|
+
// Start
|
|
52
|
+
logger.start('This is a start message');
|
|
53
|
+
|
|
54
|
+
// Warn
|
|
55
|
+
logger.warn('This is a warn message');
|
|
56
|
+
|
|
57
|
+
// Ready
|
|
58
|
+
logger.ready('This is a ready message');
|
|
59
|
+
|
|
60
|
+
// Success
|
|
61
|
+
logger.success('This is a success message');
|
|
62
|
+
|
|
63
|
+
// Error
|
|
64
|
+
logger.error('This is a error message');
|
|
65
|
+
logger.error(new Error('This is a error message with stack'));
|
|
66
|
+
|
|
67
|
+
// Debug
|
|
68
|
+
logger.debug('This is a debug message');
|
|
69
|
+
|
|
70
|
+
// Same as console.log
|
|
71
|
+
logger.log('This is a log message');
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Log Level
|
|
75
|
+
|
|
76
|
+
You can create a new logger instance through `createLogger` and specify the log level:
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
const { createLogger } = require('rslog');
|
|
80
|
+
|
|
81
|
+
const logger = createLogger({ level: 'warn' });
|
|
82
|
+
|
|
83
|
+
// Will print
|
|
84
|
+
logger.error('This is a error message');
|
|
85
|
+
logger.warn('This is a warn message');
|
|
86
|
+
|
|
87
|
+
// Will not print
|
|
88
|
+
logger.info('This is a info message');
|
|
89
|
+
logger.log('This is a log message');
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The log levels of each method are as follows:
|
|
93
|
+
|
|
94
|
+
| Level | Method |
|
|
95
|
+
| ------- | ----------------------------------- |
|
|
96
|
+
| error | `error` |
|
|
97
|
+
| warn | `warn` |
|
|
98
|
+
| info | `info`, `start`, `ready`, `success` |
|
|
99
|
+
| log | `log` |
|
|
100
|
+
| verbose | `debug` |
|
|
101
|
+
|
|
102
|
+
## Credits
|
|
103
|
+
|
|
104
|
+
The color implementation of Rslog are modified from [alexeyraspopov/picocolors](https://github.com/alexeyraspopov/picocolors).
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
Rslog is [MIT licensed](https://github.com/rspack-contrib/rslog/blob/main/LICENSE).
|
package/dist/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e
|
|
1
|
+
var e=/^\s*at\s.*:\d+:\d+[\s)]*$/,r=/^\s*at\s.*\(<anonymous>\)$/,{env:l}=process,o=!("NO_COLOR"in l)&&("FORCE_COLOR"in l||"win32"===process.platform||process.stdout.isTTY&&"dumb"!==l.TERM||"CI"in l),n=(e,r,l=e)=>o=>{let n=""+o,a=n.indexOf(r,e.length);return~a?e+t(n,r,l,a)+r:e+n+r},t=(e,r,l,o)=>{let n=e.substring(0,o)+l,a=e.substring(o+r.length),s=a.indexOf(r);return~s?n+t(a,r,l,s):n+a},a={bold:o?n("[1m","[22m","[22m[1m"):String,red:o?n("[31m","[39m"):String,green:o?n("[32m","[39m"):String,yellow:o?n("[33m","[39m"):String,magenta:o?n("[35m","[39m"):String,cyan:o?n("[36m","[39m"):String,gray:o?n("[90m","[39m"):String},s=[189,255,243],i=[74,194,154];var g={error:0,warn:1,info:2,log:3,verbose:4},c={error:{label:"error",level:"error",color:a.red},warn:{label:"warn",level:"warn",color:a.yellow},info:{label:"info",level:"info",color:a.cyan},start:{label:"start",level:"info",color:a.cyan},ready:{label:"ready",level:"info",color:a.green},success:{label:"success",level:"info",color:a.green},log:{level:"log"},debug:{label:"debug",level:"verbose",color:a.magenta}},m=(l={})=>{let n=l.level||"log",t=(l,o,...t)=>{if(g[c[l].level]>g[n])return;if(void 0===o||null===o)return void console.log();let s=c[l],i="";"label"in s&&(i=(s.label||"").padEnd(7),i=a.bold(s.color?s.color(i):i));let m="";if(o instanceof Error)if(o.stack){let[e,...r]=o.stack.split("\n");m=`${e.replace("Error: ","")}\n${a.gray(r.join("\n"))}`}else m=o.message;else if("error"===s.level&&"string"===typeof o){m=o.split("\n").map((l=>(l=>e.test(l)||r.test(l))(l)?a.gray(l):l)).join("\n")}else m=`${o}`;let d=i.length?`${i} ${m}`:m;console.log(d,...t)},m={greet:e=>t("log",function(e){if(!o)return e;let r=e.length,l=[(i[0]-s[0])/r,(i[1]-s[1])/r,(i[2]-s[2])/r],n="";for(let o=0;o<r;o++){let r="[0m";n+=`[38;2;${Math.round(s[0]+l[0]*o)};${Math.round(s[1]+l[1]*o)};${Math.round(s[2]+l[2]*o)}m${e[o]}${r}`}return n}(e))};return Object.keys(c).forEach((e=>{m[e]=(...r)=>t(e,...r)})),m},d=m();export{m as createLogger,d as logger};
|
package/dist/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,r
|
|
1
|
+
var e,r=Object.defineProperty,l=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,t=Object.prototype.hasOwnProperty,n={};((e,l)=>{for(var o in l)r(e,o,{get:l[o],enumerable:!0})})(n,{createLogger:()=>p,logger:()=>y}),module.exports=(e=n,((e,n,a,s)=>{if(n&&"object"===typeof n||"function"===typeof n)for(let i of o(n))t.call(e,i)||i===a||r(e,i,{get:()=>n[i],enumerable:!(s=l(n,i))||s.enumerable});return e})(r({},"__esModule",{value:!0}),e));var a=/^\s*at\s.*:\d+:\d+[\s)]*$/,s=/^\s*at\s.*\(<anonymous>\)$/,{env:i}=process,g=!("NO_COLOR"in i)&&("FORCE_COLOR"in i||"win32"===process.platform||process.stdout.isTTY&&"dumb"!==i.TERM||"CI"in i),c=(e,r,l=e)=>o=>{let t=""+o,n=t.indexOf(r,e.length);return~n?e+m(t,r,l,n)+r:e+t+r},m=(e,r,l,o)=>{let t=e.substring(0,o)+l,n=e.substring(o+r.length),a=n.indexOf(r);return~a?t+m(n,r,l,a):t+n},f={bold:g?c("[1m","[22m","[22m[1m"):String,red:g?c("[31m","[39m"):String,green:g?c("[32m","[39m"):String,yellow:g?c("[33m","[39m"):String,magenta:g?c("[35m","[39m"):String,cyan:g?c("[36m","[39m"):String,gray:g?c("[90m","[39m"):String},u=[189,255,243],b=[74,194,154];var d={error:0,warn:1,info:2,log:3,verbose:4},v={error:{label:"error",level:"error",color:f.red},warn:{label:"warn",level:"warn",color:f.yellow},info:{label:"info",level:"info",color:f.cyan},start:{label:"start",level:"info",color:f.cyan},ready:{label:"ready",level:"info",color:f.green},success:{label:"success",level:"info",color:f.green},log:{level:"log"},debug:{label:"debug",level:"verbose",color:f.magenta}},p=(e={})=>{let r=e.level||"log",l=(e,l,...o)=>{if(d[v[e].level]>d[r])return;if(void 0===l||null===l)return void console.log();let t=v[e],n="";"label"in t&&(n=(t.label||"").padEnd(7),n=f.bold(t.color?t.color(n):n));let i="";if(l instanceof Error)if(l.stack){let[e,...r]=l.stack.split("\n");i=`${e.replace("Error: ","")}\n${f.gray(r.join("\n"))}`}else i=l.message;else if("error"===t.level&&"string"===typeof l){i=l.split("\n").map((e=>(e=>a.test(e)||s.test(e))(e)?f.gray(e):e)).join("\n")}else i=`${l}`;let g=n.length?`${n} ${i}`:i;console.log(g,...o)},o={greet:e=>l("log",function(e){if(!g)return e;let r=e.length,l=[(b[0]-u[0])/r,(b[1]-u[1])/r,(b[2]-u[2])/r],o="";for(let t=0;t<r;t++){let r="[0m";o+=`[38;2;${Math.round(u[0]+l[0]*t)};${Math.round(u[1]+l[1]*t)};${Math.round(u[2]+l[2]*t)}m${e[t]}${r}`}return o}(e))};return Object.keys(v).forEach((e=>{o[e]=(...r)=>l(e,...r)})),o},y=p();
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
type
|
|
1
|
+
type ColorFn = (input: string | number | null | undefined) => string;
|
|
2
|
+
|
|
3
|
+
type LogLevel = 'error' | 'warn' | 'info' | 'log' | 'verbose';
|
|
2
4
|
type LogMessage = number | string | Error | null;
|
|
3
|
-
type LogFormatter = (input: string | number | null | undefined) => string;
|
|
4
5
|
interface LogType {
|
|
5
6
|
label?: string;
|
|
6
7
|
level: LogLevel;
|
|
7
|
-
|
|
8
|
+
color?: ColorFn;
|
|
8
9
|
}
|
|
9
10
|
type LogFunction = (message?: LogMessage, ...args: any[]) => void;
|
|
10
11
|
interface Options {
|
|
11
12
|
level?: LogLevel;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
declare
|
|
15
|
+
declare let createLogger: (options?: Options) => Record<"error" | "warn" | "info" | "log" | "start" | "ready" | "success" | "debug", LogFunction> & {
|
|
16
|
+
greet: (message: string) => void;
|
|
17
|
+
};
|
|
15
18
|
|
|
16
|
-
declare
|
|
19
|
+
declare let logger: Record<"error" | "warn" | "info" | "log" | "start" | "ready" | "success" | "debug", LogFunction> & {
|
|
20
|
+
greet: (message: string) => void;
|
|
21
|
+
};
|
|
17
22
|
|
|
18
|
-
export {
|
|
23
|
+
export { LogFunction, LogLevel, LogMessage, LogType, Options, createLogger, logger };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rslog",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
4
|
"types": "./dist/types/index.d.ts",
|
|
5
5
|
"main": "./dist/lib/index.js",
|
|
6
6
|
"module": "./dist/es/index.js",
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"@modern-js/tsconfig": "2.35.1",
|
|
15
15
|
"@types/jest": "~29.2.4",
|
|
16
16
|
"@types/node": "~16.11.7",
|
|
17
|
-
"picocolors": "^1.0.0",
|
|
18
17
|
"prettier": "~2.8.1",
|
|
19
18
|
"rimraf": "~3.0.2",
|
|
20
19
|
"typescript": "~5.0.4"
|
|
@@ -24,17 +23,11 @@
|
|
|
24
23
|
"registry": "https://registry.npmjs.org/"
|
|
25
24
|
},
|
|
26
25
|
"scripts": {
|
|
26
|
+
"preview": "node ./preview.js",
|
|
27
27
|
"dev": "modern dev",
|
|
28
28
|
"build": "modern build",
|
|
29
29
|
"build:watch": "modern build -w",
|
|
30
30
|
"reset": "rimraf ./**/node_modules",
|
|
31
|
-
"lint": "modern lint",
|
|
32
|
-
"change": "modern change",
|
|
33
|
-
"bump": "modern bump",
|
|
34
|
-
"pre": "modern pre",
|
|
35
|
-
"change-status": "modern change-status",
|
|
36
|
-
"gen-release-note": "modern gen-release-note",
|
|
37
|
-
"release": "modern release",
|
|
38
31
|
"new": "modern new",
|
|
39
32
|
"upgrade": "modern upgrade",
|
|
40
33
|
"test": "modern test"
|