w-syslog 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.
Files changed (56) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.js +55 -0
  4. package/.github/workflows/ci-test.yml +24 -0
  5. package/.jsdoc +25 -0
  6. package/LICENSE +21 -0
  7. package/README.md +120 -0
  8. package/SECURITY.md +5 -0
  9. package/babel.config.js +16 -0
  10. package/dist/formatter.umd.js +7 -0
  11. package/dist/formatter.umd.js.map +1 -0
  12. package/dist/w-syslog.umd.js +7 -0
  13. package/dist/w-syslog.umd.js.map +1 -0
  14. package/docs/WSyslog.html +362 -0
  15. package/docs/WSyslog.mjs.html +165 -0
  16. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  17. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  18. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  19. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  20. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  21. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  22. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  23. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  24. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  25. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  26. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  27. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  28. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  29. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  30. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  31. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  32. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  33. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  34. package/docs/index.html +84 -0
  35. package/docs/scripts/collapse.js +39 -0
  36. package/docs/scripts/commonNav.js +28 -0
  37. package/docs/scripts/linenumber.js +25 -0
  38. package/docs/scripts/nav.js +12 -0
  39. package/docs/scripts/polyfill.js +4 -0
  40. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  41. package/docs/scripts/prettify/lang-css.js +2 -0
  42. package/docs/scripts/prettify/prettify.js +28 -0
  43. package/docs/scripts/search.js +99 -0
  44. package/docs/styles/jsdoc.css +776 -0
  45. package/docs/styles/prettify.css +80 -0
  46. package/g.mjs +27 -0
  47. package/logs/2025-07-06.log +4 -0
  48. package/package.json +32 -0
  49. package/script.txt +18 -0
  50. package/src/WSyslog.mjs +93 -0
  51. package/src/formatter.mjs +77 -0
  52. package/test/WSyslog.test.mjs +50 -0
  53. package/toolg/addVersion.mjs +4 -0
  54. package/toolg/cleanFolder.mjs +4 -0
  55. package/toolg/gDistRollup.mjs +23 -0
  56. package/toolg/modifyReadme.mjs +4 -0
