@athoscommerce/snap-logger 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Athos Commerce
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,164 @@
1
+ # Snap Logger
2
+
3
+ Snap Logger is available on each controller via `controller.log`. Controller logs are prefixed with the controller's id and it is recommended to use logging methods of the controller in place of `window.console` methods.
4
+
5
+ ```js
6
+ controller.log.image({
7
+ url: 'https://searchspring.com/wp-content/uploads/2020/01/SearchSpring-Primary-FullColor-800-1-1-640x208.png',
8
+ width: '90px',
9
+ height: '30px'
10
+ });
11
+
12
+ controller.log.error('error');
13
+
14
+ controller.log.warn('warn');
15
+
16
+ controller.log.imageText({
17
+ url: 'https://searchspring.com/wp-content/themes/SearchSpring-Theme/dist/images/favicons/favicon.svg',
18
+ }, 'imageText');
19
+
20
+ controller.log.debug('debug');
21
+
22
+ controller.log.dev(`%c ${controller.log.emoji.vortex} %c${controller.log.prefix}%c${'magical text'}`,
23
+ `color: ${controller.log.colors.blue}; font-weight: bold; font-size: 10px; line-height: 12px;`,
24
+ `color: ${controller.log.colors.bluegreen}; font-weight: normal;`,
25
+ `color: ${controller.log.colors.bluegreen}; font-weight: bold;`);
26
+ ```
27
+
28
+ ## `setMode` method
29
+ The default logging mode is `production`. (Set by Snap config)
30
+
31
+ When set to production, logs using `dev` will not be visible. This also includes `image`, `imageText`, `debug`, and `profile`.
32
+
33
+ When set to `development`, all logging methods will be visible.
34
+
35
+
36
+ ## `error` method
37
+ This method takes any number of parameters and logs them to the console. It is best to use this method for error handling.
38
+ ```js
39
+ controller.log.error('error!!!');
40
+ controller.log.error('text about the error', errorObject, 'more', 'text');
41
+ ```
42
+
43
+ ## `warn` method
44
+ This method takes any number of parameters and logs them to the console. It is best to use this method for displaying warnings.
45
+ ```js
46
+ controller.log.warn('warning!!!');
47
+ controller.log.warn('warning', warningObject, 'more text');
48
+ ```
49
+
50
+ ## `dev` method
51
+ 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.
52
+
53
+ ```js
54
+ controller.log.dev('dev')
55
+ ```
56
+
57
+ ## `debug` method
58
+ 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.
59
+
60
+ ```js
61
+ controller.log.debug('debug');
62
+ ```
63
+ ## `image` method
64
+ 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.
65
+
66
+ ```js
67
+ controller.log.image({
68
+ url: 'https://searchspring.com/wp-content/uploads/2020/01/SearchSpring-Primary-FullColor-800-1-1-640x208.png',
69
+ width: '30px',
70
+ height: '30px'
71
+ });
72
+ ```
73
+
74
+ ## `imageText` method
75
+ 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.
76
+
77
+ ```js
78
+ controller.log.imageText({
79
+ url: 'https://searchspring.com/wp-content/uploads/2020/01/SearchSpring-Primary-FullColor-800-1-1-640x208.png',
80
+ text: `imageText`,
81
+ style: `color: #4c3ce2; font-weight: bold;`,
82
+ });
83
+ ```
84
+
85
+ ## `profile` method
86
+
87
+ This method takes any number of parameters and logs them to the console. The first parameter is special and takes a [Snap profile](https://athoscommerce.github.io/snap/reference-profiler). If mode is set to `LogMode.PRODUCTION`, `profile` logs will not be displayed.
88
+ ```js
89
+ const searchProfile = controller.profiler.create({
90
+ type: 'event',
91
+ name: 'search',
92
+ context: {}
93
+ });
94
+
95
+ searchProfile.start();
96
+
97
+ // code to profile
98
+
99
+ searchProfile.stop();
100
+
101
+ controller.log.profile(searchProfile)
102
+ ```
103
+
104
+ ## `emoji` property
105
+ The `emoji` property contains various emojis that can be used
106
+
107
+ The following emojis are available:
108
+
109
+ <img src="https://github.com/athoscommerce/snap/blob/main/images/emojis.png?raw=true" />
110
+
111
+ ```js
112
+ const emoji = {
113
+ bang: String.fromCodePoint(0x203c),
114
+ bright: String.fromCodePoint(0x1f506),
115
+ check: String.fromCodePoint(0x2714),
116
+ clock: String.fromCodePoint(0x1f556),
117
+ cloud: String.fromCodePoint(0x2601),
118
+ dim: String.fromCodePoint(0x1f505),
119
+ gear: String.fromCodePoint(0x2699),
120
+ interobang: String.fromCodePoint(0x2049),
121
+ lightning: String.fromCodePoint(0x26a1),
122
+ magic: String.fromCodePoint(0x2728),
123
+ rocket: String.fromCodePoint(0x1f680),
124
+ search: String.fromCodePoint(0x1f50d),
125
+ snap: String.fromCodePoint(0x1f4a5),
126
+ ufo: String.fromCodePoint(0x1f6f8),
127
+ vortex: String.fromCodePoint(0x1f300),
128
+ warning: String.fromCodePoint(0x26a0),
129
+ };
130
+ ```
131
+
132
+ ## `colors` property
133
+ The `colors` property contains various colors that can be used
134
+
135
+ The following colors are available:
136
+
137
+ <img src="https://github.com/athoscommerce/snap/blob/main/images/colors.png?raw=true" />
138
+
139
+ ```js
140
+ const colors = {
141
+ blue: '#3379c1',
142
+ bluelight: '#688BA3',
143
+ bluedark: '#1B3141',
144
+ bluegreen: '#318495',
145
+
146
+ grey: '#61717B',
147
+
148
+ green: '#507B43',
149
+ greendark: '#63715F',
150
+ greenblue: '#46927D',
151
+
152
+ indigo: '#4c3ce2',
153
+
154
+ orange: '#ecaa15',
155
+ orangelight: '#ff6600',
156
+ orangedark: '#c59600',
157
+
158
+ red: '#cc1212',
159
+ redlight: '#f30707',
160
+ reddark: '#8E111C',
161
+
162
+ yellow: '#d1d432',
163
+ };
164
+ ```
@@ -0,0 +1,63 @@
1
+ import { AppMode } from '@athoscommerce/snap-toolbox';
2
+ export type LoggerConfig = {
3
+ prefix?: string;
4
+ mode?: keyof typeof AppMode | AppMode;
5
+ };
6
+ export declare class Logger {
7
+ private mode;
8
+ emoji: {
9
+ bang: string;
10
+ bright: string;
11
+ check: string;
12
+ clock: string;
13
+ cloud: string;
14
+ dim: string;
15
+ gear: string;
16
+ interobang: string;
17
+ lightning: string;
18
+ magic: string;
19
+ rocket: string;
20
+ search: string;
21
+ snap: string;
22
+ ufo: string;
23
+ vortex: string;
24
+ warning: string;
25
+ };
26
+ colors: {
27
+ blue: string;
28
+ bluelight: string;
29
+ bluedark: string;
30
+ bluegreen: string;
31
+ grey: string;
32
+ green: string;
33
+ greendark: string;
34
+ greenblue: string;
35
+ indigo: string;
36
+ orange: string;
37
+ orangelight: string;
38
+ orangedark: string;
39
+ red: string;
40
+ redlight: string;
41
+ reddark: string;
42
+ yellow: string;
43
+ };
44
+ private prefix;
45
+ constructor(config?: LoggerConfig);
46
+ setNamespace(group: string): void;
47
+ error(...params: any[]): void;
48
+ warn(...params: any[]): void;
49
+ image({ url, width, height }: {
50
+ url: string;
51
+ width: number | string;
52
+ height: number | string;
53
+ }, ...params: any[]): void;
54
+ imageText({ url, text, style }: {
55
+ url: string;
56
+ text: string;
57
+ style: string;
58
+ }, ...params: any[]): void;
59
+ debug(...params: any[]): void;
60
+ profile(profile: any, ...params: any[]): void;
61
+ dev(...params: any[]): void;
62
+ }
63
+ //# sourceMappingURL=Logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAItD,MAAM,MAAM,YAAY,GAAG;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,OAAO,OAAO,GAAG,OAAO,CAAC;CACtC,CAAC;AAEF,qBAAa,MAAM;IAClB,OAAO,CAAC,IAAI,CAAsB;IAC3B,KAAK;;;;;;;;;;;;;;;;;MAAS;IACd,MAAM;;;;;;;;;;;;;;;;;MAAU;IACvB,OAAO,CAAC,MAAM,CAAM;gBAER,MAAM,CAAC,EAAE,YAAY;IAK1B,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIjC,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,GAAG,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IASvH,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"}
@@ -0,0 +1,111 @@
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.Logger = void 0;
13
+ var snap_toolbox_1 = require("@athoscommerce/snap-toolbox");
14
+ var colors_1 = require("./colors");
15
+ var emoji_1 = require("./emoji");
16
+ var Logger = /** @class */ (function () {
17
+ function Logger(config) {
18
+ this.mode = snap_toolbox_1.AppMode.production;
19
+ this.emoji = emoji_1.emoji;
20
+ this.colors = colors_1.colors;
21
+ this.prefix = '';
22
+ this.prefix = (config === null || config === void 0 ? void 0 : config.prefix) || '';
23
+ this.mode = ((config === null || config === void 0 ? void 0 : config.mode) || snap_toolbox_1.AppMode.production);
24
+ }
25
+ Logger.prototype.setNamespace = function (group) {
26
+ this.prefix = " [".concat(group, "] :: ");
27
+ };
28
+ Logger.prototype.error = function () {
29
+ var params = [];
30
+ for (var _i = 0; _i < arguments.length; _i++) {
31
+ params[_i] = arguments[_i];
32
+ }
33
+ var text = '';
34
+ var rest = params;
35
+ if (params.length && typeof params[0] == 'string') {
36
+ text = params[0], rest = params.slice(1);
37
+ }
38
+ 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));
39
+ };
40
+ Logger.prototype.warn = function () {
41
+ var params = [];
42
+ for (var _i = 0; _i < arguments.length; _i++) {
43
+ params[_i] = arguments[_i];
44
+ }
45
+ var text = '';
46
+ var rest = params;
47
+ if (params.length && typeof params[0] == 'string') {
48
+ text = params[0], rest = params.slice(1);
49
+ }
50
+ 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));
51
+ };
52
+ Logger.prototype.image = function (_a) {
53
+ var url = _a.url, width = _a.width, height = _a.height;
54
+ var params = [];
55
+ for (var _i = 1; _i < arguments.length; _i++) {
56
+ params[_i - 1] = arguments[_i];
57
+ }
58
+ var styles = {
59
+ size: "font-size: 1px; padding: ".concat(height || width, " ").concat(width || height, ";"),
60
+ background: "background: url(\"".concat(url, "\") no-repeat; background-size: contain;"),
61
+ };
62
+ this.dev.apply(this, __spreadArray(["%c...", "".concat(styles.size, " ").concat(styles.background)], params, false));
63
+ };
64
+ Logger.prototype.imageText = function (_a) {
65
+ var url = _a.url, _b = _a.text, text = _b === void 0 ? '' : _b, style = _a.style;
66
+ var params = [];
67
+ for (var _i = 1; _i < arguments.length; _i++) {
68
+ params[_i - 1] = arguments[_i];
69
+ }
70
+ var styles = {
71
+ background: "margin-left: 6px; background: url(\"".concat(url, "\") no-repeat; background-size: contain;"),
72
+ custom: style,
73
+ };
74
+ var imgText = text;
75
+ var rest = params;
76
+ if (!imgText && (params === null || params === void 0 ? void 0 : params.length)) {
77
+ imgText = params[0], rest = params.slice(1);
78
+ }
79
+ this.dev.apply(this, __spreadArray(["%c ".concat(' ' + this.prefix).concat(imgText), "".concat(styles.background, " ").concat(styles.custom)], rest, false));
80
+ };
81
+ Logger.prototype.debug = function () {
82
+ var params = [];
83
+ for (var _i = 0; _i < arguments.length; _i++) {
84
+ params[_i] = arguments[_i];
85
+ }
86
+ var text = '';
87
+ var rest = params;
88
+ if (params.length && typeof params[0] == 'string') {
89
+ text = params[0], rest = params.slice(1);
90
+ }
91
+ 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));
92
+ };
93
+ Logger.prototype.profile = function (profile) {
94
+ var params = [];
95
+ for (var _i = 1; _i < arguments.length; _i++) {
96
+ params[_i - 1] = arguments[_i];
97
+ }
98
+ 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));
99
+ };
100
+ Logger.prototype.dev = function () {
101
+ var params = [];
102
+ for (var _i = 0; _i < arguments.length; _i++) {
103
+ params[_i] = arguments[_i];
104
+ }
105
+ if (this.mode === snap_toolbox_1.AppMode.development) {
106
+ console.log.apply(console, params);
107
+ }
108
+ };
109
+ return Logger;
110
+ }());
111
+ exports.Logger = Logger;
@@ -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, LoggerConfig } 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,YAAY,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emoji = exports.colors = exports.Logger = void 0;
4
+ var Logger_1 = require("./Logger");
5
+ Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return Logger_1.Logger; } });
6
+ var colors_1 = require("./colors");
7
+ Object.defineProperty(exports, "colors", { enumerable: true, get: function () { return colors_1.colors; } });
8
+ var emoji_1 = require("./emoji");
9
+ Object.defineProperty(exports, "emoji", { enumerable: true, get: function () { return emoji_1.emoji; } });
@@ -0,0 +1,63 @@
1
+ import { AppMode } from '@athoscommerce/snap-toolbox';
2
+ export type LoggerConfig = {
3
+ prefix?: string;
4
+ mode?: keyof typeof AppMode | AppMode;
5
+ };
6
+ export declare class Logger {
7
+ private mode;
8
+ emoji: {
9
+ bang: string;
10
+ bright: string;
11
+ check: string;
12
+ clock: string;
13
+ cloud: string;
14
+ dim: string;
15
+ gear: string;
16
+ interobang: string;
17
+ lightning: string;
18
+ magic: string;
19
+ rocket: string;
20
+ search: string;
21
+ snap: string;
22
+ ufo: string;
23
+ vortex: string;
24
+ warning: string;
25
+ };
26
+ colors: {
27
+ blue: string;
28
+ bluelight: string;
29
+ bluedark: string;
30
+ bluegreen: string;
31
+ grey: string;
32
+ green: string;
33
+ greendark: string;
34
+ greenblue: string;
35
+ indigo: string;
36
+ orange: string;
37
+ orangelight: string;
38
+ orangedark: string;
39
+ red: string;
40
+ redlight: string;
41
+ reddark: string;
42
+ yellow: string;
43
+ };
44
+ private prefix;
45
+ constructor(config?: LoggerConfig);
46
+ setNamespace(group: string): void;
47
+ error(...params: any[]): void;
48
+ warn(...params: any[]): void;
49
+ image({ url, width, height }: {
50
+ url: string;
51
+ width: number | string;
52
+ height: number | string;
53
+ }, ...params: any[]): void;
54
+ imageText({ url, text, style }: {
55
+ url: string;
56
+ text: string;
57
+ style: string;
58
+ }, ...params: any[]): void;
59
+ debug(...params: any[]): void;
60
+ profile(profile: any, ...params: any[]): void;
61
+ dev(...params: any[]): void;
62
+ }
63
+ //# sourceMappingURL=Logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAItD,MAAM,MAAM,YAAY,GAAG;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,OAAO,OAAO,GAAG,OAAO,CAAC;CACtC,CAAC;AAEF,qBAAa,MAAM;IAClB,OAAO,CAAC,IAAI,CAAsB;IAC3B,KAAK;;;;;;;;;;;;;;;;;MAAS;IACd,MAAM;;;;;;;;;;;;;;;;;MAAU;IACvB,OAAO,CAAC,MAAM,CAAM;gBAER,MAAM,CAAC,EAAE,YAAY;IAK1B,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIjC,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,GAAG,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;IASvH,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"}
@@ -0,0 +1,67 @@
1
+ import { AppMode } from '@athoscommerce/snap-toolbox';
2
+ import { colors } from './colors';
3
+ import { emoji } from './emoji';
4
+ export class Logger {
5
+ constructor(config) {
6
+ this.mode = AppMode.production;
7
+ this.emoji = emoji;
8
+ this.colors = colors;
9
+ this.prefix = '';
10
+ this.prefix = config?.prefix || '';
11
+ this.mode = (config?.mode || AppMode.production);
12
+ }
13
+ setNamespace(group) {
14
+ this.prefix = ` [${group}] :: `;
15
+ }
16
+ error(...params) {
17
+ let text = '';
18
+ let rest = params;
19
+ if (params.length && typeof params[0] == 'string') {
20
+ [text, ...rest] = params;
21
+ }
22
+ 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);
23
+ }
24
+ warn(...params) {
25
+ let text = '';
26
+ let rest = params;
27
+ if (params.length && typeof params[0] == 'string') {
28
+ [text, ...rest] = params;
29
+ }
30
+ 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);
31
+ }
32
+ image({ url, width, height }, ...params) {
33
+ const styles = {
34
+ size: `font-size: 1px; padding: ${height || width} ${width || height};`,
35
+ background: `background: url("${url}") no-repeat; background-size: contain;`,
36
+ };
37
+ this.dev(`%c...`, `${styles.size} ${styles.background}`, ...params);
38
+ }
39
+ imageText({ url, text = '', style }, ...params) {
40
+ const styles = {
41
+ background: `margin-left: 6px; background: url("${url}") no-repeat; background-size: contain;`,
42
+ custom: style,
43
+ };
44
+ let imgText = text;
45
+ let rest = params;
46
+ if (!imgText && params?.length) {
47
+ [imgText, ...rest] = params;
48
+ }
49
+ this.dev(`%c ${' ' + this.prefix}${imgText}`, `${styles.background} ${styles.custom}`, ...rest);
50
+ }
51
+ debug(...params) {
52
+ let text = '';
53
+ let rest = params;
54
+ if (params.length && typeof params[0] == 'string') {
55
+ [text, ...rest] = params;
56
+ }
57
+ 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);
58
+ }
59
+ profile(profile, ...params) {
60
+ 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);
61
+ }
62
+ dev(...params) {
63
+ if (this.mode === AppMode.development) {
64
+ console.log(...params);
65
+ }
66
+ }
67
+ }
@@ -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, LoggerConfig } 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,YAAY,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { Logger } from './Logger';
2
+ export { colors } from './colors';
3
+ export { emoji } from './emoji';
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@athoscommerce/snap-logger",
3
+ "version": "1.0.0",
4
+ "description": "Snap Logger",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "author": "Athos Commerce",
8
+ "license": "MIT",
9
+ "repository": "https://github.com/athoscommerce/snap",
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "scripts": {
14
+ "build": "rm -rf ./dist && rm -fr ./components/dist && tsc & p1=$!; tsc -p tsconfig.cjs.json & p2=$!; wait $p1 && wait $p2",
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
+ "dependencies": {
23
+ "@athoscommerce/snap-toolbox": "1.0.0"
24
+ },
25
+ "sideEffects": false,
26
+ "files": [
27
+ "dist/**/*"
28
+ ],
29
+ "gitHead": "714fb2d140d44581a559a6025310f8df9e33e216"
30
+ }