@node-cli/logger 0.0.3 → 0.0.4

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.
Files changed (2) hide show
  1. package/dist/Logger.js +64 -139
  2. package/package.json +2 -2
package/dist/Logger.js CHANGED
@@ -1,18 +1,11 @@
1
- import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
1
  import kleur from "kleur";
6
2
  import util from "node:util";
7
- export var Logger = /*#__PURE__*/ function() {
8
- "use strict";
9
- function Logger() {
10
- var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _ref_boring = _ref.boring, boring = _ref_boring === void 0 ? false : _ref_boring, _ref_silent = _ref.silent, silent = _ref_silent === void 0 ? false : _ref_silent, _ref_prefix = _ref.prefix, prefix = _ref_prefix === void 0 ? "" : _ref_prefix, _ref_timestamp = _ref.timestamp, timestamp = _ref_timestamp === void 0 ? false : _ref_timestamp;
11
- _class_call_check(this, Logger);
12
- _define_property(this, "shouldLog", void 0);
13
- _define_property(this, "globalPrefix", void 0);
14
- _define_property(this, "showTimestamp", void 0);
15
- _define_property(this, "printOptions", void 0);
3
+ export class Logger {
4
+ shouldLog;
5
+ globalPrefix;
6
+ showTimestamp;
7
+ printOptions;
8
+ constructor({ boring =false , silent =false , prefix ="" , timestamp =false } = {}){
16
9
  this.shouldLog = !silent;
17
10
  this.globalPrefix = prefix;
18
11
  this.showTimestamp = timestamp;
@@ -22,132 +15,64 @@ export var Logger = /*#__PURE__*/ function() {
22
15
  depth: 5
23
16
  };
24
17
  }
25
- _create_class(Logger, [
26
- {
27
- key: "silent",
28
- set: function set(flag) {
29
- this.shouldLog = !flag;
30
- }
31
- },
32
- {
33
- key: "boring",
34
- set: function set(flag) {
35
- this.printOptions.colors = !flag;
36
- }
37
- },
38
- {
39
- key: "prefix",
40
- set: function set(prefix) {
41
- this.globalPrefix = prefix;
42
- }
43
- },
44
- {
45
- key: "timestamp",
46
- set: function set(flag) {
47
- this.showTimestamp = flag;
48
- }
49
- },
50
- {
51
- key: "_log",
52
- value: function _log(type) {
53
- for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
54
- args[_key - 1] = arguments[_key];
55
- }
56
- if (this.shouldLog) {
57
- var msg;
58
- if (!this.showTimestamp && !this.globalPrefix) {
59
- var _util;
60
- msg = (_util = util).formatWithOptions.apply(_util, [
61
- this.printOptions
62
- ].concat(_to_consumable_array(args)));
63
- } else {
64
- var _util1;
65
- var prefix = this.globalPrefix ? [
66
- this.globalPrefix
67
- ] : [];
68
- if (this.showTimestamp) {
69
- var now = new Date();
70
- prefix.push(this.printOptions.colors ? "".concat(kleur.grey("[ ".concat(now.toDateString(), " ").concat(now.toLocaleTimeString(), " ]"))) : "[ ".concat(now.toDateString(), " ").concat(now.toLocaleTimeString(), " ]"));
71
- }
72
- msg = (_util1 = util).formatWithOptions.apply(_util1, [
73
- this.printOptions,
74
- prefix.join(" ")
75
- ].concat(_to_consumable_array(args)));
76
- }
77
- console[type.method](this.printOptions.colors ? "".concat(type.color(msg)) : msg);
78
- }
79
- }
80
- },
81
- {
82
- key: "info",
83
- value: function info() {
84
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
85
- args[_key] = arguments[_key];
86
- }
87
- this._log.apply(this, [
88
- {
89
- method: "info",
90
- color: kleur.blue
91
- }
92
- ].concat(_to_consumable_array(args)));
93
- }
94
- },
95
- {
96
- key: "log",
97
- value: function log() {
98
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
99
- args[_key] = arguments[_key];
100
- }
101
- this._log.apply(this, [
102
- {
103
- method: "log",
104
- color: kleur.white
105
- }
106
- ].concat(_to_consumable_array(args)));
107
- }
108
- },
109
- {
110
- key: "debug",
111
- value: function debug() {
112
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
113
- args[_key] = arguments[_key];
114
- }
115
- this._log.apply(this, [
116
- {
117
- method: "debug",
118
- color: kleur.grey
119
- }
120
- ].concat(_to_consumable_array(args)));
121
- }
122
- },
123
- {
124
- key: "warn",
125
- value: function warn() {
126
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
127
- args[_key] = arguments[_key];
128
- }
129
- this._log.apply(this, [
130
- {
131
- method: "warn",
132
- color: kleur.yellow
133
- }
134
- ].concat(_to_consumable_array(args)));
135
- }
136
- },
137
- {
138
- key: "error",
139
- value: function error() {
140
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
141
- args[_key] = arguments[_key];
18
+ set silent(flag) {
19
+ this.shouldLog = !flag;
20
+ }
21
+ set boring(flag) {
22
+ this.printOptions.colors = !flag;
23
+ }
24
+ set prefix(prefix) {
25
+ this.globalPrefix = prefix;
26
+ }
27
+ set timestamp(flag) {
28
+ this.showTimestamp = flag;
29
+ }
30
+ _log(type, ...args) {
31
+ if (this.shouldLog) {
32
+ let msg;
33
+ if (!this.showTimestamp && !this.globalPrefix) {
34
+ msg = util.formatWithOptions(this.printOptions, ...args);
35
+ } else {
36
+ const prefix = this.globalPrefix ? [
37
+ this.globalPrefix
38
+ ] : [];
39
+ if (this.showTimestamp) {
40
+ const now = new Date();
41
+ prefix.push(this.printOptions.colors ? `${kleur.grey(`[ ${now.toDateString()} ${now.toLocaleTimeString()} ]`)}` : `[ ${now.toDateString()} ${now.toLocaleTimeString()} ]`);
142
42
  }
143
- this._log.apply(this, [
144
- {
145
- method: "error",
146
- color: kleur.red
147
- }
148
- ].concat(_to_consumable_array(args)));
43
+ msg = util.formatWithOptions(this.printOptions, prefix.join(" "), ...args);
149
44
  }
45
+ console[type.method](this.printOptions.colors ? `${type.color(msg)}` : msg);
150
46
  }
151
- ]);
152
- return Logger;
153
- }();
47
+ }
48
+ info(...args) {
49
+ this._log({
50
+ method: "info",
51
+ color: kleur.blue
52
+ }, ...args);
53
+ }
54
+ log(...args) {
55
+ this._log({
56
+ method: "log",
57
+ color: kleur.white
58
+ }, ...args);
59
+ }
60
+ debug(...args) {
61
+ this._log({
62
+ method: "debug",
63
+ color: kleur.grey
64
+ }, ...args);
65
+ }
66
+ warn(...args) {
67
+ this._log({
68
+ method: "warn",
69
+ color: kleur.yellow
70
+ }, ...args);
71
+ }
72
+ error(...args) {
73
+ this._log({
74
+ method: "error",
75
+ color: kleur.red
76
+ }, ...args);
77
+ }
78
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-cli/logger",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "description": "A tiny console logger for nodejs CLI apps",
@@ -25,5 +25,5 @@
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
28
- "gitHead": "4eff10b64cc9e8f60828ae0a0090d3385c54ac44"
28
+ "gitHead": "2b5ec875535713efa7352e93a4be142381c6c830"
29
29
  }