namirasoft-log 1.4.31 → 1.4.32

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/src/Logger.ts CHANGED
@@ -1,127 +1,127 @@
1
- import { FormatterFull } from "./FormatterFull";
2
- import { IFormatter } from "./IFormatter";
3
- import { ILogger } from "./ILogger";
4
- import { IStream } from "./IStream";
5
- import { Log } from "./Log";
6
- import { LogLevel } from "./LogLevel";
7
- import { StreamConsole } from "./StreamConsole";
8
-
9
- export class Logger implements ILogger
10
- {
11
- static main: Logger | null = null;
12
- private defaultStream: IStream = new StreamConsole();
13
- private formatter?: IFormatter = new FormatterFull();
14
- private customFormatter: { [level: string]: IFormatter } = {};
15
- private streams: IStream[] = [];
16
- constructor()
17
- {
18
- if (Logger.main == null)
19
- Logger.main = this;
20
- this.setFromatter = this.setFromatter.bind(this);
21
- this.setCustomFormatter = this.setCustomFormatter.bind(this);
22
- this.addStream = this.addStream.bind(this);
23
- this.log = this.log.bind(this);
24
- this.trace = this.trace.bind(this);
25
- this.verbose = this.verbose.bind(this);
26
- this.debug = this.debug.bind(this);
27
- this.info = this.info.bind(this);
28
- this.success = this.success.bind(this);
29
- this.warning = this.warning.bind(this);
30
- this.error = this.error.bind(this);
31
- this.critical = this.critical.bind(this);
32
- this.fatal = this.fatal.bind(this);
33
- this.onCatchError = this.onCatchError.bind(this);
34
- this.onCatchCritical = this.onCatchCritical.bind(this);
35
- this.onCatchFatal = this.onCatchFatal.bind(this);
36
- this.getErrorMessage = this.getErrorMessage.bind(this);
37
- this.getErrorStack = this.getErrorStack.bind(this);
38
- this.initUncought = this.initUncought.bind(this);
39
- }
40
- setFromatter(formatter: IFormatter): void
41
- {
42
- this.formatter = formatter;
43
- }
44
- setCustomFormatter(level: LogLevel, formatter: IFormatter): void
45
- {
46
- this.customFormatter[level] = formatter;
47
- }
48
- addStream(stream: IStream)
49
- {
50
- this.streams.push(stream);
51
- }
52
- log(level: LogLevel, ...messages: any[])
53
- {
54
- let log = new Log(level, ...messages);
55
- let formatted: { pre: string[], messages: string[], post: string[] } = { pre: [], messages: [], post: [] };
56
- let formatter = this.customFormatter[level.toString()] ?? this.formatter;
57
- if (formatter)
58
- formatted = formatter.format(log);
59
- if (this.streams.length == 0)
60
- this.defaultStream.write(log, formatted);
61
- else
62
- this.streams.map(s => s.write(log, formatted));
63
- }
64
- trace(...messages: any[])
65
- {
66
- this.log(LogLevel.Trace, ...messages);
67
- }
68
- verbose(...messages: any[])
69
- {
70
- this.log(LogLevel.Verbose, ...messages);
71
- }
72
- debug(...messages: any[])
73
- {
74
- this.log(LogLevel.Debug, ...messages);
75
- }
76
- info(...messages: any[])
77
- {
78
- this.log(LogLevel.Info, ...messages);
79
- }
80
- success(...messages: any[])
81
- {
82
- this.log(LogLevel.Success, ...messages);
83
- }
84
- warning(...messages: any[])
85
- {
86
- this.log(LogLevel.Warning, ...messages);
87
- }
88
- error(...messages: any[])
89
- {
90
- this.log(LogLevel.Error, ...messages);
91
- }
92
- critical(...messages: any[])
93
- {
94
- this.log(LogLevel.Critical, ...messages);
95
- }
96
- fatal(...messages: any[])
97
- {
98
- this.log(LogLevel.Fatal, ...messages);
99
- }
100
- onCatchError(error: Error | unknown)
101
- {
102
- this.error(this.getErrorMessage(error), this.getErrorStack(error));
103
- }
104
- onCatchCritical(error: Error | unknown)
105
- {
106
- this.critical(this.getErrorMessage(error), this.getErrorStack(error));
107
- }
108
- onCatchFatal(error: Error | unknown)
109
- {
110
- this.fatal(this.getErrorMessage(error), this.getErrorStack(error));
111
- }
112
- protected getErrorMessage(error: Error | unknown): string
113
- {
114
- if (error instanceof Error)
115
- return error.message;
116
- return error + "";
117
- }
118
- protected getErrorStack(error: Error | unknown): string
119
- {
120
- if (error instanceof Error)
121
- return error.stack ?? "";
122
- return error + "";
123
- }
124
- initUncought()
125
- {
126
- }
1
+ import { FormatterFull } from "./FormatterFull";
2
+ import { IFormatter } from "./IFormatter";
3
+ import { ILogger } from "./ILogger";
4
+ import { IStream } from "./IStream";
5
+ import { Log } from "./Log";
6
+ import { LogLevel } from "./LogLevel";
7
+ import { StreamConsole } from "./StreamConsole";
8
+
9
+ export class Logger implements ILogger
10
+ {
11
+ static main: Logger | null = null;
12
+ private defaultStream: IStream = new StreamConsole();
13
+ private formatter?: IFormatter = new FormatterFull();
14
+ private customFormatter: { [level: string]: IFormatter } = {};
15
+ private streams: IStream[] = [];
16
+ constructor()
17
+ {
18
+ if (Logger.main == null)
19
+ Logger.main = this;
20
+ this.setFromatter = this.setFromatter.bind(this);
21
+ this.setCustomFormatter = this.setCustomFormatter.bind(this);
22
+ this.addStream = this.addStream.bind(this);
23
+ this.log = this.log.bind(this);
24
+ this.trace = this.trace.bind(this);
25
+ this.verbose = this.verbose.bind(this);
26
+ this.debug = this.debug.bind(this);
27
+ this.info = this.info.bind(this);
28
+ this.success = this.success.bind(this);
29
+ this.warning = this.warning.bind(this);
30
+ this.error = this.error.bind(this);
31
+ this.critical = this.critical.bind(this);
32
+ this.fatal = this.fatal.bind(this);
33
+ this.onCatchError = this.onCatchError.bind(this);
34
+ this.onCatchCritical = this.onCatchCritical.bind(this);
35
+ this.onCatchFatal = this.onCatchFatal.bind(this);
36
+ this.getErrorMessage = this.getErrorMessage.bind(this);
37
+ this.getErrorStack = this.getErrorStack.bind(this);
38
+ this.initUncought = this.initUncought.bind(this);
39
+ }
40
+ setFromatter(formatter: IFormatter): void
41
+ {
42
+ this.formatter = formatter;
43
+ }
44
+ setCustomFormatter(level: LogLevel, formatter: IFormatter): void
45
+ {
46
+ this.customFormatter[level] = formatter;
47
+ }
48
+ addStream(stream: IStream)
49
+ {
50
+ this.streams.push(stream);
51
+ }
52
+ log(level: LogLevel, ...messages: any[])
53
+ {
54
+ let log = new Log(level, ...messages);
55
+ let formatted: { pre: string[], messages: string[], post: string[] } = { pre: [], messages: [], post: [] };
56
+ let formatter = this.customFormatter[level.toString()] ?? this.formatter;
57
+ if (formatter)
58
+ formatted = formatter.format(log);
59
+ if (this.streams.length == 0)
60
+ this.defaultStream.write(log, formatted);
61
+ else
62
+ this.streams.map(s => s.write(log, formatted));
63
+ }
64
+ trace(...messages: any[])
65
+ {
66
+ this.log(LogLevel.Trace, ...messages);
67
+ }
68
+ verbose(...messages: any[])
69
+ {
70
+ this.log(LogLevel.Verbose, ...messages);
71
+ }
72
+ debug(...messages: any[])
73
+ {
74
+ this.log(LogLevel.Debug, ...messages);
75
+ }
76
+ info(...messages: any[])
77
+ {
78
+ this.log(LogLevel.Info, ...messages);
79
+ }
80
+ success(...messages: any[])
81
+ {
82
+ this.log(LogLevel.Success, ...messages);
83
+ }
84
+ warning(...messages: any[])
85
+ {
86
+ this.log(LogLevel.Warning, ...messages);
87
+ }
88
+ error(...messages: any[])
89
+ {
90
+ this.log(LogLevel.Error, ...messages);
91
+ }
92
+ critical(...messages: any[])
93
+ {
94
+ this.log(LogLevel.Critical, ...messages);
95
+ }
96
+ fatal(...messages: any[])
97
+ {
98
+ this.log(LogLevel.Fatal, ...messages);
99
+ }
100
+ onCatchError(error: Error | unknown)
101
+ {
102
+ this.error(this.getErrorMessage(error), this.getErrorStack(error));
103
+ }
104
+ onCatchCritical(error: Error | unknown)
105
+ {
106
+ this.critical(this.getErrorMessage(error), this.getErrorStack(error));
107
+ }
108
+ onCatchFatal(error: Error | unknown)
109
+ {
110
+ this.fatal(this.getErrorMessage(error), this.getErrorStack(error));
111
+ }
112
+ protected getErrorMessage(error: Error | unknown): string
113
+ {
114
+ if (error instanceof Error)
115
+ return error.message;
116
+ return error + "";
117
+ }
118
+ protected getErrorStack(error: Error | unknown): string
119
+ {
120
+ if (error instanceof Error)
121
+ return error.stack ?? "";
122
+ return error + "";
123
+ }
124
+ initUncought()
125
+ {
126
+ }
127
127
  }
@@ -41,7 +41,7 @@ export class NamirasoftLogServer extends NSABaseServer
41
41
  log: NamirasoftLogServerLog;
42
42
  constructor(base_url: string, manager: TokenManager, onError: (error: Error) => void)
43
43
  {
44
- super(base_url, `1.4.30`, manager, onError);
44
+ super(base_url, `1.4.32`, manager, onError);
45
45
  this.healthz = new NamirasoftLogServerHealthz(this);
46
46
  this.metrics = new NamirasoftLogServerMetrics(this);
47
47
  this.value = new NamirasoftLogServerValue(this);
@@ -25,6 +25,7 @@ import { LogGroupRow } from "./row/LogGroupRow";
25
25
  import { NamirasoftLogServer } from "./NamirasoftLogServer";
26
26
  import { NamirasoftLogServerBase } from "./NamirasoftLogServerBase";
27
27
  import { SortItem } from "namirasoft-core";
28
+ import { SubscriptionValidation } from "namirasoft-payment";
28
29
 
29
30
  export class NamirasoftLogServerLogGroup extends NamirasoftLogServerBase
30
31
  {
@@ -32,6 +33,8 @@ export class NamirasoftLogServerLogGroup extends NamirasoftLogServerBase
32
33
  {
33
34
  super(server);
34
35
  this.List = this.List.bind(this);
36
+ this.Validation = this.Validation.bind(this);
37
+ this.Usage = this.Usage.bind(this);
35
38
  this.Get = this.Get.bind(this);
36
39
  this.Create = this.Create.bind(this);
37
40
  this.Update = this.Update.bind(this);
@@ -45,6 +48,18 @@ export class NamirasoftLogServerLogGroup extends NamirasoftLogServerBase
45
48
  let { data } = await this.server._get<{ rows: LogGroupRow[], count: number }>(path, { filters: filters_string_value, page, size, sorts: sorts_string_value });
46
49
  return data;
47
50
  }
51
+ async Validation(): Promise<SubscriptionValidation>
52
+ {
53
+ let path = `/log/group/validation`;
54
+ let { data } = await this.server._get<SubscriptionValidation>(path, {});
55
+ return data;
56
+ }
57
+ async Usage(): Promise<{ quota: { total_count: number, total_value: number }, used: { total_count: number, total_value: number } }>
58
+ {
59
+ let path = `/log/group/usage`;
60
+ let { data } = await this.server._get<{ quota: { total_count: number, total_value: number }, used: { total_count: number, total_value: number } }>(path, {});
61
+ return data;
62
+ }
48
63
  async Get(id: string): Promise<LogGroupFullRow>
49
64
  {
50
65
  let path = `/log/group/${id}`;
@@ -1,38 +1,38 @@
1
- import { ConsoleOperation } from "namirasoft-core";
2
- import { IStream } from "./IStream";
3
- import { Log } from "./Log";
4
- import { LogLevel } from './LogLevel';
5
-
6
- export class StreamConsole implements IStream
7
- {
8
- write(log: Log, formated: { pre: string[], messages: string[], post: string[] }): void
9
- {
10
- let getFormatted = (data: string) =>
11
- {
12
- if (log.level == LogLevel.Trace)
13
- return ConsoleOperation.formatTraceColor(data);
14
- if (log.level == LogLevel.Verbose)
15
- return ConsoleOperation.formatLogColor(data);
16
- if (log.level == LogLevel.Debug)
17
- return ConsoleOperation.formatDebugColor(data);
18
- if (log.level == LogLevel.Info)
19
- return ConsoleOperation.formatInfoColor(data);
20
- if (log.level == LogLevel.Success)
21
- return ConsoleOperation.formatSuccessColor(data);
22
- if (log.level == LogLevel.Warning)
23
- return ConsoleOperation.formatWarningColor(data);
24
- if (log.level == LogLevel.Error)
25
- return ConsoleOperation.formatErrorColor(data);
26
- if (log.level == LogLevel.Critical)
27
- return ConsoleOperation.formatErrorColor(data);
28
- if (log.level == LogLevel.Fatal)
29
- return ConsoleOperation.formatErrorColor(data);
30
- return ConsoleOperation.formatLogColor(data);
31
- }
32
- let preline: string[] = formated.pre.map(ConsoleOperation.formatLogColor);
33
- let msgline: string[] = formated.messages.map(getFormatted);
34
- let postline: string[] = formated.post.map(ConsoleOperation.formatLogColor);
35
- let lines = [...preline, ...msgline, ...postline];
36
- console.log(lines.join("\n"));
37
- }
1
+ import { ConsoleOperation } from "namirasoft-core";
2
+ import { IStream } from "./IStream";
3
+ import { Log } from "./Log";
4
+ import { LogLevel } from './LogLevel';
5
+
6
+ export class StreamConsole implements IStream
7
+ {
8
+ write(log: Log, formated: { pre: string[], messages: string[], post: string[] }): void
9
+ {
10
+ let getFormatted = (data: string) =>
11
+ {
12
+ if (log.level == LogLevel.Trace)
13
+ return ConsoleOperation.formatTraceColor(data);
14
+ if (log.level == LogLevel.Verbose)
15
+ return ConsoleOperation.formatLogColor(data);
16
+ if (log.level == LogLevel.Debug)
17
+ return ConsoleOperation.formatDebugColor(data);
18
+ if (log.level == LogLevel.Info)
19
+ return ConsoleOperation.formatInfoColor(data);
20
+ if (log.level == LogLevel.Success)
21
+ return ConsoleOperation.formatSuccessColor(data);
22
+ if (log.level == LogLevel.Warning)
23
+ return ConsoleOperation.formatWarningColor(data);
24
+ if (log.level == LogLevel.Error)
25
+ return ConsoleOperation.formatErrorColor(data);
26
+ if (log.level == LogLevel.Critical)
27
+ return ConsoleOperation.formatErrorColor(data);
28
+ if (log.level == LogLevel.Fatal)
29
+ return ConsoleOperation.formatErrorColor(data);
30
+ return ConsoleOperation.formatLogColor(data);
31
+ }
32
+ let preline: string[] = formated.pre.map(ConsoleOperation.formatLogColor);
33
+ let msgline: string[] = formated.messages.map(getFormatted);
34
+ let postline: string[] = formated.post.map(ConsoleOperation.formatLogColor);
35
+ let lines = [...preline, ...msgline, ...postline];
36
+ console.log(lines.join("\n"));
37
+ }
38
38
  }
package/src/StreamFile.ts CHANGED
@@ -1,48 +1,48 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import { IStream } from "./IStream";
4
- import { Log } from "./Log";
5
-
6
- export class StreamFile implements IStream
7
- {
8
- private baseName: string;
9
- private basePath: string;
10
- seprateByDate: boolean = true;
11
- seprateByLevel: boolean = true;
12
- constructor(basePath: string = "./")
13
- {
14
- this.basePath = basePath;
15
- this.baseName = this.getPackageName();
16
- }
17
- private getPackageName()
18
- {
19
- let pkgPath = path.resolve(process.cwd(), "");
20
- if (!pkgPath.endsWith('package.json'))
21
- {
22
- pkgPath = path.join(pkgPath, 'package.json');
23
- }
24
- if (fs.existsSync(pkgPath))
25
- {
26
- let json = fs.readFileSync(pkgPath) + "";
27
- let pkg = JSON.parse(json);
28
- return pkg.name;
29
- }
30
- return "";
31
- }
32
- private getFilePath(log: Log): string
33
- {
34
- let names = [this.baseName];
35
- if (this.seprateByDate)
36
- names.push(log.date.getFullYear() + "-" + (log.date.getMonth() + 1) + "-" + log.date.getDate());
37
- if (this.seprateByLevel)
38
- names.push(log.level + "");
39
- names.push(".log");
40
- let name = names.join("-");
41
- return path.resolve(this.basePath, name);
42
- }
43
- write(log: Log, formated: { pre: string[], messages: string[], post: string[] }): void
44
- {
45
- let filePath = this.getFilePath(log);
46
- fs.appendFile(filePath, [...formated.pre, ...formated.messages, ...formated.post].join("\n"), () => { });
47
- }
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { IStream } from "./IStream";
4
+ import { Log } from "./Log";
5
+
6
+ export class StreamFile implements IStream
7
+ {
8
+ private baseName: string;
9
+ private basePath: string;
10
+ seprateByDate: boolean = true;
11
+ seprateByLevel: boolean = true;
12
+ constructor(basePath: string = "./")
13
+ {
14
+ this.basePath = basePath;
15
+ this.baseName = this.getPackageName();
16
+ }
17
+ private getPackageName()
18
+ {
19
+ let pkgPath = path.resolve(process.cwd(), "");
20
+ if (!pkgPath.endsWith('package.json'))
21
+ {
22
+ pkgPath = path.join(pkgPath, 'package.json');
23
+ }
24
+ if (fs.existsSync(pkgPath))
25
+ {
26
+ let json = fs.readFileSync(pkgPath) + "";
27
+ let pkg = JSON.parse(json);
28
+ return pkg.name;
29
+ }
30
+ return "";
31
+ }
32
+ private getFilePath(log: Log): string
33
+ {
34
+ let names = [this.baseName];
35
+ if (this.seprateByDate)
36
+ names.push(log.date.getFullYear() + "-" + (log.date.getMonth() + 1) + "-" + log.date.getDate());
37
+ if (this.seprateByLevel)
38
+ names.push(log.level + "");
39
+ names.push(".log");
40
+ let name = names.join("-");
41
+ return path.resolve(this.basePath, name);
42
+ }
43
+ write(log: Log, formated: { pre: string[], messages: string[], post: string[] }): void
44
+ {
45
+ let filePath = this.getFilePath(log);
46
+ fs.appendFile(filePath, [...formated.pre, ...formated.messages, ...formated.post].join("\n"), () => { });
47
+ }
48
48
  }
@@ -1,65 +1,65 @@
1
- import { IStream } from "./IStream";
2
- import { Log } from "./Log";
3
- import { NamirasoftLogServer } from "./NamirasoftLogServer";
4
-
5
- export class StreamNamirasoftLog implements IStream
6
- {
7
- private queue: (() => Promise<void>)[] = [];
8
- private isProcessing = false;
9
- server: NamirasoftLogServer;
10
- user_id?: string;
11
- log_group_id: string;
12
- getProductID: () => (string | null);
13
- constructor(server: NamirasoftLogServer, log_group_id: string, getProductID: () => (string | null))
14
- {
15
- this.server = server;
16
- this.log_group_id = log_group_id;
17
- this.getProductID = getProductID;
18
- }
19
- write(log: Log, formated: { pre: string[], messages: string[], post: string[] }): void
20
- {
21
- if (process.env.NAMIRASOFT_STANDALNOE)
22
- return;
23
- let message = [...formated.pre, ...formated.messages, ...formated.post].join("\n");
24
- let body = {
25
- level: log.level.toString(),
26
- log_group_id: this.log_group_id,
27
- product_id: this.getProductID(),
28
- message
29
- };
30
- this.queue.push(async () =>
31
- {
32
- if (this.user_id)
33
- await this.server.log._CreateFor(this.user_id, body);
34
- else
35
- await this.server.log.Create(body);
36
- });
37
- this.processQueue();
38
- }
39
- private async processQueue()
40
- {
41
- if (this.isProcessing)
42
- return;
43
- this.isProcessing = true;
44
- try
45
- {
46
- while (this.queue.length > 0)
47
- {
48
- const job = this.queue.shift();
49
- if (job)
50
- {
51
- try
52
- {
53
- await job();
54
- }
55
- catch (err)
56
- {
57
- }
58
- }
59
- }
60
- } finally
61
- {
62
- this.isProcessing = false;
63
- }
64
- }
1
+ import { IStream } from "./IStream";
2
+ import { Log } from "./Log";
3
+ import { NamirasoftLogServer } from "./NamirasoftLogServer";
4
+
5
+ export class StreamNamirasoftLog implements IStream
6
+ {
7
+ private queue: (() => Promise<void>)[] = [];
8
+ private isProcessing = false;
9
+ server: NamirasoftLogServer;
10
+ user_id?: string;
11
+ log_group_id: string;
12
+ getProductID: () => (string | null);
13
+ constructor(server: NamirasoftLogServer, log_group_id: string, getProductID: () => (string | null))
14
+ {
15
+ this.server = server;
16
+ this.log_group_id = log_group_id;
17
+ this.getProductID = getProductID;
18
+ }
19
+ write(log: Log, formated: { pre: string[], messages: string[], post: string[] }): void
20
+ {
21
+ if (process.env.NAMIRASOFT_STANDALNOE)
22
+ return;
23
+ let message = [...formated.pre, ...formated.messages, ...formated.post].join("\n");
24
+ let body = {
25
+ level: log.level.toString(),
26
+ log_group_id: this.log_group_id,
27
+ product_id: this.getProductID(),
28
+ message
29
+ };
30
+ this.queue.push(async () =>
31
+ {
32
+ if (this.user_id)
33
+ await this.server.log._CreateFor(this.user_id, body);
34
+ else
35
+ await this.server.log.Create(body);
36
+ });
37
+ this.processQueue();
38
+ }
39
+ private async processQueue()
40
+ {
41
+ if (this.isProcessing)
42
+ return;
43
+ this.isProcessing = true;
44
+ try
45
+ {
46
+ while (this.queue.length > 0)
47
+ {
48
+ const job = this.queue.shift();
49
+ if (job)
50
+ {
51
+ try
52
+ {
53
+ await job();
54
+ }
55
+ catch (err)
56
+ {
57
+ }
58
+ }
59
+ }
60
+ } finally
61
+ {
62
+ this.isProcessing = false;
63
+ }
64
+ }
65
65
  }
@@ -24,6 +24,8 @@ import { LogGroupDeleteCommand } from "./LogGroupDeleteCommand";
24
24
  import { LogGroupGetCommand } from "./LogGroupGetCommand";
25
25
  import { LogGroupListCommand } from "./LogGroupListCommand";
26
26
  import { LogGroupUpdateCommand } from "./LogGroupUpdateCommand";
27
+ import { LogGroupUsageCommand } from "./LogGroupUsageCommand";
28
+ import { LogGroupValidationCommand } from "./LogGroupValidationCommand";
27
29
 
28
30
  export class LogGroupCommand extends BaseNavigatorCommand
29
31
  {
@@ -31,6 +33,8 @@ export class LogGroupCommand extends BaseNavigatorCommand
31
33
  {
32
34
  super(argv, {
33
35
  "list": LogGroupListCommand,
36
+ "validation": LogGroupValidationCommand,
37
+ "usage": LogGroupUsageCommand,
34
38
  "get": LogGroupGetCommand,
35
39
  "create": LogGroupCreateCommand,
36
40
  "update": LogGroupUpdateCommand,
@@ -0,0 +1,45 @@
1
+ /****************************************************************/
2
+ /* */
3
+ /* This is an Auto-Generated File */
4
+ /* Made By */
5
+ /* Namirasoft SDK Generator NPM Package */
6
+ /* */
7
+ /****************************************************************/
8
+ /****************************************************************/
9
+ /* */
10
+ /* Please do not make any change to this file */
11
+ /* If any change is required, ns-sdkg command must be used */
12
+ /* */
13
+ /****************************************************************/
14
+ /****************************************************************/
15
+ /* */
16
+ /* Namira Software Corporation */
17
+ /* https://namirasoft.com */
18
+ /* */
19
+ /****************************************************************/
20
+
21
+ import { BaseFinalCommand } from "namirasoft-node-cli";
22
+ import { IStorageMemoryDedicated } from "namirasoft-core";
23
+ import { NamirasoftLogServer } from "../NamirasoftLogServer";
24
+ import { TokenManager } from "namirasoft-account";
25
+
26
+ export class LogGroupUsageCommand extends BaseFinalCommand
27
+ {
28
+ constructor(argv: string[])
29
+ {
30
+ super(argv, [], []);
31
+ }
32
+ override async exec()
33
+ {
34
+ let token = this.app.storage.getNSAToken();
35
+ if (token == null)
36
+ throw new Error("Token is not available. Please login first using:\nns-log account config \nor \nns-log account login.");
37
+ let storage = new IStorageMemoryDedicated();
38
+ let manager = new TokenManager(storage, () => { });
39
+ manager.setValue(token, false);
40
+ let url = this.app.storage.getItem("ns-log-server-url");
41
+ let server = new NamirasoftLogServer(url, manager, e => this.app.logger.error(e.message));
42
+ let ans = await server.log_group.Usage();
43
+ this.app.logger.success(JSON.stringify(ans));
44
+ }
45
+ };