hermodlog 1.8.1 → 1.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermodlog",
3
- "version": "1.8.1",
3
+ "version": "1.9.0",
4
4
  "description": "Simple contextual logger to simplify log display in heavy load context and provide easy parsing",
5
5
  "main": "src/Logger.js",
6
6
  "type": "module",
package/src/Logger.js CHANGED
@@ -14,6 +14,7 @@ import warn from "./methods/warn.js";
14
14
  import fatal from "./methods/fatal.js";
15
15
  import child from "./methods/child.js";
16
16
  import submethod from "./methods/submethod.js";
17
+ import submodule from "./methods/submodule.js";
17
18
 
18
19
  import LOG_COLORS from "./LOG_COLORS.js";
19
20
  import object from "./methods/object.js";
@@ -60,6 +61,11 @@ class Logger {
60
61
  writable: true,
61
62
  enumerable: true
62
63
  },
64
+ submoduleName: {
65
+ value: props.submoduleName ?? null,
66
+ writable: true,
67
+ enumerable: true
68
+ },
63
69
  submethodName: {
64
70
  value: props.submethodName ?? null,
65
71
  writable: true,
@@ -99,6 +105,7 @@ class Logger {
99
105
  const keepMethod = opts?.keepMethod ?? true;
100
106
  const keepModule = opts?.keepModule ?? true;
101
107
  const keepSubmethod = opts?.keepSubmethod ?? true;
108
+ const keepSubmodule = opts?.keepSubmodule ?? true;
102
109
  const keepListener = opts?.keepListener ?? true;
103
110
  const keepObject = opts?.keepObject ?? true;
104
111
 
@@ -110,6 +117,7 @@ class Logger {
110
117
  contextName: (keepContext) ? this.contextName : opts.contextName ?? null,
111
118
  methodName: (keepMethod) ? this.methodName : opts.methodName ?? null,
112
119
  moduleName: (keepModule) ? this.moduleName : opts.moduleName ?? null,
120
+ submoduleName: (keepSubmodule) ? this.submoduleName : opts.submoduleName ?? null,
113
121
  listenerName: (keepListener) ? this.listenerName : opts.listenerName ?? null,
114
122
  submethodName: (keepSubmethod) ? this.submethodName : opts.submethodName ?? null,
115
123
  objectName: (keepObject) ? this.objectName : opts.objectName ?? null,
@@ -156,6 +164,7 @@ Logger.prototype.log = log;
156
164
  Logger.prototype.method = method;
157
165
  Logger.prototype.object = object;
158
166
  Logger.prototype.submethod = submethod;
167
+ Logger.prototype.submodule = submodule;
159
168
  Logger.prototype.module = module;
160
169
  Logger.prototype.trace = trace;
161
170
  Logger.prototype.warn = warn;
@@ -1,5 +1,3 @@
1
- import Logger from "../Logger.js";
2
-
3
1
  export default function submethod(_submethod) {
4
2
  const logger = this.clone();
5
3
  logger.submethodName = _submethod;
@@ -0,0 +1,6 @@
1
+ export default function submodule(_submodule) {
2
+ const logger = this.clone();
3
+ logger.submoduleName = _submodule;
4
+ logger._log = this._log.bind(logger);
5
+ return logger;
6
+ }
package/src/utils/log.js CHANGED
@@ -37,11 +37,12 @@ export default function log(level, args, context) {
37
37
  const hasListener = !!context.listenerName;
38
38
  const hasMethod = !!context.methodName;
39
39
  const hasSubmethod = !!context.submethodName;
40
+ const hasSubmodule = !!context.submoduleName;
40
41
  const hasObject = !!context.objectName;
41
42
 
42
43
  if (hasContext) {
43
44
  message += ` context: ${colors[2](context.contextName)}`;
44
- const hasNext = hasModule || hasListener || hasMethod || hasSubmethod;
45
+ const hasNext = hasModule || hasListener || hasMethod || hasSubmethod || hasSubmodule;
45
46
  if (hasNext) {
46
47
  message += ' |';
47
48
  }
@@ -49,6 +50,14 @@ export default function log(level, args, context) {
49
50
 
50
51
  if (hasModule) {
51
52
  message += ` module:${colors[3](context.moduleName)}`;
53
+ const hasNext = hasListener || hasMethod || hasSubmethod || hasSubmodule;
54
+ if (hasNext) {
55
+ message += ' |';
56
+ }
57
+ }
58
+
59
+ if (hasSubmodule) {
60
+ message += ` submodule: ${colors[6](context.submoduleName)}`;
52
61
  const hasNext = hasListener || hasMethod || hasSubmethod;
53
62
  if (hasNext) {
54
63
  message += ' |';
@@ -57,7 +66,7 @@ export default function log(level, args, context) {
57
66
 
58
67
  if (hasMethod) {
59
68
  message += ` method: ${colors[5](context.methodName)}`;
60
- const hasNext = hasSubmethod;
69
+ const hasNext = hasSubmethod || hasSubmodule;
61
70
  if (hasNext) {
62
71
  message += ' |';
63
72
  }
@@ -65,7 +74,7 @@ export default function log(level, args, context) {
65
74
 
66
75
  if (hasSubmethod) {
67
76
  message += ` submethod: ${colors[6](context.submethodName)}`;
68
- const hasNext = hasListener || hasMethod;
77
+ const hasNext = hasListener || hasMethod || hasSubmodule;
69
78
  if (hasNext) {
70
79
  message += ' |';
71
80
  }
package/usage.example.js CHANGED
@@ -40,4 +40,7 @@ el.log(8);
40
40
  el.log(9);
41
41
  el.log(10);
42
42
 
43
- console.log(el.getHistory(2,{fromDate: new Date('2025-10-08T02:52:20')}));
43
+ console.log(el.getHistory(2,{fromDate: new Date('2025-10-08T02:52:20')}));
44
+
45
+
46
+ el.submodule('submodule1').log('submodule1');