sylog 1.0.0 → 2.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/dist/index.cjs +2 -2
- package/dist/index.d.cts +82 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`};
|
|
1
|
+
"use strict";var b=Object.create;var i=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var v=(e,s)=>{for(var t in s)i(e,t,{get:s[t],enumerable:!0})},a=(e,s,t,l)=>{if(s&&typeof s=="object"||typeof s=="function")for(let o of y(s))!S.call(e,o)&&o!==t&&i(e,o,{get:()=>s[o],enumerable:!(l=w(s,o))||l.enumerable});return e};var f=(e,s,t)=>(t=e!=null?b(O(e)):{},a(s||!e||!e.__esModule?i(t,"default",{value:e,enumerable:!0}):t,e)),m=e=>a(i({},"__esModule",{value:!0}),e);var E={};v(E,{Sylog:()=>n,default:()=>A,sylog:()=>u});module.exports=m(E);var r=f(require("ansilory"),1),n=class{opts;LEVEL_COLORS={log:s=>r.default.white.apply(s),info:s=>r.default.blue.bold.apply(s),warn:s=>r.default.yellow.bold.apply(s),error:s=>r.default.red.bold.apply(s),success:s=>r.default.green.bold.apply(s),debug:s=>r.default.cyan.bold.apply(s)};DEFAULT_OPTS={showTimeStamp:!1,timeStamp:"utc",showLevels:!0,debug:!1,levels:{log:null,info:"INFO",warn:"WARN",error:"ERROR",success:"SUCCESS",debug:"DEBUG"}};constructor(s){this.opts={...this.DEFAULT_OPTS,...s}}isLogOpts(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)&&("sep"in s||"end"in s||"label"in s)}write(s,t,...l){let o={sep:" ",end:`
|
|
2
|
+
`};l.length&&this.isLogOpts(l[l.length-1])&&(o={...o,...l.pop()});let c=this.opts.showTimeStamp?r.default.gray.apply(`[${this.opts.timeStamp==="utc"?new Date().toISOString().replace("T"," ").slice(0,19):new Date().toLocaleString("sv-SE")}]`):"",d=l.map(p=>typeof p=="object"&&p!==null?JSON.stringify(p):String(p)).join(o.sep),g=o.label??this.opts.levels?.[t],h=g?this.LEVEL_COLORS[t](`[${g}]`):null,L=[this.opts.prefix&&r.default.gray.bold.apply(this.opts.prefix),c,this.opts.showLevels&&h,d].filter(Boolean).join(" ")+o.end;s.write(L)}enableDebug(){this.opts.debug=!0}disableDebug(){this.opts.debug=!1}isDebugEnabled(){return!!this.opts.debug}setLevels(s){this.opts.levels={...this.opts.levels,...s}}getLevels(){return{...this.opts.levels}}log(...s){this.write(process.stdout,"log",...s)}info(...s){this.write(process.stdout,"info",...s)}warn(...s){this.write(process.stderr,"warn",...s)}error(...s){this.write(process.stderr,"error",...s)}success(...s){this.write(process.stdout,"success",...s)}debug(...s){this.opts.debug&&this.write(process.stdout,"debug",...s)}},u=new n,A=u;0&&(module.exports={Sylog,sylog});
|
package/dist/index.d.cts
CHANGED
|
@@ -31,6 +31,12 @@ interface SylogOpts {
|
|
|
31
31
|
showLevels?: boolean;
|
|
32
32
|
/** Custom names for each level or null to hide */
|
|
33
33
|
levels?: Partial<Record<Levels, string | null>>;
|
|
34
|
+
/**
|
|
35
|
+
* Enables debug output
|
|
36
|
+
*
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
debug?: boolean;
|
|
34
40
|
}
|
|
35
41
|
/** Options for a log call */
|
|
36
42
|
interface LogOpts {
|
|
@@ -46,6 +52,10 @@ interface LogOpts {
|
|
|
46
52
|
* @default "\n"
|
|
47
53
|
*/
|
|
48
54
|
end?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Override the default level label
|
|
57
|
+
*/
|
|
58
|
+
label?: string;
|
|
49
59
|
}
|
|
50
60
|
|
|
51
61
|
/**
|
|
@@ -63,6 +73,24 @@ interface LogOpts {
|
|
|
63
73
|
* logger.success('Task completed successfully');
|
|
64
74
|
* logger.debug('Debug info', { foo: 'bar' });
|
|
65
75
|
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { sylog } from 'sylog';
|
|
80
|
+
*
|
|
81
|
+
* sylog.info('Starting server...');
|
|
82
|
+
* sylog.success('Server started successfully!');
|
|
83
|
+
*
|
|
84
|
+
* // Enable debug logs
|
|
85
|
+
* sylog.enableDebug();
|
|
86
|
+
* sylog.debug('Debug mode active', { label: 'Trace' });
|
|
87
|
+
*
|
|
88
|
+
* // Customize global labels at runtime
|
|
89
|
+
* sylog.setLevels({ info: 'ℹ️', success: '✅', error: '❌' });
|
|
90
|
+
*
|
|
91
|
+
* // Per-call label override
|
|
92
|
+
* sylog.info('Startup complete', { label: 'Information' });
|
|
93
|
+
* ```
|
|
66
94
|
*/
|
|
67
95
|
declare class Sylog {
|
|
68
96
|
private opts;
|
|
@@ -74,6 +102,60 @@ declare class Sylog {
|
|
|
74
102
|
constructor(options?: SylogOpts);
|
|
75
103
|
private isLogOpts;
|
|
76
104
|
private write;
|
|
105
|
+
/**
|
|
106
|
+
* Enables debug mode.
|
|
107
|
+
*
|
|
108
|
+
* When enabled, `debug()` logs will be printed to the console.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* sylog.enableDebug();
|
|
113
|
+
* sylog.debug('Verbose details');
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
enableDebug(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Disables debug mode.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* sylog.disableDebug();
|
|
123
|
+
* sylog.debug('This will not print');
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
disableDebug(): void;
|
|
127
|
+
/**
|
|
128
|
+
* Returns whether debug mode is currently enabled.
|
|
129
|
+
*
|
|
130
|
+
* @returns `true` if debug mode is active.
|
|
131
|
+
*/
|
|
132
|
+
isDebugEnabled(): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Updates log level labels globally at runtime.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* sylog.setLevels({ info: 'ℹ️ Info', success: '✅ Done' });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
setLevels(
|
|
142
|
+
/**
|
|
143
|
+
* A partial map of log levels and new label strings.
|
|
144
|
+
*/
|
|
145
|
+
levels: SylogOpts['levels']): void;
|
|
146
|
+
/**
|
|
147
|
+
* Returns the current log level label configuration.
|
|
148
|
+
*
|
|
149
|
+
* @returns A copy of the internal levels map.
|
|
150
|
+
*/
|
|
151
|
+
getLevels(): {
|
|
152
|
+
log?: string | null | undefined;
|
|
153
|
+
info?: string | null | undefined;
|
|
154
|
+
warn?: string | null | undefined;
|
|
155
|
+
error?: string | null | undefined;
|
|
156
|
+
success?: string | null | undefined;
|
|
157
|
+
debug?: string | null | undefined;
|
|
158
|
+
};
|
|
77
159
|
/**
|
|
78
160
|
* Logs a general message
|
|
79
161
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,12 @@ interface SylogOpts {
|
|
|
31
31
|
showLevels?: boolean;
|
|
32
32
|
/** Custom names for each level or null to hide */
|
|
33
33
|
levels?: Partial<Record<Levels, string | null>>;
|
|
34
|
+
/**
|
|
35
|
+
* Enables debug output
|
|
36
|
+
*
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
debug?: boolean;
|
|
34
40
|
}
|
|
35
41
|
/** Options for a log call */
|
|
36
42
|
interface LogOpts {
|
|
@@ -46,6 +52,10 @@ interface LogOpts {
|
|
|
46
52
|
* @default "\n"
|
|
47
53
|
*/
|
|
48
54
|
end?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Override the default level label
|
|
57
|
+
*/
|
|
58
|
+
label?: string;
|
|
49
59
|
}
|
|
50
60
|
|
|
51
61
|
/**
|
|
@@ -63,6 +73,24 @@ interface LogOpts {
|
|
|
63
73
|
* logger.success('Task completed successfully');
|
|
64
74
|
* logger.debug('Debug info', { foo: 'bar' });
|
|
65
75
|
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { sylog } from 'sylog';
|
|
80
|
+
*
|
|
81
|
+
* sylog.info('Starting server...');
|
|
82
|
+
* sylog.success('Server started successfully!');
|
|
83
|
+
*
|
|
84
|
+
* // Enable debug logs
|
|
85
|
+
* sylog.enableDebug();
|
|
86
|
+
* sylog.debug('Debug mode active', { label: 'Trace' });
|
|
87
|
+
*
|
|
88
|
+
* // Customize global labels at runtime
|
|
89
|
+
* sylog.setLevels({ info: 'ℹ️', success: '✅', error: '❌' });
|
|
90
|
+
*
|
|
91
|
+
* // Per-call label override
|
|
92
|
+
* sylog.info('Startup complete', { label: 'Information' });
|
|
93
|
+
* ```
|
|
66
94
|
*/
|
|
67
95
|
declare class Sylog {
|
|
68
96
|
private opts;
|
|
@@ -74,6 +102,60 @@ declare class Sylog {
|
|
|
74
102
|
constructor(options?: SylogOpts);
|
|
75
103
|
private isLogOpts;
|
|
76
104
|
private write;
|
|
105
|
+
/**
|
|
106
|
+
* Enables debug mode.
|
|
107
|
+
*
|
|
108
|
+
* When enabled, `debug()` logs will be printed to the console.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* sylog.enableDebug();
|
|
113
|
+
* sylog.debug('Verbose details');
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
enableDebug(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Disables debug mode.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* sylog.disableDebug();
|
|
123
|
+
* sylog.debug('This will not print');
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
disableDebug(): void;
|
|
127
|
+
/**
|
|
128
|
+
* Returns whether debug mode is currently enabled.
|
|
129
|
+
*
|
|
130
|
+
* @returns `true` if debug mode is active.
|
|
131
|
+
*/
|
|
132
|
+
isDebugEnabled(): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Updates log level labels globally at runtime.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* sylog.setLevels({ info: 'ℹ️ Info', success: '✅ Done' });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
setLevels(
|
|
142
|
+
/**
|
|
143
|
+
* A partial map of log levels and new label strings.
|
|
144
|
+
*/
|
|
145
|
+
levels: SylogOpts['levels']): void;
|
|
146
|
+
/**
|
|
147
|
+
* Returns the current log level label configuration.
|
|
148
|
+
*
|
|
149
|
+
* @returns A copy of the internal levels map.
|
|
150
|
+
*/
|
|
151
|
+
getLevels(): {
|
|
152
|
+
log?: string | null | undefined;
|
|
153
|
+
info?: string | null | undefined;
|
|
154
|
+
warn?: string | null | undefined;
|
|
155
|
+
error?: string | null | undefined;
|
|
156
|
+
success?: string | null | undefined;
|
|
157
|
+
debug?: string | null | undefined;
|
|
158
|
+
};
|
|
77
159
|
/**
|
|
78
160
|
* Logs a general message
|
|
79
161
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
`};
|
|
1
|
+
import e from"ansilory";var l=class{opts;LEVEL_COLORS={log:s=>e.white.apply(s),info:s=>e.blue.bold.apply(s),warn:s=>e.yellow.bold.apply(s),error:s=>e.red.bold.apply(s),success:s=>e.green.bold.apply(s),debug:s=>e.cyan.bold.apply(s)};DEFAULT_OPTS={showTimeStamp:!1,timeStamp:"utc",showLevels:!0,debug:!1,levels:{log:null,info:"INFO",warn:"WARN",error:"ERROR",success:"SUCCESS",debug:"DEBUG"}};constructor(s){this.opts={...this.DEFAULT_OPTS,...s}}isLogOpts(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)&&("sep"in s||"end"in s||"label"in s)}write(s,p,...t){let o={sep:" ",end:`
|
|
2
|
+
`};t.length&&this.isLogOpts(t[t.length-1])&&(o={...o,...t.pop()});let n=this.opts.showTimeStamp?e.gray.apply(`[${this.opts.timeStamp==="utc"?new Date().toISOString().replace("T"," ").slice(0,19):new Date().toLocaleString("sv-SE")}]`):"",g=t.map(r=>typeof r=="object"&&r!==null?JSON.stringify(r):String(r)).join(o.sep),i=o.label??this.opts.levels?.[p],a=i?this.LEVEL_COLORS[p](`[${i}]`):null,u=[this.opts.prefix&&e.gray.bold.apply(this.opts.prefix),n,this.opts.showLevels&&a,g].filter(Boolean).join(" ")+o.end;s.write(u)}enableDebug(){this.opts.debug=!0}disableDebug(){this.opts.debug=!1}isDebugEnabled(){return!!this.opts.debug}setLevels(s){this.opts.levels={...this.opts.levels,...s}}getLevels(){return{...this.opts.levels}}log(...s){this.write(process.stdout,"log",...s)}info(...s){this.write(process.stdout,"info",...s)}warn(...s){this.write(process.stderr,"warn",...s)}error(...s){this.write(process.stderr,"error",...s)}success(...s){this.write(process.stdout,"success",...s)}debug(...s){this.opts.debug&&this.write(process.stdout,"debug",...s)}},c=new l,L=c;export{l as Sylog,L as default,c as sylog};
|