@nu-art/commando 0.204.96 → 0.204.98

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": "@nu-art/commando",
3
- "version": "0.204.96",
3
+ "version": "0.204.98",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Constructor } from '@nu-art/ts-common';
2
+ import { Constructor, LogLevel } from '@nu-art/ts-common';
3
3
  import { LogTypes } from '../types';
4
4
  import { BaseCommando } from '../core/BaseCommando';
5
5
  export declare class CommandoInteractive extends BaseCommando {
@@ -68,6 +68,7 @@ export declare class CommandoInteractive extends BaseCommando {
68
68
  * @returns {this} - The CommandoInteractive instance for method chaining.
69
69
  */
70
70
  addLogProcessor(processor: (log: string, std: LogTypes) => boolean): this;
71
+ setLogLevelFilter(processor: (log: string, std: LogTypes) => LogLevel): this;
71
72
  /**
72
73
  * Removes a log processor from the shell.
73
74
  * @param {Function} processor - The log processor function to remove.
@@ -71,14 +71,14 @@ class CommandoInteractive extends BaseCommando_1.BaseCommando {
71
71
  */
72
72
  onLog(filter, callback) {
73
73
  const regexp = typeof filter === 'string' ? new RegExp(filter) : filter;
74
- const pidLogProcessor = (log) => {
74
+ const logFilter = (log) => {
75
75
  const match = log.match(regexp);
76
76
  if (!match)
77
77
  return true;
78
78
  callback(match);
79
79
  return true;
80
80
  };
81
- this.addLogProcessor(pidLogProcessor);
81
+ this.addLogProcessor(logFilter);
82
82
  return this;
83
83
  }
84
84
  /**
@@ -154,6 +154,10 @@ class CommandoInteractive extends BaseCommando_1.BaseCommando {
154
154
  this.shell.addLogProcessor(processor);
155
155
  return this;
156
156
  }
157
+ setLogLevelFilter(processor) {
158
+ this.shell.setLogLevelFilter(processor);
159
+ return this;
160
+ }
157
161
  /**
158
162
  * Removes a log processor from the shell.
159
163
  * @param {Function} processor - The log processor function to remove.
@@ -4,7 +4,7 @@
4
4
  /// <reference types="node" />
5
5
  /// <reference types="node" />
6
6
  /// <reference types="node" />
7
- import { Logger } from '@nu-art/ts-common';
7
+ import { Logger, LogLevel } from '@nu-art/ts-common';
8
8
  import { LogTypes } from '../types';
9
9
  type LogProcessor = (log: string, std: LogTypes) => boolean;
10
10
  export declare class InteractiveShell extends Logger {
@@ -12,6 +12,7 @@ export declare class InteractiveShell extends Logger {
12
12
  private logProcessors;
13
13
  private shell;
14
14
  private alive;
15
+ private logLevelFilter;
15
16
  /**
16
17
  * Constructs an InteractiveShell instance, initializes a detached shell session, and sets up log processors.
17
18
  */
@@ -49,6 +50,7 @@ export declare class InteractiveShell extends Logger {
49
50
  * @returns {this} - The InteractiveShell instance for method chaining.
50
51
  */
51
52
  addLogProcessor(processor: LogProcessor): this;
53
+ setLogLevelFilter(logLevelFilter: (log: string, std: LogTypes) => LogLevel): this;
52
54
  /**
53
55
  * Removes a log processor from handling log messages.
54
56
  * @param {(log: string, std: LogTypes) => boolean} processor - The log processor function to remove.
@@ -12,6 +12,7 @@ class InteractiveShell extends ts_common_1.Logger {
12
12
  super();
13
13
  this._debug = false;
14
14
  this.logProcessors = [];
15
+ this.logLevelFilter = (log, std) => std === 'err' ? ts_common_1.LogLevel.Error : ts_common_1.LogLevel.Info;
15
16
  /**
16
17
  * Executes a command in the interactive shell.
17
18
  * @param {string} command - The command to execute.
@@ -85,11 +86,10 @@ class InteractiveShell extends ts_common_1.Logger {
85
86
  const filter = processor(message, std);
86
87
  return toPrint && filter;
87
88
  }, true);
88
- if (toPrint)
89
- if (std === 'out')
90
- this.logInfo(`${message}`);
91
- else
92
- this.logError(`${message}`);
89
+ if (toPrint) {
90
+ const logLevel = this.logLevelFilter(message, std);
91
+ this.log(logLevel, false, [message]);
92
+ }
93
93
  }
94
94
  catch (e) {
95
95
  this.logError(e);
@@ -122,6 +122,10 @@ class InteractiveShell extends ts_common_1.Logger {
122
122
  this.logProcessors.push(processor);
123
123
  return this;
124
124
  }
125
+ setLogLevelFilter(logLevelFilter) {
126
+ this.logLevelFilter = logLevelFilter;
127
+ return this;
128
+ }
125
129
  /**
126
130
  * Removes a log processor from handling log messages.
127
131
  * @param {(log: string, std: LogTypes) => boolean} processor - The log processor function to remove.