-
Notifications
You must be signed in to change notification settings - Fork 0
/
logni.js
808 lines (673 loc) · 19.8 KB
/
logni.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
/*
* GNU General Public License v3.0
*
* Permissions of this strong copyleft license are conditioned on making
* available complete source code of licensed works and modifications,
* which include larger works using a licensed work, under the same license.
* Copyright and license notices must be preserved. Contributors provide
* an express grant of patent rights.
*
* see all: https://github.com/erikni/logni.js/blob/master/LICENSE
*/
/**
* @fileoverview logni is javascript library for event logging
* and application states
*
* <h3>Example:</h3>
* <pre>
* // initialization
* logni.debugMode = true;
* logni.mask("ALL");
* logni.stderr(1);
* logni.color(true);
* logni.file("https://yourweb/log");
* logni.env("local");
* logni.release("0.0.1");
* logni.name("testlog");
*
* // log message
* logni.debug("log debug test");
* logni.info("log info test" ,4);
* logni.warn("log warning test" ,3);
* logni.error("log error test");
* </pre>
*
* @version 0.2.3
* @author Erik Brozek - https://github.com/erikni
* @since 2017
* @static
* Website: https://logni.net
*/
// version
const version = '0.2.3';
// nodejs compatible mode
const Console = console;
// nodejs 6 compatible for console.debug
try {
Console.debug(`[logni.js] version=${version}`);
}
catch(err) {
Console.debug = function(msg) {
Console.log(`DEBUG: ${msg}`);
};
}
// nodejs cookies compatible
let cookies = `logni=${version}`;
try {
cookies = document.cookie;
}
catch(err) {
console.log(`[logni.js] cookie err="${err}"`);
}
// logni
const logni = new function() {
// debugMode is disabled
this.debugMode = false;
// error stack default string
this.__LOGniRelStr = "rel=0.0.0";
this.__LOGniEnvStr = "env=local";
this.__LOGniNameStr = "name=unknown";
this.__LOGniFile = "";
// colors: https://getbootstrap.com/docs/4.1/components/alerts/
this.__LOGniColors = {
primary: "#004085", // blue light
secondary:"#383d41", // seda
success: "#155724", // green light
danger: "#721c24", // ping light
warning: "#856404", // yellow light
info: "#0c5460", // blue-green light
light: "#818182", // svetle seda
dark: "#1b1e21", // tmave seda
};
// severity
this.__LOGniMaskSeverity = {};
this.__LOGniSeverityColors = {
DEBUG: "light",
INFO: "primary",
WARN: "warning",
ERROR: "danger" ,
CRITICAL: "danger",
};
// init
this.__init__ = function() {
Console.debug(`[logni.js] debugMode=${this.debugMode}`);
// severity (fullname)
this.__logMaskSeverityFull = ["DEBUG", "INFO", "WARN", "ERROR", "CRITICAL"];
this.__debug(`this.__logMaskSeverityFull=${this.__logMaskSeverityFull}`);
// severity (sortname)
this.__logMaskSeverityShort = [];
let i=0;
for (i = 0; i < this.__logMaskSeverityFull.length; i++) {
let _s = this.__logMaskSeverityFull[i].substring(0,1);
this.__logMaskSeverityShort[i] = _s;
this.__debug('severity fullName='
+ `${this.__logMaskSeverityFull[i]} -> shortName=${_s}`
);
this.__LOGniMaskSeverity[this.__logMaskSeverityShort[i]] = 5;
}
this.__debug(`this.__logMaskSeverityShort=${this.__logMaskSeverityShort}`);
this.__debug(`this.__LOGniMaskSeverity=${this.__LOGniMaskSeverity}`);
this.__debug(this.__LOGniMaskSeverity, false);
// default
this.mask("ALL");
this.stderr(1);
this.color(true);
return 1;
};
/**
* Set mask
*
* @param {string} LOGniMask,
* @static
*/
this.mask = function(LOGniMask) {
if (LOGniMask === undefined) LOGniMask="ALL";
// cookie mask
let cookieLOGniMask = this.cookieGet('LOGNI_MASK');
if (cookieLOGniMask) {
this.__debug(`set LOGniMask=${cookieLOGniMask}`);
LOGniMask = cookieLOGniMask;
}
// debug mask
this.__debug(`init logni.mask(${LOGniMask})`);
this.LOGniMask = LOGniMask;
// log mask = ALL
let i=0;
if (this.LOGniMask === "ALL") {
// set default LEVEL=1
for (i = 0; i < this.__logMaskSeverityShort.length; i++) {
this.__LOGniMaskSeverity[this.__logMaskSeverityShort[i]] = 1;
}
this.info(`[logni.js] init mask=${LOGniMask}`, 1);
return 0;
}
// len is wrong
const l = this.LOGniMask.length;
if (l < 2) {
return 1;
} else if (l > 10) {
return 1;
}
// set default LEVEL=0
for (i = 0; i < this.__logMaskSeverityShort.length; i++) {
this.__LOGniMaskSeverity[this.__logMaskSeverityShort[i]] = 5;
}
// set severity
for (i = 0; i < l; i += 2) {
let _l = this.LOGniMask.substring(i,i+1);
let _no= parseInt(this.LOGniMask.substring(i+1,i+2), 10);
this.__debug('mask='
+ `${this.LOGniMask} ${i}:${i+1} severity=${_l} priority=${_no}`
);
if(typeof this.__LOGniMaskSeverity[_l] === "undefined") {
this.__debug(`this.__LOGniMaskSeverity[${l}] is undefined`);
return 0;
} else {
this.__LOGniMaskSeverity[_l] = _no;
}
}
this.__debug(`set this.__LOGniMaskSeverity=${this.__LOGniMaskSeverity}`);
this.__debug(this.__LOGniMaskSeverity, false);
this.info(`[logni.js] init mask=${LOGniMask}`, 1);
return 0;
};
/**
* Set stderr
*
* @param {number} LOGniStderr,
* @static
*/
this.stderr = function(LOGniStderr) {
if (LOGniStderr === undefined) LOGniStderr=0;
// cookie stderr
let cookieLOGniStderr = this.cookieGet('LOGNI_STDERR');
if (cookieLOGniStderr) {
this.__debug(`set LOGniStderr=${cookieLOGniStderr}`);
LOGniStderr = cookieLOGniStderr;
}
// debug stderr
this.__debug(`init logni.stderr(${LOGniStderr})`);
this.LOGniStderr = LOGniStderr;
};
this.console = this.stderr;
/**
* Set file/url
*
* @param {string} LOGniFile,
* @static
*/
this.file = function(LOGniFile) {
if (LOGniFile === undefined) LOGniFile="";
// debug file/url
this.__debug(`init logni.file(${LOGniFile})`);
this.__LOGniFile = LOGniFile;
};
/**
* Set enviroment (dev|develop / stage / test / live|prod / ...)
*
* @param {string} LOGniEnv,
* @static
*/
this.enviroment = function(LOGniEnv) {
if (LOGniEnv === undefined) LOGniEnv="live";
// debug enviroment
this.__debug(`init logni.enviroment(${LOGniEnv})`);
this.__LOGniEnvStr = "env="+LOGniEnv;
this.info(`[logni.js] init enviroment=${LOGniEnv}`, 1);
};
this.env = this.enviroment;
/**
* Set application name
*
* @param {string} LOGniName,
* @static
*/
this.name = function(LOGniName) {
if (LOGniName === undefined) LOGniName="unknown";
// debug name
this.__debug(`init logni.name(${LOGniName})`);
this.LOGniName = LOGniName;
this.__LOGniNameStr = "name="+LOGniName;
this.info(`[logni.js] init name=${LOGniName}`, 1);
};
/**
* Set release version
*
* @param {string} LOGniRelease,
* @static
*/
this.release = function(LOGniRelease) {
if (LOGniRelease === undefined) LOGniRelease="0.0.0";
// debug release
this.__debug(`init logni.release(${LOGniRelease})`);
this.LOGniRelease = LOGniRelease;
this.__LOGniRelStr = "rel="+LOGniRelease;
this.info(`[logni.js] init release=${LOGniRelease}`, 1);
};
/**
* Set color for message logs
*
* @param {bool} LOGniColor,
* @static
*/
this.color = function(LOGniColor) {
if (LOGniColor === undefined) LOGniColor=true;
// cookie color
let cookieLOGniColor = this.cookieGet('LOGNI_COLOR');
if (cookieLOGniColor) {
this.__debug(`set LOGniColor=${cookieLOGniColor}`);
LOGniColor = cookieLOGniColor;
}
this.LOGniColor = LOGniColor;
this.__debug(`init color=${LOGniColor}`);
};
/**
* Use log?
*
* @param {string} LOGniMsgSeverity0,
* @param {number} LOGniMsgNo,
* @return {number} return
* @private
*/
this.__logUse = function(LOGniMsgSeverity0, LOGniMsgNo) {
if (LOGniMsgNo === undefined) LOGniMsgNo=1;
// mask=ALL
if (this.LOGniMask === "ALL") {
this.__debug(`severity=${LOGniMsgSeverity0} msgNo=${LOGniMsgNo} `
+ `>= mask=ALL -> msg log is VISIBLE`);
return true;
}
if(typeof this.__LOGniMaskSeverity[LOGniMsgSeverity0] === "undefined") {
this.__debug(`${this.__LOGniMaskSeverity.LOGniMsgSeverity0} `
+ 'is undefined');
return false;
}
// message hidden
const _no = this.__LOGniMaskSeverity[LOGniMsgSeverity0];
if (LOGniMsgNo < _no) {
this.__debug(`severity=${LOGniMsgSeverity0} `
+ `msgNo=${LOGniMsgNo} < maskNo=${_no} -> msg log is HIDDEN`);
return false;
}
// message visible
this.__debug(`severity=${LOGniMsgSeverity0} `
+ `msgNo=${LOGniMsgNo} >= maskNo=${_no} -> msg log is VISIBLE`);
return true;
};
/**
* Error stack
*
* @param {string} LOGniError,
* @param {number} LOGniErrorStackNo,
*
* @return {string} LOGniErrorStacksLast
* @private
*/
this.__errorStack = function(LOGniError, LOGniErrorStackNo) {
const LOGniErrorStacks = LOGniError.stack.toString().split('\n');
const LOGniErrorStackLen = LOGniErrorStacks.length;
const LOGniErrorStacksLasts = LOGniErrorStacks[LOGniErrorStackLen-LOGniErrorStackNo].split('/');
const LOGniErrorStacksLastLen = LOGniErrorStacksLasts.length;
// debug mode
this.__debug(LOGniErrorStacksLasts, false);
this.__debug(`errorStack len=${LOGniErrorStacksLastLen}`);
let LOGniErrorStacksLast;
if (LOGniErrorStacksLasts[0].indexOf('(') === -1) {
LOGniErrorStacksLast = LOGniErrorStacksLasts[LOGniErrorStacksLastLen-1].split(')')[0].trim();
} else {
LOGniErrorStacksLast = LOGniErrorStacksLasts[0].split('(')[0].trim()+' '+
LOGniErrorStacksLasts[LOGniErrorStacksLastLen-1].split(')')[0].trim();
}
return LOGniErrorStacksLast;
};
/**
* Http(s) request with credentials
*
* @param {string} LOGniUrl,
* @return {number} ,
* @static
*/
this.__request = function(LOGniUrl) {
let __req = new XMLHttpRequest();
__req.open("GET", LOGniUrl, true);
__req.setRequestHeader("Content-type","application/json; charset=utf-8");
__req.withCredentials = true;
__req.send(null);
// debug url
this.__debug(`url=${LOGniUrl}`);
return 0;
};
/**
* Log message
*
* @param {string} LOGniMsgMessage,
* @param {string} LOGniMsgSeverity,
* @param {number} LOGniMsgNo,
* @param {bool} LOGniMsgExt,
* @param {array} LOGniMsgData,
* @return {number} return
* @private
*/
this.__msg = function(LOGniMsgMessage, LOGniMsgSeverity, LOGniMsgNo, LOGniMsgExt, LOGniMsgData) {
if (LOGniMsgMessage === undefined) LOGniMsgMessage="";
if (LOGniMsgSeverity === undefined) LOGniMsgSeverity="DEBUG";
if (LOGniMsgNo === undefined) LOGniMsgNo=1;
// priority
if (LOGniMsgNo < 1) {
LOGniMsgNo = 1;
} else if (LOGniMsgNo > 4 ) {
LOGniMsgNo = 4;
}
const __logniTime = new Date().toISOString();
const __logniTS = Math.round(new Date().getTime()/1000);
const __l0 = LOGniMsgSeverity.substring(0, 1);
const __logniPrefix = __l0 + LOGniMsgNo;
let LOGniMsgText = '';
if (this.__logUse(__l0, LOGniMsgNo) === false) {
return '';
}
// error stack
const LOGniError = new Error();
const LOGniErrorStackLast2 = this.__errorStack(LOGniError, 2);
const LOGniErrorStackLast1 = this.__errorStack(LOGniError, 1);
const LOGniErrorStackExt = 'stack='+LOGniErrorStackLast2+', '+LOGniErrorStackLast1;
// const LOGniErrorStackExt = '';
this.__debug(LOGniError);
// stderr(1)
if (this.LOGniStderr) {
let LOGniMsgExtVisible = false;
if (LOGniMsgExt) {
LOGniMsgExtVisible = true;
}
// if environment dont set -> no visible
if (this.__LOGniRelStr === "rel=0.0.0" &&
this.__LOGniNameStr === "name=unknown" &&
this.__LOGniEnvStr === "env=local") {
LOGniMsgExtVisible = false;
}
// log messsage with env params
if (LOGniMsgExtVisible) {
LOGniMsgText = `${__logniTime} ${__logniPrefix}: ${LOGniMsgMessage} `
+ `{${LOGniErrorStackExt}, ${this.__LOGniNameStr}, `
+ `${this.__LOGniRelStr}, ${this.__LOGniEnvStr}}`;
// log message without env params
} else {
LOGniMsgText = `${__logniTime} ${__logniPrefix}: ${LOGniMsgMessage} `
+ `{${LOGniErrorStackExt}}`;
}
// https://developer.mozilla.org/en-US/docs/Web/API/Console/table
if (typeof LOGniMsgData !== "undefined") {
Console.table(LOGniMsgData);
}
}
if (this.__LOGniFile !== "") {
const __url=`${this.__LOGniFile}/log/${__logniPrefix}.json?n=${this.LOGniName}&`
+ `t=${__logniTS}&m=${encodeURIComponent(LOGniMsgMessage)}`;
this.__request(__url);
}
return LOGniMsgText;
};
/**
* Debug-level messages
*
* Outputs a message to the console with the log level "debug".
*
* @param {string} LOGniMsgMessage,
* @param {number} LOGniMsgNo,
* @static
*/
this.debug = function(LOGniMsgMessage, LOGniMsgNo, LOGniMsgData) {
if (LOGniMsgNo === undefined) LOGniMsgNo=1;
const msg = this.__msg(LOGniMsgMessage, "DEBUG", LOGniMsgNo, true, LOGniMsgData);
if (msg === "") {
return 0;
}
let style = `background:white; color:black; font-size:10px;`;
if (this.LOGniColor) {
style = `color: ${this.__LOGniColors[this.__LOGniSeverityColors.DEBUG]}`;
}
Console.debug(`%c${msg}`, style);
return 1;
};
this.dbg = this.debug;
/**
* Critical error message
*
* @param {string} LOGniMsgMessage,
* @param {number} LOGniMsgNo,
* @static
*/
this.critical = function(LOGniMsgMessage, LOGniMsgNo, LOGniMsgData) {
if (LOGniMsgNo === undefined) LOGniMsgNo=1;
const msg = this.__msg(LOGniMsgMessage, "CRITICAL", LOGniMsgNo, true, LOGniMsgData);
if (msg === "") {
return 0;
}
let style = `background:white; color:black; font-weight:bold; font-size:14px;`;
if (this.LOGniColor) {
style = `color:${this.__LOGniColors[this.__LOGniSeverityColors.CRITICAL]}`;
Console.error(`%c${msg}`, style);
} else {
Console.log(`%c${msg}`, style);
}
return 1;
};
this.fatal = this.critical;
/**
* Informational messages
*
* Informative logging of information. You may use string substitution
* and additional arguments with this method.
*
* @param {string} LOGniMsgMessage,
* @param {number} LOGniMsgNo,
* @static
*/
this.info = function(LOGniMsgMessage, LOGniMsgNo, LOGniMsgData) {
if (LOGniMsgNo === undefined) LOGniMsgNo=1;
const msg = this.__msg(LOGniMsgMessage, "INFO", LOGniMsgNo, true, LOGniMsgData);
if (msg === "") {
return 0;
}
let style = `background:white; color:black;`;
if (this.LOGniColor) {
style = `color:${this.__LOGniColors[this.__LOGniSeverityColors.INFO]}`;
}
Console.info(`%c${msg}`, style);
return 1;
};
this.informational = this.info;
/**
* Warning message: warning conditions
*
* Outputs a warning message. You may use string substitution
* and additional arguments with this method.
*
* @param {string} LOGniMsgMessage,
* @param {number} LOGniMsgNo,
* @static
*/
this.warn = function(LOGniMsgMessage, LOGniMsgNo, LOGniMsgData) {
if (LOGniMsgNo === undefined) LOGniMsgNo=1;
const msg = this.__msg(LOGniMsgMessage, "WARN", LOGniMsgNo, true, LOGniMsgData);
if (msg === "") {
return 0;
}
let style = `background:white; color:black; font-style:italic;`;
if (this.LOGniColor) {
style = `color: ${this.__LOGniColors[this.__LOGniSeverityColors.WARN]}`;
Console.warn(`%c${msg}`, style);
} else {
Console.log(`%c${msg}`, style);
}
return 1;
};
this.warning = this.warn;
/**
* Error message: error conditions
*
* Outputs an error message. You may use string substitution
* and additional arguments with this method.
*
* @param {string} LOGniMsgMessage,
* @param {number} LOGniMsgNo,
* @static
*/
this.error = function(LOGniMsgMessage, LOGniMsgNo, LOGniMsgData) {
if (LOGniMsgNo === undefined) LOGniMsgNo=1;
const msg = this.__msg(LOGniMsgMessage, "ERROR", LOGniMsgNo, true, LOGniMsgData);
if (msg === "") {
return 0;
}
let style = `background:white; color:black; font-weight:bold;`;
if (this.LOGniColor) {
style = `color: ${this.__LOGniColors[this.__LOGniSeverityColors.ERROR]}`;
Console.error(`%c${msg}`, style);
} else {
Console.log(`%c${msg}`, style);
}
return 1;
};
this.err = this.error;
/**
* Emergency message: system is unusable
*
* Alias for CRITICAL=4
*
* @param {string} LOGniMsgMessage,
* @static
*/
this.emergency = function(LOGniMsgMessage) {
return this.critical(LOGniMsgMessage, 4);
};
/**
* Notice message: normal but significant condition
*
* Alias for INFO=1
*
* @param {string} LOGniMsgMessage,
* @static
*/
this.notice = function(LOGniMsgMessage) {
return this.info(LOGniMsgMessage, 1);
};
/**
* Alert message: action must be taken immediately
*
* Alias for ERROR=3
*
* @param {string} LOGniMsgMessage,
* @static
*/
this.alert = function(LOGniMsgMessage) {
return this.error(LOGniMsgMessage, 3);
};
/**
* Log message
*
* For general output of logging information. You may use string
* substitution and additional arguments with this method.
*
* Alias for INFO=1
*
* @param {string} LOGniMsgMessage,
* @static
*/
this.log = function(LOGniMsgMessage) {
return this.info(LOGniMsgMessage, 1);
};
/**
* Exception message
*
* This deprecated API should no longer be used,
* but will probably still work
*
* Alias for ERROR=4
*
* @param {string} LOGniMsgMessage,
* @static
*/
this.exception = function(LOGniMsgMessage) {
return this.error(LOGniMsgMessage, 4);
};
/**
* Create or update cookie
*
* @param {string} name,
* @param {string} value,
* @param {number} dayNo,
* @static
*/
this.setCookie = function(name, value, dayNo) {
let expires;
if (dayNo) {
let date = new Date();
date.setTime(date.getTime()+(dayNo*86400*1000));
expires = `; expires=${date.toGMTString()}`;
} else {
expires = '';
}
cookies = `${name}=${value}${expires}; path=/`;
this.__debug(`cookieSet ${name}="${value}"${expires}`);
return 0;
};
/**
* Read cookie
*
* @param {string} name,
* @static
*/
this.cookieGet = function(name) {
const cookieNameEQ = name + "=";
const cookieDecoded = decodeURIComponent(cookies);
const ca = cookieDecoded.split(';');
for(let i=0;i < ca.length;i++) {
let c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1,c.length);
}
if (c.indexOf(cookieNameEQ) === 0) {
const ret = c.substring(cookieNameEQ.length,c.length);
this.__debug(`cookieGet ${name}="${ret}"`);
return ret;
}
}
this.__debug(`cookieGet ${name} not exist`);
return;
};
/**
* Remove cookie
*
* @param {string} name,
* @static
*/
this.cookieDel = function(name) {
this.__debug(`cookieDel ${name}`);
this.setCookie(name, '', -1);
return 0;
};
/**
* Log for debug mode
*
* @param {string} msg,
* @param {bool} prefix,
* @static
*/
this.__debug = function(msg, prefix) {
if (prefix === undefined) prefix=true;
if (this.debugMode) {
if (prefix) {
Console.debug(`%c[logni.js] ${msg}`, 'font-style: italic;');
} else {
Console.debug(msg);
}
}
return 0;
};
// initialize
this.__init__();
};
// package.json
if ("undefined" !== typeof module) {
module.exports = logni;
}