@rife/logger 0.0.6-beta.12 → 0.0.6-beta.13

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.
@@ -0,0 +1,74 @@
1
+ import "node:module";
2
+ import pino from "pino";
3
+ import path from "path";
4
+ import { getTraceId } from "../trace.mjs";
5
+ import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
6
+ var worker_filename = __rspack_fileURLToPath(import.meta.url);
7
+ function getPinoConfig() {
8
+ const targets = [];
9
+ if ('production' === process.env.NODE_ENV) ;
10
+ else {
11
+ const rotate = `./rotate${path.extname(worker_filename)}`;
12
+ targets.push({
13
+ level: 'debug',
14
+ target: rotate,
15
+ options: {
16
+ path: './logs/'
17
+ }
18
+ });
19
+ targets.push({
20
+ level: 'debug',
21
+ target: 'pino-pretty',
22
+ options: {
23
+ ignore: 'pid',
24
+ messageKey: 'message'
25
+ }
26
+ });
27
+ }
28
+ const config = {
29
+ transport: {
30
+ targets
31
+ },
32
+ mixin (data) {
33
+ const traceId = data?.traceId;
34
+ delete data.traceId;
35
+ delete data.level;
36
+ delete data.time;
37
+ delete data.pid;
38
+ delete data.name;
39
+ delete data.hostname;
40
+ if (!traceId) return {
41
+ traceId: getTraceId()
42
+ };
43
+ return {
44
+ traceId
45
+ };
46
+ },
47
+ browser: {
48
+ write: (o)=>{
49
+ const { name, time, level, ...rest } = o;
50
+ if (name) rest.message = rest.message ? `[${name}] ${rest.message}` : `[${name}]`;
51
+ if (!rest.traceId) rest.traceId = getTraceId();
52
+ if (level >= 50) console.error(rest);
53
+ else if (level >= 40) console.warn(rest);
54
+ else console.log(rest);
55
+ }
56
+ }
57
+ };
58
+ return config;
59
+ }
60
+ function createLogger() {
61
+ const logger = pino({
62
+ base: {
63
+ pid: process.pid
64
+ },
65
+ messageKey: 'message',
66
+ errorKey: 'error',
67
+ timestamp: pino.stdTimeFunctions.epochTime,
68
+ ...getPinoConfig()
69
+ });
70
+ return {
71
+ logger
72
+ };
73
+ }
74
+ export { createLogger };
@@ -0,0 +1,19 @@
1
+ import "node:module";
2
+ var __webpack_modules__ = {};
3
+ var __webpack_module_cache__ = {};
4
+ function __webpack_require__(moduleId) {
5
+ var cachedModule = __webpack_module_cache__[moduleId];
6
+ if (void 0 !== cachedModule) return cachedModule.exports;
7
+ var module = __webpack_module_cache__[moduleId] = {
8
+ exports: {}
9
+ };
10
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
11
+ return module.exports;
12
+ }
13
+ __webpack_require__.m = __webpack_modules__;
14
+ (()=>{
15
+ __webpack_require__.add = function(modules) {
16
+ Object.assign(__webpack_require__.m, modules);
17
+ };
18
+ })();
19
+ export { __webpack_require__ };
package/dist/esm/test.mjs CHANGED
@@ -1,9 +1,8 @@
1
- import 'module';
2
- /*#__PURE__*/ import.meta.url;
1
+ import "node:module";
3
2
  import { createLogger } from "./pino/index.mjs";
4
3
  import { genTraceId, runInTrace } from "./trace.mjs";
5
4
  process.env.NODE_ENV = 'development';
6
- const { logger } = createLogger();
5
+ const { logger: logger } = createLogger();
7
6
  logger.info({
8
7
  a: 999
9
8
  }, '1');
@@ -1,5 +1,4 @@
1
- import 'module';
2
- /*#__PURE__*/ import.meta.url;
1
+ import "node:module";
3
2
  import { AsyncLocalStorage } from "async_hooks";
4
3
  const als = new AsyncLocalStorage();
5
4
  function runInTrace(data, fn) {
@@ -0,0 +1 @@
1
+ import "node:module";