sylog 1.0.0 → 2.1.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 CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var w=Object.create;var l=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var f=(s,t)=>{for(var e in t)l(s,e,{get:t[e],enumerable:!0})},c=(s,t,e,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of O(t))!m.call(s,o)&&o!==e&&l(s,o,{get:()=>t[o],enumerable:!(p=y(t,o))||p.enumerable});return s};var b=(s,t,e)=>(e=s!=null?w(S(s)):{},c(t||!s||!s.__esModule?l(e,"default",{value:s,enumerable:!0}):e,s)),v=s=>c(l({},"__esModule",{value:!0}),s);var E={};f(E,{Sylog:()=>n,default:()=>A,sylog:()=>a});module.exports=v(E);var r=b(require("ansilory"),1),n=class{opts;LEVEL_COLORS={log:t=>r.default.white.apply(t),info:t=>r.default.blue.bold.apply(t),warn:t=>r.default.yellow.bold.apply(t),error:t=>r.default.red.bold.apply(t),success:t=>r.default.green.bold.apply(t),debug:t=>r.default.cyan.bold.apply(t)};DEFAULT_OPTS={showTimeStamp:!1,timeStamp:"utc",showLevels:!0,levels:{log:null,info:"INFO",warn:"WARN",error:"ERROR",success:"SUCCESS",debug:"DEBUG"}};constructor(t){this.opts={...this.DEFAULT_OPTS,...t}}isLogOpts(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&("sep"in t||"end"in t)}write(t,e,...p){let o={sep:" ",end:`
2
- `};p.length&&this.isLogOpts(p[p.length-1])&&(o={...o,...p.pop()});let L=this.opts.showTimeStamp?r.default.gray.apply(`[${this.opts.timeStamp==="utc"?new Date().toISOString().replace("T"," ").slice(0,19):new Date().toLocaleString("sv-SE")}]`):"",u=p.map(i=>typeof i=="object"&&i!==null?JSON.stringify(i):String(i)).join(o.sep),g=this.opts.levels?.[e],d=g?this.LEVEL_COLORS[e](`[${g}]`):null,h=[this.opts.prefix&&r.default.gray.bold.apply(this.opts.prefix),L,this.opts.showLevels&&d,u].filter(Boolean).join(" ")+o.end;t.write(h)}log(...t){this.write(process.stdout,"log",...t)}info(...t){this.write(process.stdout,"info",...t)}warn(...t){this.write(process.stderr,"warn",...t)}error(...t){this.write(process.stderr,"error",...t)}success(...t){this.write(process.stdout,"success",...t)}debug(...t){this.write(process.stdout,"debug",...t)}},a=new n,A=a;0&&(module.exports={Sylog,sylog});
1
+ "use strict";var b=Object.create;var i=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var v=(t,s)=>{for(var e in s)i(t,e,{get:s[e],enumerable:!0})},u=(t,s,e,l)=>{if(s&&typeof s=="object"||typeof s=="function")for(let o of w(s))!S.call(t,o)&&o!==e&&i(t,o,{get:()=>s[o],enumerable:!(l=y(s,o))||l.enumerable});return t};var f=(t,s,e)=>(e=t!=null?b(O(t)):{},u(s||!t||!t.__esModule?i(e,"default",{value:t,enumerable:!0}):e,t)),m=t=>u(i({},"__esModule",{value:!0}),t);var E={};v(E,{Sylog:()=>n,default:()=>A,sylog:()=>a});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.gray.bold.apply(s),dryrun:s=>r.default.magenta.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",dryrun:"DRYRUN"}};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,e,...l){let o={sep:" ",end:`
2
+ `};l.length&&this.isLogOpts(l[l.length-1])&&(o={...o,...l.pop()});let d=this.opts.showTimeStamp?r.default.gray.apply(`[${this.opts.timeStamp==="utc"?new Date().toISOString().replace("T"," ").slice(0,19):new Date().toLocaleString("sv-SE")}]`):"",c=l.map(p=>typeof p=="object"&&p!==null?JSON.stringify(p):String(p)).join(o.sep),g=o.label??this.opts.levels?.[e],h=g?this.LEVEL_COLORS[e](`[${g}]`):null,L=[this.opts.prefix&&r.default.gray.bold.apply(this.opts.prefix),d,this.opts.showLevels&&h,c].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)}dryrun(...s){this.write(process.stdout,"dryrun",...s)}},a=new n,A=a;0&&(module.exports={Sylog,sylog});
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Log levels */
2
- type Levels = 'log' | 'info' | 'warn' | 'error' | 'success' | 'debug';
2
+ type Levels = 'log' | 'info' | 'warn' | 'error' | 'success' | 'debug' | 'dryrun';
3
3
  /**
4
4
  * - Arguments passed to log methods.
5
5
  * - Last argument can optionally be {@link LogOpts} to customize.
@@ -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,61 @@ 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
+ dryrun?: string | null | undefined;
159
+ };
77
160
  /**
78
161
  * Logs a general message
79
162
  *
@@ -128,6 +211,15 @@ declare class Sylog {
128
211
  * ```
