@searchspring/snap-logger 0.20.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Searchspring
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 ADDED
@@ -0,0 +1,249 @@
1
+ # Snap Logger
2
+
3
+ <a href="https://www.npmjs.com/package/@searchspring/snap-logger"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-logger.svg?style=flat"></a>
4
+
5
+ Simple logger for debugging
6
+
7
+ <img src="https://github.com/searchspring/snap/blob/main/images/logger-example.png?raw=true" />
8
+ <br/><br/>
9
+ <details>
10
+ <summary>Sample code</summary>
11
+ <br/>
12
+
13
+ ```typescript
14
+ logger.image({
15
+ url: 'https://searchspring.com/wp-content/uploads/2020/01/SearchSpring-Primary-FullColor-800-1-1-640x208.png',
16
+ width: '90px',
17
+ height: '30px'
18
+ });
19
+
20
+ logger.error('error');
21
+
22
+ logger.warn('warn');
23
+
24
+ logger.imageText({
25
+ url: 'https://searchspring.com/wp-content/themes/SearchSpring-Theme/dist/images/favicons/favicon.svg',
26
+ }, 'imageText');
27
+
28
+ logger.debug('debug');
29
+
30
+ logger.dev(`%c ${logger.emoji.vortex} %c${logger.prefix}%c${'magical text'}`,
31
+ `color: ${logger.colors.blue}; font-weight: bold; font-size: 10px; line-height: 12px;`,
32
+ `color: ${logger.colors.bluegreen}; font-weight: normal;`,
33
+ `color: ${logger.colors.bluegreen}; font-weight: bold;`);
34
+ ```
35
+ </details>
36
+
37
+
38
+
39
+
40
+ ## Dependency
41
+
42
+ Snap Logger is a dependency of [@searchspring/snap-controller](https://github.com/searchspring/snap/tree/main/packages/snap-controller) <a href="https://www.npmjs.com/package/@searchspring/snap-controller"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-controller.svg?style=flat"></a>
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ npm install --save @searchspring/snap-logger
48
+ ```
49
+
50
+
51
+
52
+ ## Import
53
+ ```typescript
54
+ import { Logger } from '@searchspring/snap-logger';
55
+ ```
56
+
57
+ ## Config
58
+ Snap Logger accepts an optional string prefix which when set is prepended to all logs.
59
+
60
+ ```typescript
61
+ const prefix = 'Log:';
62
+ const logger = new Logger(prefix)
63
+ ```
64
+
65
+ ## Controller usage
66
+ Snap Logger is a dependency of Snap Controller and it is recommended to use logging methods of the controller in place of `console` methods.
67
+
68
+
69
+ ## Standalone usage
70
+ ```typescript
71
+ const logger = new Logger();
72
+
73
+ logger.warn('this is a warning');
74
+ ```
75
+
76
+ ### `setNamespace` method
77
+ Sets prefix instead of defining a prefix in the constructor.
78
+ ```typescript
79
+ const logger = new Logger();
80
+
81
+ logger.warn('Hello');
82
+ // 'Hello'
83
+
84
+ logger.setNamespace('search');
85
+
86
+ logger.warn('Hello');
87
+ // ' [search] :: Hello'
88
+ ```
89
+
90
+ ### `setMode` method
91
+ The default logging mode is `production`.
92
+
93
+ When set to production, logs using `dev` will not be visible. This also includes `image`, `imageText`, `debug`, and `profile`.
94
+
95
+ When set to `development`, all logging methods will be visible.
96
+
97
+
98
+
99
+ ```typescript
100
+ import { Logger, LogMode } from '@searchspring/snap-logger';
101
+
102
+ const logger = new Logger();
103
+ logger.setMode(LogMode.DEVELOPMENT);
104
+ ```
105
+
106
+ ```typescript
107
+ enum LogMode {
108
+ PRODUCTION = 'production',
109
+ DEVELOPMENT = 'development',
110
+ }
111
+ ```
112
+
113
+ ### `error` method
114
+ This method takes any number of parameters and logs them to the console. It is best to use this method for error handling.
115
+ ```typescript
116
+ logger.error('error!!!');
117
+ logger.error('text about the error', errorObject, 'more', 'text');
118
+ ```
119
+
120
+ ### `warn` method
121
+ This method takes any number of parameters and logs them to the console. It is best to use this method for displaying warnings.
122
+ ```typescript
123
+ logger.warn('warning!!!');
124
+ logger.warn('warning', warningObject, 'more text');
125
+ ```
126
+
127
+ ### `dev` method
128
+ This method takes any number of parameters and logs them to the console. If mode is set to `LogMode.PRODUCTION`, the `dev` logs will not be displayed.
129
+
130
+ ```typescript
131
+ logger.dev('dev')
132
+ ```
133
+
134
+ ### `debug` method
135
+ This method takes any number of parameters and logs them to the console. If mode is set to `LogMode.PRODUCTION`, `debug` logs will not be displayed.
136
+
137
+ ```typescript
138
+ logger.debug('debug');
139
+ ```
140
+ ### `image` method
141
+ This method takes any number of parameters and logs them to the console. The first parameter is special and takes properties that specify the image details. If mode is set to `LogMode.PRODUCTION`, `image` logs will not be displayed.
142
+
143
+ ```typescript
144
+ logger.image({
145
+ url: 'https://searchspring.com/wp-content/uploads/2020/01/SearchSpring-Primary-FullColor-800-1-1-640x208.png',
146
+ width: '30px',
147
+ height: '30px'
148
+ });
149
+ ```
150
+
151
+ ### `imageText` method
152
+ This method takes any number of parameters and logs them to the console. The first parameter is special and takes properties that specify the image details. If mode is set to `LogMode.PRODUCTION`, `imageText` logs will not be displayed.
153
+
154
+ ```typescript
155
+ logger.imageText({
156
+ url: 'https://searchspring.com/wp-content/uploads/2020/01/SearchSpring-Primary-FullColor-800-1-1-640x208.png',
157
+ text: `imageText`,
158
+ style: `color: #4c3ce2; font-weight: bold;`,
159
+ });
160
+ ```
161
+
162
+ ### `profile` method
163
+ This method takes any number of parameters and logs them to the console. The first parameter is special and takes a Snap profile. If mode is set to `LogMode.PRODUCTION`, `profile` logs will not be displayed.
164
+
165
+ See [@searchspring/snap-profiler](https://github.com/searchspring/snap/tree/main/packages/snap-profiler) <a href="https://www.npmjs.com/package/@searchspring/snap-profiler"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-profiler.svg?style=flat"></a>
166
+
167
+ ```typescript
168
+ import { Profiler } from '@searchspring/snap-profiler';
169
+ import { Logger } from '@searchspring/snap-logger';
170
+
171
+ const logger = new Logger();
172
+ const profiler = new Profiler();
173
+
174
+ const searchProfile = profiler.create({
175
+ type: 'event',
176
+ name: 'search',
177
+ context: {}
178
+ });
179
+
180
+ searchProfile.start();
181
+
182
+ // code to profile
183
+
184
+ searchProfile.stop();
185
+
186
+ logger.profile(searchProfile)
187
+ ```
188
+
189
+ ### `emoji` property
190
+ The `emoji` property contains various emojis that can be used
191
+
192
+ The following emojis are available:
193
+
194
+ <img src="https://github.com/searchspring/snap/blob/main/images/emojis.png?raw=true" />
195
+
196
+ ```typescript
197
+ const emoji = {
198
+ bang: String.fromCodePoint(0x203c),
199
+ bright: String.fromCodePoint(0x1f506),
200
+ check: String.fromCodePoint(0x2714),
201
+ clock: String.fromCodePoint(0x1f556),
202
+ cloud: String.fromCodePoint(0x2601),
203
+ dim: String.fromCodePoint(0x1f505),
204
+ gear: String.fromCodePoint(0x2699),
205
+ interobang: String.fromCodePoint(0x2049),
206
+ lightning: String.fromCodePoint(0x26a1),
207
+ magic: String.fromCodePoint(0x2728),
208
+ rocket: String.fromCodePoint(0x1f680),
209
+ search: String.fromCodePoint(0x1f50d),
210
+ snap: String.fromCodePoint(0x1f4a5),
211
+ ufo: String.fromCodePoint(0x1f6f8),
212
+ vortex: String.fromCodePoint(0x1f300),
213
+ warning: String.fromCodePoint(0x26a0),
214
+ };
215
+ ```
216
+
217
+ ### `colors` property
218
+ The `colors` property contains various colors that can be used
219
+
220
+ The following colors are available:
221
+
222
+ <img src="https://github.com/searchspring/snap/blob/main/images/colors.png?raw=true" />
223
+
224
+ ```typescript
225
+ const colors = {
226
+ blue: '#3379c1',
227
+ bluelight: '#688BA3',
228
+ bluedark: '#1B3141',
229
+ bluegreen: '#318495',
230
+
231
+ grey: '#61717B',
232
+
233
+ green: '#507B43',
234
+ greendark: '#63715F',
235
+ greenblue: '#46927D',
236
+
237
+ indigo: '#4c3ce2',
238
+
239
+ orange: '#ecaa15',
240
+ orangelight: '#ff6600',
241
+ orangedark: '#c59600',
242
+
243
+ red: '#cc1212',
244
+ redlight: '#f30707',
245
+ reddark: '#8E111C',
246
+
247
+ yellow: '#d1d432',
248
+ };
249
+ ```
@@ -0,0 +1,63 @@
1
+ export declare class Logger {
2
+ private mode;
3
+ emoji: {
4
+ bang: string;
5
+ bright: string;
6
+ check: string;
7
+ clock: string;
8
+ cloud: string;
9
+ dim: string;
10
+ gear: string;
11
+ interobang: string;
12
+ lightning: string;
13
+ magic: string;
14
+ rocket: string;
15
+ search: string;
16
+ snap: string;
17
+ ufo: string;
18
+ vortex: string;
19
+ warning: string;
20
+ };
21
+ colors: {
22
+ blue: string;
23
+ bluelight: string;
24
+ bluedark: string;
25
+ bluegreen: string;
26
+ grey: string;
27
+ green: string;
28
+ greendark: string;
29
+ greenblue: string;
30
+ indigo: string;
31
+ orange: string;
32
+ orangelight: string;
33
+ orangedark: string;
34
+ red: string;
35
+ redlight: string;
36
+ reddark: string;
37
+ yellow: string;
38
+ };
39
+ private prefix;
40
+ constructor(prefix?: string);
41
+ setNamespace(group: string): void;
42
+ setMode(mode: LogMode): void;
43
+ error(...params: any[]): void;
44
+ warn(...params: any[]): void;
45
+ image({ url, width, height }: {
46
+ url: string;
47
+ width: number;
48
+ height: number;
49
+ }, ...params: any[]): void;
50
+ imageText({ url, text, style }: {
51
+ url: string;
52
+ text: string;
53
+ style: string;
54
+ }, ...params: any[]): void;
55
+ debug(...params: any[]): void;
56
+ profile(profile: any, ...params: any[]): void;
57
+ dev(...params: any[]): void;
58
+ }
59
+ export declare enum LogMode {
60
+ PRODUCTION = "production",
61
+ DEVELOPMENT = "development"
62
+ }
63
+ //# sourceMappingURL=Logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAGA,qBAAa,MAAM;IAClB,OAAO,CAAC,IAAI,CAAsB;IAC3B,KAAK;;;;;;;;;;;;;;;;;MAAS;IACd,MAAM;;;;;;;;;;;;;;;;;MAAU;IACvB,OAAO,CAAC,MAAM,CAAM;gBAER,MAAM,CAAC,EAAE,MAAM;IAIpB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIjC,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAM5B,KAAK,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IAe7B,IAAI,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IAgB5B,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IASrG,SAAS,CAAC,EAAE,GAAG,EAAE,IAAS,EAAE,KAAK,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IAe1G,KAAK,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IAe7B,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IAe7C,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;CAKlC;AAED,oBAAY,OAAO;IAClB,UAAU,eAAe;IACzB,WAAW,gBAAgB;CAC3B"}
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LogMode = exports.Logger = void 0;
13
+ var colors_1 = require("./colors");
14
+ var emoji_1 = require("./emoji");
15
+ var Logger = /** @class */ (function () {
16
+ function Logger(prefix) {
17
+ this.mode = LogMode.PRODUCTION;
18
+ this.emoji = emoji_1.emoji;
19
+ this.colors = colors_1.colors;
20
+ this.prefix = '';
21
+ this.prefix = prefix;
22
+ }
23
+ Logger.prototype.setNamespace = function (group) {
24
+ this.prefix = " [".concat(group, "] :: ");
25
+ };
26
+ Logger.prototype.setMode = function (mode) {
27
+ if (Object.values(LogMode).includes(mode)) {
28
+ this.mode = mode;
29
+ }
30
+ };
31
+ Logger.prototype.error = function () {
32
+ var params = [];
33
+ for (var _i = 0; _i < arguments.length; _i++) {
34
+ params[_i] = arguments[_i];
35
+ }
36
+ var text = '';
37
+ var rest = params;
38
+ if (params.length && typeof params[0] == 'string') {
39
+ text = params[0], rest = params.slice(1);
40
+ }
41
+ console.log.apply(console, __spreadArray(["%c ".concat(emoji_1.emoji.bang, " %c").concat(this.prefix).concat(text), "color: ".concat(colors_1.colors.red, "; font-weight: bold; font-size: 14px; line-height: 12px;"), "color: ".concat(colors_1.colors.red, "; font-weight: bold;")], rest, false));
42
+ };
43
+ Logger.prototype.warn = function () {
44
+ var params = [];
45
+ for (var _i = 0; _i < arguments.length; _i++) {
46
+ params[_i] = arguments[_i];
47
+ }
48
+ var text = '';
49
+ var rest = params;
50
+ if (params.length && typeof params[0] == 'string') {
51
+ text = params[0], rest = params.slice(1);
52
+ }
53
+ console.log.apply(console, __spreadArray(["%c ".concat(emoji_1.emoji.warning, " %c").concat(this.prefix, "%c").concat(text), "color: ".concat(colors_1.colors.yellow, "; font-weight: bold; font-size: 14px; line-height: 12px;"), "color: ".concat(colors_1.colors.yellow, "; font-weight: normal;"), "color: ".concat(colors_1.colors.yellow, "; font-weight: bold;")], rest, false));
54
+ };
55
+ Logger.prototype.image = function (_a) {
56
+ var url = _a.url, width = _a.width, height = _a.height;
57
+ var params = [];
58
+ for (var _i = 1; _i < arguments.length; _i++) {
59
+ params[_i - 1] = arguments[_i];
60
+ }
61
+ var styles = {
62
+ size: "font-size: 1px; padding: ".concat(height || width, " ").concat(width || height, ";"),
63
+ background: "background: url(\"".concat(url, "\") no-repeat; background-size: contain;"),
64
+ };
65
+ this.dev.apply(this, __spreadArray(["%c...", "".concat(styles.size, " ").concat(styles.background)], params, false));
66
+ };
67
+ Logger.prototype.imageText = function (_a) {
68
+ var url = _a.url, _b = _a.text, text = _b === void 0 ? '' : _b, style = _a.style;
69
+ var params = [];
70
+ for (var _i = 1; _i < arguments.length; _i++) {
71
+ params[_i - 1] = arguments[_i];
72
+ }
73
+ var styles = {
74
+ background: "margin-left: 6px; background: url(\"".concat(url, "\") no-repeat; background-size: contain;"),
75
+ custom: style,
76
+ };
77
+ var imgText = text;
78
+ var rest = params;
79
+ if (!imgText && (params === null || params === void 0 ? void 0 : params.length)) {
80
+ imgText = params[0], rest = params.slice(1);
81
+ }
82
+ this.dev.apply(this, __spreadArray(["%c ".concat(' ' + this.prefix).concat(imgText), "".concat(styles.background, " ").concat(styles.custom)], rest, false));
83
+ };
84
+ Logger.prototype.debug = function () {
85
+ var params = [];
86
+ for (var _i = 0; _i < arguments.length; _i++) {
87
+ params[_i] = arguments[_i];
88
+ }
89
+ var text = '';
90
+ var rest = params;
91
+ if (params.length && typeof params[0] == 'string') {
92
+ text = params[0], rest = params.slice(1);
93
+ }
94
+ this.dev.apply(this, __spreadArray(["%c ".concat(emoji_1.emoji.interobang, " %c").concat(this.prefix).concat(text), "color: ".concat(colors_1.colors.orangelight, "; font-weight: bold; font-size: 14px; line-height: 12px;"), "color: ".concat(colors_1.colors.orangelight, "; font-weight: bold;")], rest, false));
95
+ };
96
+ Logger.prototype.profile = function (profile) {
97
+ var params = [];
98
+ for (var _i = 1; _i < arguments.length; _i++) {
99
+ params[_i - 1] = arguments[_i];
100
+ }
101
+ this.dev.apply(this, __spreadArray(["%c ".concat(emoji_1.emoji.gear, " %c").concat(this.prefix, "%c").concat(profile.type, " %c~ ").concat(profile.name, " :: %c").concat(profile.status.toUpperCase()).concat(profile.status == 'finished' ? ' :: %c' + profile.time.run + 'ms' : ''), "color: ".concat(colors_1.colors.orange, "; font-size: 14px; line-height: 12px;"), "color: ".concat(colors_1.colors.orange, ";"), "color: ".concat(colors_1.colors.orange, "; font-style: italic;"), "color: ".concat(colors_1.colors.orange, ";"), "color: ".concat(colors_1.colors.orange, "; font-weight: bold;"), "color: ".concat(colors_1.colors.grey, ";")], params, false));
102
+ };
103
+ Logger.prototype.dev = function () {
104
+ var params = [];
105
+ for (var _i = 0; _i < arguments.length; _i++) {
106
+ params[_i] = arguments[_i];
107
+ }
108
+ if (this.mode === LogMode.DEVELOPMENT) {
109
+ console.log.apply(console, params);
110
+ }
111
+ };
112
+ return Logger;
113
+ }());
114
+ exports.Logger = Logger;
115
+ var LogMode;
116
+ (function (LogMode) {
117
+ LogMode["PRODUCTION"] = "production";
118
+ LogMode["DEVELOPMENT"] = "development";
119
+ })(LogMode = exports.LogMode || (exports.LogMode = {}));
@@ -0,0 +1,19 @@
1
+ export declare const colors: {
2
+ blue: string;
3
+ bluelight: string;
4
+ bluedark: string;
5
+ bluegreen: string;
6
+ grey: string;
7
+ green: string;
8
+ greendark: string;
9
+ greenblue: string;
10
+ indigo: string;
11
+ orange: string;
12
+ orangelight: string;
13
+ orangedark: string;
14
+ red: string;
15
+ redlight: string;
16
+ reddark: string;
17
+ yellow: string;
18
+ };
19
+ //# sourceMappingURL=colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/colors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;CAuBlB,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.colors = void 0;
4
+ exports.colors = {
5
+ blue: '#3379c1',
6
+ bluelight: '#688BA3',
7
+ bluedark: '#1B3141',
8
+ bluegreen: '#318495',
9
+ grey: '#61717B',
10
+ green: '#507B43',
11
+ greendark: '#63715F',
12
+ greenblue: '#46927D',
13
+ indigo: '#4c3ce2',
14
+ orange: '#ecaa15',
15
+ orangelight: '#ff6600',
16
+ orangedark: '#c59600',
17
+ red: '#cc1212',
18
+ redlight: '#f30707',
19
+ reddark: '#8E111C',
20
+ yellow: '#d1d432',
21
+ };
@@ -0,0 +1,19 @@
1
+ export declare const emoji: {
2
+ bang: string;
3
+ bright: string;
4
+ check: string;
5
+ clock: string;
6
+ cloud: string;
7
+ dim: string;
8
+ gear: string;
9
+ interobang: string;
10
+ lightning: string;
11
+ magic: string;
12
+ rocket: string;
13
+ search: string;
14
+ snap: string;
15
+ ufo: string;
16
+ vortex: string;
17
+ warning: string;
18
+ };
19
+ //# sourceMappingURL=emoji.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emoji.d.ts","sourceRoot":"","sources":["../../src/emoji.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;CAiBjB,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emoji = void 0;
4
+ exports.emoji = {
5
+ bang: String.fromCodePoint(0x203c),
6
+ bright: String.fromCodePoint(0x1f506),
7
+ check: String.fromCodePoint(0x2714),
8
+ clock: String.fromCodePoint(0x1f556),
9
+ cloud: String.fromCodePoint(0x2601),
10
+ dim: String.fromCodePoint(0x1f505),
11
+ gear: String.fromCodePoint(0x2699),
12
+ interobang: String.fromCodePoint(0x2049),
13
+ lightning: String.fromCodePoint(0x26a1),
14
+ magic: String.fromCodePoint(0x2728),
15
+ rocket: String.fromCodePoint(0x1f680),
16
+ search: String.fromCodePoint(0x1f50d),
17
+ snap: String.fromCodePoint(0x1f4a5),
18
+ ufo: String.fromCodePoint(0x1f6f8),
19
+ vortex: String.fromCodePoint(0x1f300),
20
+ warning: String.fromCodePoint(0x26a0),
21
+ };
@@ -0,0 +1,4 @@
1
+ export { Logger, LogMode } from './Logger';
2
+ export { colors } from './colors';
3
+ export { emoji } from './emoji';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emoji = exports.colors = exports.LogMode = exports.Logger = void 0;
4
+ var Logger_1 = require("./Logger");
5
+ Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return Logger_1.Logger; } });
6
+ Object.defineProperty(exports, "LogMode", { enumerable: true, get: function () { return Logger_1.LogMode; } });
7
+ var colors_1 = require("./colors");
8
+ Object.defineProperty(exports, "colors", { enumerable: true, get: function () { return colors_1.colors; } });
9
+ var emoji_1 = require("./emoji");
10
+ Object.defineProperty(exports, "emoji", { enumerable: true, get: function () { return emoji_1.emoji; } });
@@ -0,0 +1,63 @@
1
+ export declare class Logger {
2
+ private mode;
3
+ emoji: {
4
+ bang: string;
5
+ bright: string;
6
+ check: string;
7
+ clock: string;
8
+ cloud: string;
9
+ dim: string;
10
+ gear: string;
11
+ interobang: string;
12
+ lightning: string;
13
+ magic: string;
14
+ rocket: string;
15
+ search: string;
16
+ snap: string;
17
+ ufo: string;
18
+ vortex: string;
19
+ warning: string;
20
+ };
21
+ colors: {
22
+ blue: string;
23
+ bluelight: string;
24
+ bluedark: string;
25
+ bluegreen: string;
26
+ grey: string;
27
+ green: string;
28
+ greendark: string;
29
+ greenblue: string;
30
+ indigo: string;
31
+ orange: string;
32
+ orangelight: string;
33
+ orangedark: string;
34
+ red: string;
35
+ redlight: string;
36
+ reddark: string;
37
+ yellow: string;
38
+ };
39
+ private prefix;
40
+ constructor(prefix?: string);
41
+ setNamespace(group: string): void;
42
+ setMode(mode: LogMode): void;
43
+ error(...params: any[]): void;
44
+ warn(...params: any[]): void;
45
+ image({ url, width, height }: {
46
+ url: string;
47
+ width: number;
48
+ height: number;
49
+ }, ...params: any[]): void;
50
+ imageText({ url, text, style }: {
51
+ url: string;
52
+ text: string;
53
+ style: string;
54
+ }, ...params: any[]): void;
55
+ debug(...params: any[]): void;
56
+ profile(profile: any, ...params: any[]): void;
57
+ dev(...params: any[]): void;
58
+ }
59
+ export declare enum LogMode {
60
+ PRODUCTION = "production",
61
+ DEVELOPMENT = "development"
62
+ }
63
+ //# sourceMappingURL=Logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAGA,qBAAa,MAAM;IAClB,OAAO,CAAC,IAAI,CAAsB;IAC3B,KAAK;;;;;;;;;;;;;;;;;MAAS;IACd,MAAM;;;;;;;;;;;;;;;;;MAAU;IACvB,OAAO,CAAC,MAAM,CAAM;gBAER,MAAM,CAAC,EAAE,MAAM;IAIpB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIjC,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAM5B,KAAK,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IAe7B,IAAI,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IAgB5B,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IASrG,SAAS,CAAC,EAAE,GAAG,EAAE,IAAS,EAAE,KAAK,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IAe1G,KAAK,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IAe7B,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IAe7C,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;CAKlC;AAED,oBAAY,OAAO;IAClB,UAAU,eAAe;IACzB,WAAW,gBAAgB;CAC3B"}
@@ -0,0 +1,75 @@
1
+ import { colors } from './colors';
2
+ import { emoji } from './emoji';
3
+ export class Logger {
4
+ constructor(prefix) {
5
+ this.mode = LogMode.PRODUCTION;
6
+ this.emoji = emoji;
7
+ this.colors = colors;
8
+ this.prefix = '';
9
+ this.prefix = prefix;
10
+ }
11
+ setNamespace(group) {
12
+ this.prefix = ` [${group}] :: `;
13
+ }
14
+ setMode(mode) {
15
+ if (Object.values(LogMode).includes(mode)) {
16
+ this.mode = mode;
17
+ }
18
+ }
19
+ error(...params) {
20
+ let text = '';
21
+ let rest = params;
22
+ if (params.length && typeof params[0] == 'string') {
23
+ [text, ...rest] = params;
24
+ }
25
+ console.log(`%c ${emoji.bang} %c${this.prefix}${text}`, `color: ${colors.red}; font-weight: bold; font-size: 14px; line-height: 12px;`, `color: ${colors.red}; font-weight: bold;`, ...rest);
26
+ }
27
+ warn(...params) {
28
+ let text = '';
29
+ let rest = params;
30
+ if (params.length && typeof params[0] == 'string') {
31
+ [text, ...rest] = params;
32
+ }
33
+ console.log(`%c ${emoji.warning} %c${this.prefix}%c${text}`, `color: ${colors.yellow}; font-weight: bold; font-size: 14px; line-height: 12px;`, `color: ${colors.yellow}; font-weight: normal;`, `color: ${colors.yellow}; font-weight: bold;`, ...rest);
34
+ }
35
+ image({ url, width, height }, ...params) {
36
+ const styles = {
37
+ size: `font-size: 1px; padding: ${height || width} ${width || height};`,
38
+ background: `background: url("${url}") no-repeat; background-size: contain;`,
39
+ };
40
+ this.dev(`%c...`, `${styles.size} ${styles.background}`, ...params);
41
+ }
42
+ imageText({ url, text = '', style }, ...params) {
43
+ const styles = {
44
+ background: `margin-left: 6px; background: url("${url}") no-repeat; background-size: contain;`,
45
+ custom: style,
46
+ };
47
+ let imgText = text;
48
+ let rest = params;
49
+ if (!imgText && params?.length) {
50
+ [imgText, ...rest] = params;
51
+ }
52
+ this.dev(`%c ${' ' + this.prefix}${imgText}`, `${styles.background} ${styles.custom}`, ...rest);
53
+ }
54
+ debug(...params) {
55
+ let text = '';
56
+ let rest = params;
57
+ if (params.length && typeof params[0] == 'string') {
58
+ [text, ...rest] = params;
59
+ }
60
+ this.dev(`%c ${emoji.interobang} %c${this.prefix}${text}`, `color: ${colors.orangelight}; font-weight: bold; font-size: 14px; line-height: 12px;`, `color: ${colors.orangelight}; font-weight: bold;`, ...rest);
61
+ }
62
+ profile(profile, ...params) {
63
+ this.dev(`%c ${emoji.gear} %c${this.prefix}%c${profile.type} %c~ ${profile.name} :: %c${profile.status.toUpperCase()}${profile.status == 'finished' ? ' :: %c' + profile.time.run + 'ms' : ''}`, `color: ${colors.orange}; font-size: 14px; line-height: 12px;`, `color: ${colors.orange};`, `color: ${colors.orange}; font-style: italic;`, `color: ${colors.orange};`, `color: ${colors.orange}; font-weight: bold;`, `color: ${colors.grey};`, ...params);
64
+ }
65
+ dev(...params) {
66
+ if (this.mode === LogMode.DEVELOPMENT) {
67
+ console.log(...params);
68
+ }
69
+ }
70
+ }
71
+ export var LogMode;
72
+ (function (LogMode) {
73
+ LogMode["PRODUCTION"] = "production";
74
+ LogMode["DEVELOPMENT"] = "development";
75
+ })(LogMode || (LogMode = {}));
@@ -0,0 +1,19 @@
1
+ export declare const colors: {
2
+ blue: string;
3
+ bluelight: string;
4
+ bluedark: string;
5
+ bluegreen: string;
6
+ grey: string;
7
+ green: string;
8
+ greendark: string;
9
+ greenblue: string;
10
+ indigo: string;
11
+ orange: string;
12
+ orangelight: string;
13
+ orangedark: string;
14
+ red: string;
15
+ redlight: string;
16
+ reddark: string;
17
+ yellow: string;
18
+ };
19
+ //# sourceMappingURL=colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/colors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;CAuBlB,CAAC"}
@@ -0,0 +1,18 @@
1
+ export const colors = {
2
+ blue: '#3379c1',
3
+ bluelight: '#688BA3',
4
+ bluedark: '#1B3141',
5
+ bluegreen: '#318495',
6
+ grey: '#61717B',
7
+ green: '#507B43',
8
+ greendark: '#63715F',
9
+ greenblue: '#46927D',
10
+ indigo: '#4c3ce2',
11
+ orange: '#ecaa15',
12
+ orangelight: '#ff6600',
13
+ orangedark: '#c59600',
14
+ red: '#cc1212',
15
+ redlight: '#f30707',
16
+ reddark: '#8E111C',
17
+ yellow: '#d1d432',
18
+ };
@@ -0,0 +1,19 @@
1
+ export declare const emoji: {
2
+ bang: string;
3
+ bright: string;
4
+ check: string;
5
+ clock: string;
6
+ cloud: string;
7
+ dim: string;
8
+ gear: string;
9
+ interobang: string;
10
+ lightning: string;
11
+ magic: string;
12
+ rocket: string;
13
+ search: string;
14
+ snap: string;
15
+ ufo: string;
16
+ vortex: string;
17
+ warning: string;
18
+ };
19
+ //# sourceMappingURL=emoji.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emoji.d.ts","sourceRoot":"","sources":["../../src/emoji.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;CAiBjB,CAAC"}
@@ -0,0 +1,18 @@
1
+ export const emoji = {
2
+ bang: String.fromCodePoint(0x203c),
3
+ bright: String.fromCodePoint(0x1f506),
4
+ check: String.fromCodePoint(0x2714),
5
+ clock: String.fromCodePoint(0x1f556),
6
+ cloud: String.fromCodePoint(0x2601),
7
+ dim: String.fromCodePoint(0x1f505),
8
+ gear: String.fromCodePoint(0x2699),
9
+ interobang: String.fromCodePoint(0x2049),
10
+ lightning: String.fromCodePoint(0x26a1),
11
+ magic: String.fromCodePoint(0x2728),
12
+ rocket: String.fromCodePoint(0x1f680),
13
+ search: String.fromCodePoint(0x1f50d),
14
+ snap: String.fromCodePoint(0x1f4a5),
15
+ ufo: String.fromCodePoint(0x1f6f8),
16
+ vortex: String.fromCodePoint(0x1f300),
17
+ warning: String.fromCodePoint(0x26a0),
18
+ };
@@ -0,0 +1,4 @@
1
+ export { Logger, LogMode } from './Logger';
2
+ export { colors } from './colors';
3
+ export { emoji } from './emoji';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { Logger, LogMode } from './Logger';
2
+ export { colors } from './colors';
3
+ export { emoji } from './emoji';
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@searchspring/snap-logger",
3
+ "version": "0.20.0",
4
+ "description": "Snap Logger",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "author": "Searchspring",
8
+ "license": "MIT",
9
+ "repository": "https://github.com/searchspring/snap",
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "scripts": {
14
+ "build": "rm -rf ./dist && tsc && tsc -p tsconfig.cjs.json",
15
+ "build:docs": "typedoc --out docs src/index.ts",
16
+ "dev": "tsc --watch",
17
+ "format": "prettier --write 'src/**/*.{js,jsx,ts,tsx}'",
18
+ "lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
19
+ "test": "jest --passWithNoTests",
20
+ "test:watch": "jest --watch"
21
+ },
22
+ "sideEffects": false,
23
+ "files": [
24
+ "dist/**/*"
25
+ ],
26
+ "gitHead": "122405b27b497c7bb6a189c30535fdc197bc3ef0"
27
+ }