@@ -0,0 +1,362 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+
5
+ <meta charset="utf-8">
6
+ <title>WSyslog - Documentation</title>
7
+
8
+
9
+ <script src="scripts/prettify/prettify.js"></script>
10
+ <script src="scripts/prettify/lang-css.js"></script>
11
+ <!--[if lt IE 9]>
12
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
13
+ <![endif]-->
14
+ <link type="text/css" rel="stylesheet" href="styles/prettify.css">
15
+ <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
16
+ <script src="scripts/nav.js" defer></script>
17
+
18
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
19
+ </head>
20
+ <body>
21
+
22
+ <input type="checkbox" id="nav-trigger" class="nav-trigger" />
23
+ <label for="nav-trigger" class="navicon-button x">
24
+ <div class="navicon"></div>
25
+ </label>
26
+
27
+ <label for="nav-trigger" class="overlay"></label>
28
+
29
+ <nav >
30
+
31
+
32
+ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WSyslog.html">WSyslog</a></li></ul>
33
+
34
+ </nav>
35
+
36
+ <div id="main">
37
+
38
+ <h1 class="page-title">WSyslog</h1>
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ <section>
47
+
48
+ <header>
49
+
50
+ <h2>
51
+
52
+ WSyslog
53
+
54
+ </h2>
55
+
56
+
57
+ </header>
58
+
59
+ <article>
60
+
61
+ <div class="container-overview">
62
+
63
+
64
+
65
+
66
+
67
+ <h4 class="name" id="WSyslog"><span class="type-signature type-signature-async">(async) </span>new WSyslog<span class="signature">(opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Object}</span></h4>
68
+
69
+
70
+
71
+
72
+
73
+
74
+ <dl class="details">
75
+
76
+ <dt class="tag-description">Description:</dt>
77
+ <dd class="tag-description"><ul class="dummy"><li><p>輸出log</p></li></ul></dd>
78
+
79
+
80
+
81
+ <dt class="tag-source">Source:</dt>
82
+ <dd class="tag-source"><ul class="dummy"><li>
83
+ <a href="WSyslog.mjs.html">WSyslog.mjs</a>, <a href="WSyslog.mjs.html#line47">line 47</a>
84
+ </li></ul></dd>
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
+ </dl>
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+ <h5 class="h5-examples">Example</h5>
129
+
130
+ <pre class="prettyprint"><code>import fs from 'fs'
131
+
132
+
133
+
134
+
135
+ <h5 class="h5-parameters">Parameters:</h5>
136
+
137
+
138
+ <table class="params">
139
+ <thead>
140
+ <tr>
141
+
142
+ <th>Name</th>
143
+
144
+
145
+ <th>Type</th>
146
+
147
+
148
+ <th>Attributes</th>
149
+
150
+
151
+
152
+ <th>Default</th>
153
+
154
+
155
+ <th class="last">Description</th>
156
+ </tr>
157
+ </thead>
158
+
159
+ <tbody>
160
+
161
+
162
+ <tr>
163
+
164
+ <td class="name"><code>opt</code></td>
165
+
166
+
167
+ <td class="type">
168
+
169
+
170
+ <span class="param-type">Object</span>
171
+
172
+
173
+
174
+
175
+ </td>
176
+
177
+
178
+ <td class="attributes">
179
+
180
+ &lt;optional><br>
181
+
182
+
183
+
184
+
185
+
186
+ </td>
187
+
188
+
189
+
190
+ <td class="default">
191
+
192
+ <code>{}</code>
193
+
194
+ </td>
195
+
196
+
197
+ <td class="description last"><p>輸入設定物件,預設{}</p>
198
+ <h6>Properties</h6>
199
+
200
+
201
+ <table class="params">
202
+ <thead>
203
+ <tr>
204
+
205
+ <th>Name</th>
206
+
207
+
208
+ <th>Type</th>
209
+
210
+
211
+ <th>Attributes</th>
212
+
213
+
214
+
215
+ <th>Default</th>
216
+
217
+
218
+ <th class="last">Description</th>
219
+ </tr>
220
+ </thead>
221
+
222
+ <tbody>
223
+
224
+
225
+ <tr>
226
+
227
+ <td class="name"><code>timeCpuUsage</code></td>
228
+
229
+
230
+ <td class="type">
231
+
232
+
233
+ <span class="param-type">String</span>
234
+
235
+
236
+
237
+
238
+ </td>
239
+
240
+
241
+ <td class="attributes">
242
+
243
+ &lt;optional><br>
244
+
245
+
246
+
247
+
248
+
249
+ </td>
250
+
251
+
252
+
253
+ <td class="default">
254
+
255
+ <code>200</code>
256
+
257
+ </td>
258
+
259
+
260
+ <td class="description last"><p>輸入偵測CPU使用率時取樣時間數字,單位ms,預設200</p></td>
261
+ </tr>
262
+
263
+
264
+ </tbody>
265
+ </table>
266
+
267
+ </td>
268
+ </tr>
269
+
270
+
271
+ </tbody>
272
+ </table>
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+ <h5 class="h5-returns">Returns:</h5>
290
+
291
+
292
+ <div class="param-desc">
293
+ <p>回傳事件物件</p>
294
+ </div>
295
+
296
+
297
+
298
+ <dl class="param-type">
299
+ <dt>
300
+ Type
301
+ </dt>
302
+ <dd>
303
+
304
+ <span class="param-type">Object</span>
305
+
306
+
307
+
308
+ </dd>
309
+ </dl>
310
+
311
+
312
+
313
+
314
+
315
+
316
+ </div>
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+ </article>
339
+
340
+ </section>
341
+
342
+
343
+
344
+
345
+
346
+
347
+ </div>
348
+
349
+ <br class="clear">
350
+
351
+ <footer>
352
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Sun Jul 06 2025 13:38:25 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
353
+ </footer>
354
+
355
+ <script>prettyPrint();</script>
356
+ <script src="scripts/polyfill.js"></script>
357
+ <script src="scripts/linenumber.js"></script>
358
+
359
+
360
+
361
+ </body>
362
+ </html>
@@ -0,0 +1,165 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+
5
+ <meta charset="utf-8">
6
+ <title>WSyslog.mjs - Documentation</title>
7
+
8
+
9
+ <script src="scripts/prettify/prettify.js"></script>
10
+ <script src="scripts/prettify/lang-css.js"></script>
11
+ <!--[if lt IE 9]>
12
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
13
+ <![endif]-->
14
+ <link type="text/css" rel="stylesheet" href="styles/prettify.css">
15
+ <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
16
+ <script src="scripts/nav.js" defer></script>
17
+
18
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
19
+ </head>
20
+ <body>
21
+
22
+ <input type="checkbox" id="nav-trigger" class="nav-trigger" />
23
+ <label for="nav-trigger" class="navicon-button x">
24
+ <div class="navicon"></div>
25
+ </label>
26
+
27
+ <label for="nav-trigger" class="overlay"></label>
28
+
29
+ <nav >
30
+
31
+
32
+ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WSyslog.html">WSyslog</a></li></ul>
33
+
34
+ </nav>
35
+
36
+ <div id="main">
37
+
38
+ <h1 class="page-title">WSyslog.mjs</h1>
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ <section>
47
+ <article>
48
+ <pre class="prettyprint source linenums"><code>import path from 'path'
49
+ import { fileURLToPath } from 'url'
50
+ import get from 'lodash-es/get.js'
51
+ import isestr from 'wsemi/src/isestr.mjs'
52
+ import pino from 'pino'
53
+
54
+
55
+ // __dirname
56
+ let __filename = fileURLToPath(import.meta.url)
57
+ let __dirname = path.dirname(__filename)
58
+
59
+
60
+ /**
61
+ * 輸出log
62
+ *
63
+ * @class
64
+ * @param {Object} [opt={}] 輸入設定物件,預設{}
65
+ * @param {String} [opt.timeCpuUsage=200] 輸入偵測CPU使用率時取樣時間數字,單位ms,預設200
66
+ * @returns {Object} 回傳事件物件
67
+ * @example
68
+ * import fs from 'fs'
69
+ * import _ from 'lodash-es'
70
+ * import w from 'wsemi'
71
+ * import WSyslog from './src/WSyslog.mjs'
72
+ *
73
+ * w.fsCleanFolder('./logs')
74
+ *
75
+ * let log = await WSyslog()
76
+ * log.info({ event: 'runner', msg: 'start' })
77
+ * log.warn({ event: 'monitor-memory', msg: 'usage-high' })
78
+ * log.error({ event: 'crash', msg: 'db connection', code: 500 })
79
+ *
80
+ * await w.delay(2000) //等待2秒讓pino能flush數據
81
+ *
82
+ * let vpfs = w.fsTreeFolder('./logs')
83
+ * // console.log('vpfs', vpfs)
84
+ *
85
+ * let fp = _.get(vpfs, `0.path`, '')
86
+ *
87
+ * let jj = fs.readFileSync(fp, 'utf8')
88
+ * console.log(jj)
89
+ * // {"level":30,"time":1751780174415,"pid":24144,"hostname":"DESKTOP-6R7USAO","event":"runner","msg":"start"}
90
+ * // {"level":40,"time":1751780174415,"pid":24144,"hostname":"DESKTOP-6R7USAO","event":"monitor-memory","msg":"usage-high"}
91
+ * // {"level":50,"time":1751780174415,"pid":24144,"hostname":"DESKTOP-6R7USAO","event":"crash","msg":"db connection","code":500}
92
+ *
93
+ */
94
+ async function WSyslog(opt = {}) {
95
+
96
+ //fdLog
97
+ let fdLog = get(opt, 'fdLog')
98
+ if (!isestr(fdLog)) {
99
+ fdLog = './logs'
100
+ }
101
+
102
+ //interval
103
+ let interval = get(opt, 'interval')
104
+ if (interval !== 'day' &amp;&amp; interval !== 'hr') {
105
+ interval = 'day'
106
+ }
107
+
108
+ // 建立 logger,使用自訂 transport
109
+ let transport = pino.transport({
110
+ targets: [
111
+ {
112
+
113
+ // fatal: 60
114
+ // error: 50
115
+ // warn: 40
116
+ // info: 30
117
+ // debug: 20
118
+ // trace: 10
119
+ level: 'info', //僅紀錄info(30)以上
120
+
121
+ target: path.resolve(__dirname, './formatter.mjs'),
122
+
123
+ options: {
124
+ interval,
125
+ logDir: fdLog,
126
+ },
127
+
128
+ },
129
+ ]
130
+ })
131
+
132
+ //log
133
+ let log = pino(transport)
134
+ // console.log('log', log)
135
+
136
+ return log
137
+ }
138
+
139
+
140
+ export default WSyslog
141
+ </code></pre>
142
+ </article>
143
+ </section>
144
+
145
+
146
+
147
+
148
+
149
+
150
+ </div>
151
+
152
+ <br class="clear">
153
+
154
+ <footer>
155
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Sun Jul 06 2025 13:38:25 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
156
+ </footer>
157
+
158
+ <script>prettyPrint();</script>
159
+ <script src="scripts/polyfill.js"></script>
160
+ <script src="scripts/linenumber.js"></script>
161
+
162
+
163
+
164
+ </body>
165
+ </html>