129
212
  */
130
213
  debug(...args: LogArgs): void;
214
+ /**
215
+ * Logs a dry-run message
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * sylog.dryrun('Dry run mode enabled');
220
+ * ```
221
+ */
222
+ dryrun(...args: LogArgs): void;
131
223
  }
132
224
  /**
133
225
  * Default singleton
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Log levels */
2
- type Levels = 'log' | 'info' | 'warn' | 'error' | 'success' | 'debug';
2
+ type Levels = 'log' | 'info' | 'warn' | 'error' | 'success' | 'debug' | 'dryrun';
3
3
  /**
4
4
  * - Arguments passed to log methods.
5
5
  * - Last argument can optionally be {@link LogOpts} to customize.
@@ -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,61 @@ 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
+ dryrun?: string | null | undefined;
159
+ };
77
160
  /**
78
161
  * Logs a general message
79
162
  *
@@ -128,6 +211,15 @@ declare class Sylog {
128
211
  * ```
129
212
  */
130
213
  debug(...args: LogArgs): void;
214
+ /**
215
+ * Logs a dry-run message
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * sylog.dryrun('Dry run mode enabled');
220
+ * ```
221
+ */
222
+ dryrun(...args: LogArgs): void;
131
223
  }
132
224
  /**
133
225
  * Default singleton
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import s from"ansilory";var p=class{opts;LEVEL_COLORS={log:t=>s.white.apply(t),info:t=>s.blue.bold.apply(t),warn:t=>s.yellow.bold.apply(t),error:t=>s.red.bold.apply(t),success:t=>s.green.bold.apply(t),debug:t=>s.cyan.bold.apply(t)};DEFAULT_OPTS={showTimeStamp:!1,timeStamp:"utc",showLevels:!0,levels:{log:null,info:"INFO",warn:"WARN",error:"ERROR",success:"SUCCESS",debug:"DEBUG"}};constructor(t){this.opts={...this.DEFAULT_OPTS,...t}}isLogOpts(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&("sep"in t||"end"in t)}write(t,i,...e){let o={sep:" ",end:`
2
- `};e.length&&this.isLogOpts(e[e.length-1])&&(o={...o,...e.pop()});let n=this.opts.showTimeStamp?s.gray.apply(`[${this.opts.timeStamp==="utc"?new Date().toISOString().replace("T"," ").slice(0,19):new Date().toLocaleString("sv-SE")}]`):"",g=e.map(r=>typeof r=="object"&&r!==null?JSON.stringify(r):String(r)).join(o.sep),l=this.opts.levels?.[i],c=l?this.LEVEL_COLORS[i](`[${l}]`):null,a=[this.opts.prefix&&s.gray.bold.apply(this.opts.prefix),n,this.opts.showLevels&&c,g].filter(Boolean).join(" ")+o.end;t.write(a)}log(...t){this.write(process.stdout,"log",...t)}info(...t){this.write(process.stdout,"info",...t)}warn(...t){this.write(process.stderr,"warn",...t)}error(...t){this.write(process.stderr,"error",...t)}success(...t){this.write(process.stdout,"success",...t)}debug(...t){this.write(process.stdout,"debug",...t)}},L=new p,h=L;export{p as Sylog,h as default,L as sylog};
1
+ import t from"ansilory";var l=class{opts;LEVEL_COLORS={log:s=>t.white.apply(s),info:s=>t.blue.bold.apply(s),warn:s=>t.yellow.bold.apply(s),error:s=>t.red.bold.apply(s),success:s=>t.green.bold.apply(s),debug:s=>t.gray.bold.apply(s),dryrun:s=>t.magenta.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",dryrun:"DRYRUN"}};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,...e){let o={sep:" ",end:`
2
+ `};e.length&&this.isLogOpts(e[e.length-1])&&(o={...o,...e.pop()});let n=this.opts.showTimeStamp?t.gray.apply(`[${this.opts.timeStamp==="utc"?new Date().toISOString().replace("T"," ").slice(0,19):new Date().toLocaleString("sv-SE")}]`):"",g=e.map(r=>typeof r=="object"&&r!==null?JSON.stringify(r):String(r)).join(o.sep),i=o.label??this.opts.levels?.[p],u=i?this.LEVEL_COLORS[p](`[${i}]`):null,a=[this.opts.prefix&&t.gray.bold.apply(this.opts.prefix),n,this.opts.showLevels&&u,g].filter(Boolean).join(" ")+o.end;s.write(a)}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)}dryrun(...s){this.write(process.stdout,"dryrun",...s)}},d=new l,L=d;export{l as Sylog,L as default,d as sylog};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sylog",
3
3
  "displayName": "Sylog",
4
- "version": "1.0.0",
4
+ "version": "2.1.0",
5
5
  "description": "Sync system logs terminal clarity file durability",
6
6
  "private": false,
7
7
  "repository": {