@searchspring/snap-logger 0.70.1 → 0.72.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/README.md +42 -127
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,177 +1,92 @@
|
|
|
1
1
|
# Snap Logger
|
|
2
2
|
|
|
3
|
-
|
|
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
4
|
|
|
5
|
-
|
|
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({
|
|
5
|
+
```js
|
|
6
|
+
controller.log.image({
|
|
15
7
|
url: 'https://searchspring.com/wp-content/uploads/2020/01/SearchSpring-Primary-FullColor-800-1-1-640x208.png',
|
|
16
8
|
width: '90px',
|
|
17
9
|
height: '30px'
|
|
18
10
|
});
|
|
19
11
|
|
|
20
|
-
|
|
12
|
+
controller.log.error('error');
|
|
21
13
|
|
|
22
|
-
|
|
14
|
+
controller.log.warn('warn');
|
|
23
15
|
|
|
24
|
-
|
|
16
|
+
controller.log.imageText({
|
|
25
17
|
url: 'https://searchspring.com/wp-content/themes/SearchSpring-Theme/dist/images/favicons/favicon.svg',
|
|
26
18
|
}, 'imageText');
|
|
27
19
|
|
|
28
|
-
|
|
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');
|
|
20
|
+
controller.log.debug('debug');
|
|
85
21
|
|
|
86
|
-
|
|
87
|
-
|
|
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;`);
|
|
88
26
|
```
|
|
89
27
|
|
|
90
|
-
|
|
91
|
-
The default logging mode is `production`.
|
|
28
|
+
## `setMode` method
|
|
29
|
+
The default logging mode is `production`. (Set by Snap config)
|
|
92
30
|
|
|
93
31
|
When set to production, logs using `dev` will not be visible. This also includes `image`, `imageText`, `debug`, and `profile`.
|
|
94
32
|
|
|
95
33
|
When set to `development`, all logging methods will be visible.
|
|
96
34
|
|
|
97
35
|
|
|
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
|
|
36
|
+
## `error` method
|
|
114
37
|
This method takes any number of parameters and logs them to the console. It is best to use this method for error handling.
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
|
|
38
|
+
```js
|
|
39
|
+
controller.log.error('error!!!');
|
|
40
|
+
controller.log.error('text about the error', errorObject, 'more', 'text');
|
|
118
41
|
```
|
|
119
42
|
|
|
120
|
-
|
|
43
|
+
## `warn` method
|
|
121
44
|
This method takes any number of parameters and logs them to the console. It is best to use this method for displaying warnings.
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
|
|
45
|
+
```js
|
|
46
|
+
controller.log.warn('warning!!!');
|
|
47
|
+
controller.log.warn('warning', warningObject, 'more text');
|
|
125
48
|
```
|
|
126
49
|
|
|
127
|
-
|
|
50
|
+
## `dev` method
|
|
128
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.
|
|
129
52
|
|
|
130
|
-
```
|
|
131
|
-
|
|
53
|
+
```js
|
|
54
|
+
controller.log.dev('dev')
|
|
132
55
|
```
|
|
133
56
|
|
|
134
|
-
|
|
57
|
+
## `debug` method
|
|
135
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.
|
|
136
59
|
|
|
137
|
-
```
|
|
138
|
-
|
|
60
|
+
```js
|
|
61
|
+
controller.log.debug('debug');
|
|
139
62
|
```
|
|
140
|
-
|
|
63
|
+
## `image` method
|
|
141
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.
|
|
142
65
|
|
|
143
|
-
```
|
|
144
|
-
|
|
66
|
+
```js
|
|
67
|
+
controller.log.image({
|
|
145
68
|
url: 'https://searchspring.com/wp-content/uploads/2020/01/SearchSpring-Primary-FullColor-800-1-1-640x208.png',
|
|
146
69
|
width: '30px',
|
|
147
70
|
height: '30px'
|
|
148
71
|
});
|
|
149
72
|
```
|
|
150
73
|
|
|
151
|
-
|
|
74
|
+
## `imageText` method
|
|
152
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.
|
|
153
76
|
|
|
154
|
-
```
|
|
155
|
-
|
|
77
|
+
```js
|
|
78
|
+
controller.log.imageText({
|
|
156
79
|
url: 'https://searchspring.com/wp-content/uploads/2020/01/SearchSpring-Primary-FullColor-800-1-1-640x208.png',
|
|
157
80
|
text: `imageText`,
|
|
158
81
|
style: `color: #4c3ce2; font-weight: bold;`,
|
|
159
82
|
});
|
|
160
83
|
```
|
|
161
84
|
|
|
162
|
-
|
|
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();
|
|
85
|
+
## `profile` method
|
|
173
86
|
|
|
174
|
-
|
|
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://searchspring.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({
|
|
175
90
|
type: 'event',
|
|
176
91
|
name: 'search',
|
|
177
92
|
context: {}
|
|
@@ -183,17 +98,17 @@ searchProfile.start();
|
|
|
183
98
|
|
|
184
99
|
searchProfile.stop();
|
|
185
100
|
|
|
186
|
-
|
|
101
|
+
controller.log.profile(searchProfile)
|
|
187
102
|
```
|
|
188
103
|
|
|
189
|
-
|
|
104
|
+
## `emoji` property
|
|
190
105
|
The `emoji` property contains various emojis that can be used
|
|
191
106
|
|
|
192
107
|
The following emojis are available:
|
|
193
108
|
|
|
194
109
|
<img src="https://github.com/searchspring/snap/blob/main/images/emojis.png?raw=true" />
|
|
195
110
|
|
|
196
|
-
```
|
|
111
|
+
```js
|
|
197
112
|
const emoji = {
|
|
198
113
|
bang: String.fromCodePoint(0x203c),
|
|
199
114
|
bright: String.fromCodePoint(0x1f506),
|
|
@@ -214,14 +129,14 @@ const emoji = {
|
|
|
214
129
|
};
|
|
215
130
|
```
|
|
216
131
|
|
|
217
|
-
|
|
132
|
+
## `colors` property
|
|
218
133
|
The `colors` property contains various colors that can be used
|
|
219
134
|
|
|
220
135
|
The following colors are available:
|
|
221
136
|
|
|
222
137
|
<img src="https://github.com/searchspring/snap/blob/main/images/colors.png?raw=true" />
|
|
223
138
|
|
|
224
|
-
```
|
|
139
|
+
```js
|
|
225
140
|
const colors = {
|
|
226
141
|
blue: '#3379c1',
|
|
227
142
|
bluelight: '#688BA3',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@searchspring/snap-logger",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.72.0",
|
|
4
4
|
"description": "Snap Logger",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"test:watch": "jest --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@searchspring/snap-toolbox": "0.
|
|
23
|
+
"@searchspring/snap-toolbox": "0.72.0"
|
|
24
24
|
},
|
|
25
25
|
"sideEffects": false,
|
|
26
26
|
"files": [
|
|
27
27
|
"dist/**/*"
|
|
28
28
|
],
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "737d4bd308ebbb852fe3f09b2b90f4af87bbe264"
|
|
30
30
|
}
|