namirasoft-log 1.4.37 → 1.4.39
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/.ns-sdkg-file-keep +11 -11
- package/dist/StreamNamirasoftLog.js +2 -0
- package/dist/StreamNamirasoftLog.js.map +1 -1
- package/package.json +28 -28
- package/src/BaseFormatter.ts +36 -36
- package/src/FormatterFull.ts +19 -19
- package/src/FormatterShort.ts +12 -12
- package/src/IFormatter.ts +5 -5
- package/src/ILogger.ts +17 -17
- package/src/IStream.ts +4 -4
- package/src/Log.ts +13 -13
- package/src/LogLevel.ts +11 -11
- package/src/Logger.ts +126 -126
- package/src/NamirasoftLogServer.ts +53 -53
- package/src/NamirasoftLogServerLogGroup.ts +92 -92
- package/src/StreamConsole.ts +37 -37
- package/src/StreamFile.ts +47 -47
- package/src/StreamNamirasoftLog.ts +67 -64
package/.ns-sdkg-file-keep
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/src/BaseFormatter.ts
|
|
2
|
-
/src/FormatterFull.ts
|
|
3
|
-
/src/FormatterShort.ts
|
|
4
|
-
/src/IFormatter.ts
|
|
5
|
-
/src/ILogger.ts
|
|
6
|
-
/src/IStream.ts
|
|
7
|
-
/src/Log.ts
|
|
8
|
-
/src/Logger.ts
|
|
9
|
-
/src/LogLevel.ts
|
|
10
|
-
/src/StreamConsole.ts
|
|
11
|
-
/src/StreamFile.ts
|
|
1
|
+
/src/BaseFormatter.ts
|
|
2
|
+
/src/FormatterFull.ts
|
|
3
|
+
/src/FormatterShort.ts
|
|
4
|
+
/src/IFormatter.ts
|
|
5
|
+
/src/ILogger.ts
|
|
6
|
+
/src/IStream.ts
|
|
7
|
+
/src/Log.ts
|
|
8
|
+
/src/Logger.ts
|
|
9
|
+
/src/LogLevel.ts
|
|
10
|
+
/src/StreamConsole.ts
|
|
11
|
+
/src/StreamFile.ts
|
|
12
12
|
/src/StreamNamirasoftLog.ts
|
|
@@ -17,10 +17,12 @@ class StreamNamirasoftLog {
|
|
|
17
17
|
this.server = server;
|
|
18
18
|
this.log_group_id = log_group_id;
|
|
19
19
|
this.getProductID = getProductID;
|
|
20
|
+
console.log({ server });
|
|
20
21
|
}
|
|
21
22
|
write(log, formated) {
|
|
22
23
|
if (process.env.NAMIRASOFT_STANDALNOE)
|
|
23
24
|
return;
|
|
25
|
+
console.log({ server: this.server });
|
|
24
26
|
let message = [...formated.pre, ...formated.messages, ...formated.post].join("\n");
|
|
25
27
|
let body = {
|
|
26
28
|
level: log.level.toString(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StreamNamirasoftLog.js","sourceRoot":"","sources":["../src/StreamNamirasoftLog.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,MAAa,mBAAmB;IAQ5B,YAAY,MAA2B,EAAE,YAAoB,EAAE,YAAmC;QAN1F,UAAK,GAA4B,EAAE,CAAC;QACpC,iBAAY,GAAG,KAAK,CAAC;QAOzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"StreamNamirasoftLog.js","sourceRoot":"","sources":["../src/StreamNamirasoftLog.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,MAAa,mBAAmB;IAQ5B,YAAY,MAA2B,EAAE,YAAoB,EAAE,YAAmC;QAN1F,UAAK,GAA4B,EAAE,CAAC;QACpC,iBAAY,GAAG,KAAK,CAAC;QAOzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAC3B,CAAC;IACD,KAAK,CAAC,GAAQ,EAAE,QAA+D;QAE3E,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB;YACjC,OAAO;QAEX,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QACrC,IAAI,OAAO,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnF,IAAI,IAAI,GAAG;YACP,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE;YAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,UAAU,EAAE,IAAI,CAAC,YAAY,EAAE;YAC/B,OAAO;SACV,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAS,EAAE;YAEvB,IAAI,IAAI,CAAC,OAAO;gBACZ,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;;gBAErD,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3C,CAAC,CAAA,CAAC,CAAC;QACH,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;IACa,YAAY;;YAEtB,IAAI,IAAI,CAAC,YAAY;gBACjB,OAAO;YACX,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;YACzB,IACA,CAAC;gBACG,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAC5B,CAAC;oBACG,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;oBAC/B,IAAI,GAAG,EACP,CAAC;wBACG,IACA,CAAC;4BACG,MAAM,GAAG,EAAE,CAAC;wBAChB,CAAC;wBACD,OAAO,GAAG,EACV,CAAC;wBACD,CAAC;oBACL,CAAC;gBACL,CAAC;YACL,CAAC;oBACD,CAAC;gBACG,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;YAC9B,CAAC;QACL,CAAC;KAAA;CACJ;AA/DD,kDA+DC"}
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "namirasoft-log",
|
|
3
|
-
"title": "Namirasoft Log NPM Package",
|
|
4
|
-
"description": "Namira Software Corporation Log NPM Package",
|
|
5
|
-
"icon": "logo.png",
|
|
6
|
-
"logo": "https://static.namirasoft.com/image/namirasoft/log/logo/base.png",
|
|
7
|
-
"language": "ts",
|
|
8
|
-
"framework": "npm",
|
|
9
|
-
"application": "package",
|
|
10
|
-
"private": false,
|
|
11
|
-
"version": "1.4.
|
|
12
|
-
"author": "Amir Abolhasani",
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"main": "./dist/index.js",
|
|
15
|
-
"types": "./dist/index.d.ts",
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": ""
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"namirasoft-core": "^1.4.
|
|
21
|
-
"namirasoft-site": "^1.4.41",
|
|
22
|
-
"namirasoft-node-cli": "^1.4.10",
|
|
23
|
-
"namirasoft-account": "^1.4.
|
|
24
|
-
"namirasoft-payment": "^1.4.
|
|
25
|
-
},
|
|
26
|
-
"bin": {
|
|
27
|
-
"ns-log": "./dist/command/cli.js"
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "namirasoft-log",
|
|
3
|
+
"title": "Namirasoft Log NPM Package",
|
|
4
|
+
"description": "Namira Software Corporation Log NPM Package",
|
|
5
|
+
"icon": "logo.png",
|
|
6
|
+
"logo": "https://static.namirasoft.com/image/namirasoft/log/logo/base.png",
|
|
7
|
+
"language": "ts",
|
|
8
|
+
"framework": "npm",
|
|
9
|
+
"application": "package",
|
|
10
|
+
"private": false,
|
|
11
|
+
"version": "1.4.39",
|
|
12
|
+
"author": "Amir Abolhasani",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": ""
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"namirasoft-core": "^1.4.107",
|
|
21
|
+
"namirasoft-site": "^1.4.41",
|
|
22
|
+
"namirasoft-node-cli": "^1.4.10",
|
|
23
|
+
"namirasoft-account": "^1.4.100",
|
|
24
|
+
"namirasoft-payment": "^1.4.133"
|
|
25
|
+
},
|
|
26
|
+
"bin": {
|
|
27
|
+
"ns-log": "./dist/command/cli.js"
|
|
28
|
+
}
|
|
29
29
|
}
|
package/src/BaseFormatter.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
export abstract class BaseFormatter
|
|
2
|
-
{
|
|
3
|
-
protected formatDateTime(date: Date)
|
|
4
|
-
{
|
|
5
|
-
return this.formatDate(date) + " " + this.formatTime(date) + " UTC";
|
|
6
|
-
}
|
|
7
|
-
protected formatDate(date: Date)
|
|
8
|
-
{
|
|
9
|
-
const year = date.getUTCFullYear();
|
|
10
|
-
const month = (date.getUTCMonth() + 1).toString().padStart(2, '0');
|
|
11
|
-
const day = String(date.getUTCDate()).toString().padStart(2, '0');
|
|
12
|
-
return `${year}-${month}-${day}`;
|
|
13
|
-
}
|
|
14
|
-
protected formatTime(date: Date)
|
|
15
|
-
{
|
|
16
|
-
const hours = String(date.getUTCHours()).padStart(2, '0');
|
|
17
|
-
const minutes = String(date.getUTCMinutes()).padStart(2, '0');
|
|
18
|
-
const seconds = String(date.getUTCSeconds()).padStart(2, '0');
|
|
19
|
-
return `${hours}:${minutes}:${seconds}`;
|
|
20
|
-
}
|
|
21
|
-
protected qoute(text: string, size: number, filler: string)
|
|
22
|
-
{
|
|
23
|
-
let count = (size - text.length) / 2;
|
|
24
|
-
text = text.padStart(text.length + count, filler);
|
|
25
|
-
text = text.padEnd(size, filler);
|
|
26
|
-
return text;
|
|
27
|
-
}
|
|
28
|
-
protected getMesssages(messages: any[]): string[]
|
|
29
|
-
{
|
|
30
|
-
return messages.map(x =>
|
|
31
|
-
{
|
|
32
|
-
if (typeof (x) == "object")
|
|
33
|
-
return JSON.stringify(x, undefined, 4);
|
|
34
|
-
return x + "";
|
|
35
|
-
});
|
|
36
|
-
}
|
|
1
|
+
export abstract class BaseFormatter
|
|
2
|
+
{
|
|
3
|
+
protected formatDateTime(date: Date)
|
|
4
|
+
{
|
|
5
|
+
return this.formatDate(date) + " " + this.formatTime(date) + " UTC";
|
|
6
|
+
}
|
|
7
|
+
protected formatDate(date: Date)
|
|
8
|
+
{
|
|
9
|
+
const year = date.getUTCFullYear();
|
|
10
|
+
const month = (date.getUTCMonth() + 1).toString().padStart(2, '0');
|
|
11
|
+
const day = String(date.getUTCDate()).toString().padStart(2, '0');
|
|
12
|
+
return `${year}-${month}-${day}`;
|
|
13
|
+
}
|
|
14
|
+
protected formatTime(date: Date)
|
|
15
|
+
{
|
|
16
|
+
const hours = String(date.getUTCHours()).padStart(2, '0');
|
|
17
|
+
const minutes = String(date.getUTCMinutes()).padStart(2, '0');
|
|
18
|
+
const seconds = String(date.getUTCSeconds()).padStart(2, '0');
|
|
19
|
+
return `${hours}:${minutes}:${seconds}`;
|
|
20
|
+
}
|
|
21
|
+
protected qoute(text: string, size: number, filler: string)
|
|
22
|
+
{
|
|
23
|
+
let count = (size - text.length) / 2;
|
|
24
|
+
text = text.padStart(text.length + count, filler);
|
|
25
|
+
text = text.padEnd(size, filler);
|
|
26
|
+
return text;
|
|
27
|
+
}
|
|
28
|
+
protected getMesssages(messages: any[]): string[]
|
|
29
|
+
{
|
|
30
|
+
return messages.map(x =>
|
|
31
|
+
{
|
|
32
|
+
if (typeof (x) == "object")
|
|
33
|
+
return JSON.stringify(x, undefined, 4);
|
|
34
|
+
return x + "";
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
37
|
}
|
package/src/FormatterFull.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { BaseFormatter } from "./BaseFormatter";
|
|
2
|
-
import { IFormatter } from "./IFormatter";
|
|
3
|
-
import { Log } from "./Log";
|
|
4
|
-
import { LogLevel } from "./LogLevel";
|
|
5
|
-
|
|
6
|
-
export class FormatterFull extends BaseFormatter implements IFormatter
|
|
7
|
-
{
|
|
8
|
-
format(log: Log): { pre: string[], messages: string[], post: string[] }
|
|
9
|
-
{
|
|
10
|
-
let pre: string[] = [];
|
|
11
|
-
let messages: string[] = [];
|
|
12
|
-
let post: string[] = [];
|
|
13
|
-
pre.push(this.qoute(this.formatDateTime(log.date), 100, '-'));
|
|
14
|
-
pre.push("Level: " + LogLevel[log.level]);
|
|
15
|
-
messages.push(...this.getMesssages(log.messages));
|
|
16
|
-
post.push(this.qoute("", 100, '-'));
|
|
17
|
-
post.push("");
|
|
18
|
-
return { pre, messages, post };
|
|
19
|
-
}
|
|
1
|
+
import { BaseFormatter } from "./BaseFormatter";
|
|
2
|
+
import { IFormatter } from "./IFormatter";
|
|
3
|
+
import { Log } from "./Log";
|
|
4
|
+
import { LogLevel } from "./LogLevel";
|
|
5
|
+
|
|
6
|
+
export class FormatterFull extends BaseFormatter implements IFormatter
|
|
7
|
+
{
|
|
8
|
+
format(log: Log): { pre: string[], messages: string[], post: string[] }
|
|
9
|
+
{
|
|
10
|
+
let pre: string[] = [];
|
|
11
|
+
let messages: string[] = [];
|
|
12
|
+
let post: string[] = [];
|
|
13
|
+
pre.push(this.qoute(this.formatDateTime(log.date), 100, '-'));
|
|
14
|
+
pre.push("Level: " + LogLevel[log.level]);
|
|
15
|
+
messages.push(...this.getMesssages(log.messages));
|
|
16
|
+
post.push(this.qoute("", 100, '-'));
|
|
17
|
+
post.push("");
|
|
18
|
+
return { pre, messages, post };
|
|
19
|
+
}
|
|
20
20
|
}
|
package/src/FormatterShort.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { BaseFormatter } from "./BaseFormatter";
|
|
2
|
-
import { IFormatter } from "./IFormatter";
|
|
3
|
-
import { Log } from "./Log";
|
|
4
|
-
|
|
5
|
-
export class FormatterShort extends BaseFormatter implements IFormatter
|
|
6
|
-
{
|
|
7
|
-
format(log: Log): { pre: string[], messages: string[], post: string[] }
|
|
8
|
-
{
|
|
9
|
-
let ans: string[] = [];
|
|
10
|
-
ans.push(this.formatDateTime(log.date) + ": " + this.getMesssages(log.messages).filter(m => m).join(" - "));
|
|
11
|
-
return { pre: [], messages: ans, post: [] };
|
|
12
|
-
}
|
|
1
|
+
import { BaseFormatter } from "./BaseFormatter";
|
|
2
|
+
import { IFormatter } from "./IFormatter";
|
|
3
|
+
import { Log } from "./Log";
|
|
4
|
+
|
|
5
|
+
export class FormatterShort extends BaseFormatter implements IFormatter
|
|
6
|
+
{
|
|
7
|
+
format(log: Log): { pre: string[], messages: string[], post: string[] }
|
|
8
|
+
{
|
|
9
|
+
let ans: string[] = [];
|
|
10
|
+
ans.push(this.formatDateTime(log.date) + ": " + this.getMesssages(log.messages).filter(m => m).join(" - "));
|
|
11
|
+
return { pre: [], messages: ans, post: [] };
|
|
12
|
+
}
|
|
13
13
|
}
|
package/src/IFormatter.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Log } from "./Log";
|
|
2
|
-
|
|
3
|
-
export interface IFormatter
|
|
4
|
-
{
|
|
5
|
-
format(log: Log): { pre: string[], messages: string[], post: string[] };
|
|
1
|
+
import { Log } from "./Log";
|
|
2
|
+
|
|
3
|
+
export interface IFormatter
|
|
4
|
+
{
|
|
5
|
+
format(log: Log): { pre: string[], messages: string[], post: string[] };
|
|
6
6
|
}
|
package/src/ILogger.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { LogLevel } from "./LogLevel";
|
|
2
|
-
|
|
3
|
-
export interface ILogger
|
|
4
|
-
{
|
|
5
|
-
log(level: LogLevel, ...messages: any[]): void;
|
|
6
|
-
trace(...messages: any[]): void;
|
|
7
|
-
verbose(...messages: any[]): void;
|
|
8
|
-
debug(...messages: any[]): void;
|
|
9
|
-
info(...messages: any[]): void;
|
|
10
|
-
success(...messages: any[]): void;
|
|
11
|
-
warning(...messages: any[]): void;
|
|
12
|
-
error(...messages: any[]): void;
|
|
13
|
-
critical(...messages: any[]): void;
|
|
14
|
-
fatal(...messages: any[]): void;
|
|
15
|
-
onCatchError(error: Error | unknown): void;
|
|
16
|
-
onCatchCritical(error: Error | unknown): void;
|
|
17
|
-
onCatchFatal(error: Error | unknown): void;
|
|
1
|
+
import { LogLevel } from "./LogLevel";
|
|
2
|
+
|
|
3
|
+
export interface ILogger
|
|
4
|
+
{
|
|
5
|
+
log(level: LogLevel, ...messages: any[]): void;
|
|
6
|
+
trace(...messages: any[]): void;
|
|
7
|
+
verbose(...messages: any[]): void;
|
|
8
|
+
debug(...messages: any[]): void;
|
|
9
|
+
info(...messages: any[]): void;
|
|
10
|
+
success(...messages: any[]): void;
|
|
11
|
+
warning(...messages: any[]): void;
|
|
12
|
+
error(...messages: any[]): void;
|
|
13
|
+
critical(...messages: any[]): void;
|
|
14
|
+
fatal(...messages: any[]): void;
|
|
15
|
+
onCatchError(error: Error | unknown): void;
|
|
16
|
+
onCatchCritical(error: Error | unknown): void;
|
|
17
|
+
onCatchFatal(error: Error | unknown): void;
|
|
18
18
|
}
|
package/src/IStream.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Log } from "./Log";
|
|
2
|
-
export interface IStream
|
|
3
|
-
{
|
|
4
|
-
write(log: Log, formated: { pre: string[], messages: string[], post: string[] }): void;
|
|
1
|
+
import { Log } from "./Log";
|
|
2
|
+
export interface IStream
|
|
3
|
+
{
|
|
4
|
+
write(log: Log, formated: { pre: string[], messages: string[], post: string[] }): void;
|
|
5
5
|
}
|
package/src/Log.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { LogLevel } from "./LogLevel";
|
|
2
|
-
|
|
3
|
-
export class Log
|
|
4
|
-
{
|
|
5
|
-
date: Date;
|
|
6
|
-
level: LogLevel;
|
|
7
|
-
messages: any[];
|
|
8
|
-
constructor(level: LogLevel, ...messages: any[])
|
|
9
|
-
{
|
|
10
|
-
this.date = new Date();
|
|
11
|
-
this.level = level;
|
|
12
|
-
this.messages = messages;
|
|
13
|
-
}
|
|
1
|
+
import { LogLevel } from "./LogLevel";
|
|
2
|
+
|
|
3
|
+
export class Log
|
|
4
|
+
{
|
|
5
|
+
date: Date;
|
|
6
|
+
level: LogLevel;
|
|
7
|
+
messages: any[];
|
|
8
|
+
constructor(level: LogLevel, ...messages: any[])
|
|
9
|
+
{
|
|
10
|
+
this.date = new Date();
|
|
11
|
+
this.level = level;
|
|
12
|
+
this.messages = messages;
|
|
13
|
+
}
|
|
14
14
|
}
|
package/src/LogLevel.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export enum LogLevel
|
|
2
|
-
{
|
|
3
|
-
Trace = "Trace",
|
|
4
|
-
Verbose = "Verbose",
|
|
5
|
-
Debug = "Debug",
|
|
6
|
-
Info = "Info",
|
|
7
|
-
Success = "Success",
|
|
8
|
-
Warning = "Warning",
|
|
9
|
-
Error = "Error",
|
|
10
|
-
Critical = "Critical",
|
|
11
|
-
Fatal = "Fatal"
|
|
1
|
+
export enum LogLevel
|
|
2
|
+
{
|
|
3
|
+
Trace = "Trace",
|
|
4
|
+
Verbose = "Verbose",
|
|
5
|
+
Debug = "Debug",
|
|
6
|
+
Info = "Info",
|
|
7
|
+
Success = "Success",
|
|
8
|
+
Warning = "Warning",
|
|
9
|
+
Error = "Error",
|
|
10
|
+
Critical = "Critical",
|
|
11
|
+
Fatal = "Fatal"
|
|
12
12
|
}
|
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
|
}
|
|
@@ -1,54 +1,54 @@
|
|
|
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 { NSABaseServer } from "namirasoft-account";
|
|
22
|
-
import { NamirasoftLogServerHealthz } from "./NamirasoftLogServerHealthz";
|
|
23
|
-
import { NamirasoftLogServerLog } from "./NamirasoftLogServerLog";
|
|
24
|
-
import { NamirasoftLogServerLogGroup } from "./NamirasoftLogServerLogGroup";
|
|
25
|
-
import { NamirasoftLogServerLogGroupCategory } from "./NamirasoftLogServerLogGroupCategory";
|
|
26
|
-
import { NamirasoftLogServerLogGroupField } from "./NamirasoftLogServerLogGroupField";
|
|
27
|
-
import { NamirasoftLogServerLogGroupTag } from "./NamirasoftLogServerLogGroupTag";
|
|
28
|
-
import { NamirasoftLogServerMetrics } from "./NamirasoftLogServerMetrics";
|
|
29
|
-
import { NamirasoftLogServerValue } from "./NamirasoftLogServerValue";
|
|
30
|
-
import { TokenManager } from "namirasoft-account";
|
|
31
|
-
|
|
32
|
-
export class NamirasoftLogServer extends NSABaseServer
|
|
33
|
-
{
|
|
34
|
-
healthz: NamirasoftLogServerHealthz;
|
|
35
|
-
metrics: NamirasoftLogServerMetrics;
|
|
36
|
-
value: NamirasoftLogServerValue;
|
|
37
|
-
log_group_category: NamirasoftLogServerLogGroupCategory;
|
|
38
|
-
log_group_field: NamirasoftLogServerLogGroupField;
|
|
39
|
-
log_group_tag: NamirasoftLogServerLogGroupTag;
|
|
40
|
-
log_group: NamirasoftLogServerLogGroup;
|
|
41
|
-
log: NamirasoftLogServerLog;
|
|
42
|
-
constructor(base_url: string, manager: TokenManager, onError: (error: Error) => void)
|
|
43
|
-
{
|
|
44
|
-
super(base_url, `1.4.37`, manager, onError);
|
|
45
|
-
this.healthz = new NamirasoftLogServerHealthz(this);
|
|
46
|
-
this.metrics = new NamirasoftLogServerMetrics(this);
|
|
47
|
-
this.value = new NamirasoftLogServerValue(this);
|
|
48
|
-
this.log_group_category = new NamirasoftLogServerLogGroupCategory(this);
|
|
49
|
-
this.log_group_field = new NamirasoftLogServerLogGroupField(this);
|
|
50
|
-
this.log_group_tag = new NamirasoftLogServerLogGroupTag(this);
|
|
51
|
-
this.log_group = new NamirasoftLogServerLogGroup(this);
|
|
52
|
-
this.log = new NamirasoftLogServerLog(this);
|
|
53
|
-
}
|
|
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 { NSABaseServer } from "namirasoft-account";
|
|
22
|
+
import { NamirasoftLogServerHealthz } from "./NamirasoftLogServerHealthz";
|
|
23
|
+
import { NamirasoftLogServerLog } from "./NamirasoftLogServerLog";
|
|
24
|
+
import { NamirasoftLogServerLogGroup } from "./NamirasoftLogServerLogGroup";
|
|
25
|
+
import { NamirasoftLogServerLogGroupCategory } from "./NamirasoftLogServerLogGroupCategory";
|
|
26
|
+
import { NamirasoftLogServerLogGroupField } from "./NamirasoftLogServerLogGroupField";
|
|
27
|
+
import { NamirasoftLogServerLogGroupTag } from "./NamirasoftLogServerLogGroupTag";
|
|
28
|
+
import { NamirasoftLogServerMetrics } from "./NamirasoftLogServerMetrics";
|
|
29
|
+
import { NamirasoftLogServerValue } from "./NamirasoftLogServerValue";
|
|
30
|
+
import { TokenManager } from "namirasoft-account";
|
|
31
|
+
|
|
32
|
+
export class NamirasoftLogServer extends NSABaseServer
|
|
33
|
+
{
|
|
34
|
+
healthz: NamirasoftLogServerHealthz;
|
|
35
|
+
metrics: NamirasoftLogServerMetrics;
|
|
36
|
+
value: NamirasoftLogServerValue;
|
|
37
|
+
log_group_category: NamirasoftLogServerLogGroupCategory;
|
|
38
|
+
log_group_field: NamirasoftLogServerLogGroupField;
|
|
39
|
+
log_group_tag: NamirasoftLogServerLogGroupTag;
|
|
40
|
+
log_group: NamirasoftLogServerLogGroup;
|
|
41
|
+
log: NamirasoftLogServerLog;
|
|
42
|
+
constructor(base_url: string, manager: TokenManager, onError: (error: Error) => void)
|
|
43
|
+
{
|
|
44
|
+
super(base_url, `1.4.37`, manager, onError);
|
|
45
|
+
this.healthz = new NamirasoftLogServerHealthz(this);
|
|
46
|
+
this.metrics = new NamirasoftLogServerMetrics(this);
|
|
47
|
+
this.value = new NamirasoftLogServerValue(this);
|
|
48
|
+
this.log_group_category = new NamirasoftLogServerLogGroupCategory(this);
|
|
49
|
+
this.log_group_field = new NamirasoftLogServerLogGroupField(this);
|
|
50
|
+
this.log_group_tag = new NamirasoftLogServerLogGroupTag(this);
|
|
51
|
+
this.log_group = new NamirasoftLogServerLogGroup(this);
|
|
52
|
+
this.log = new NamirasoftLogServerLog(this);
|
|
53
|
+
}
|
|
54
54
|
};
|
|
@@ -1,93 +1,93 @@
|
|
|
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 { BaseServerConfig } from "namirasoft-core";
|
|
22
|
-
import { FilterItem } from "namirasoft-core";
|
|
23
|
-
import { LogGroupFullRow } from "./row/LogGroupFullRow";
|
|
24
|
-
import { LogGroupInputRow } from "./row/LogGroupInputRow";
|
|
25
|
-
import { LogGroupRow } from "./row/LogGroupRow";
|
|
26
|
-
import { NamirasoftLogServer } from "./NamirasoftLogServer";
|
|
27
|
-
import { NamirasoftLogServerBase } from "./NamirasoftLogServerBase";
|
|
28
|
-
import { SortItem } from "namirasoft-core";
|
|
29
|
-
import { SubscriptionValidation } from "namirasoft-payment";
|
|
30
|
-
|
|
31
|
-
export class NamirasoftLogServerLogGroup extends NamirasoftLogServerBase
|
|
32
|
-
{
|
|
33
|
-
constructor(server: NamirasoftLogServer)
|
|
34
|
-
{
|
|
35
|
-
super(server);
|
|
36
|
-
this._CancelationCheck = this._CancelationCheck.bind(this);
|
|
37
|
-
this.List = this.List.bind(this);
|
|
38
|
-
this.Validation = this.Validation.bind(this);
|
|
39
|
-
this.Usage = this.Usage.bind(this);
|
|
40
|
-
this.Get = this.Get.bind(this);
|
|
41
|
-
this.Create = this.Create.bind(this);
|
|
42
|
-
this.Update = this.Update.bind(this);
|
|
43
|
-
this.Delete = this.Delete.bind(this);
|
|
44
|
-
}
|
|
45
|
-
async _CancelationCheck(user_id: string, config?: BaseServerConfig<any>): Promise<void>
|
|
46
|
-
{
|
|
47
|
-
let path = `/application/user/${user_id}/log/group/cancelation/condition`;
|
|
48
|
-
await this.server._get<void>(path, {}, config);
|
|
49
|
-
}
|
|
50
|
-
async List(filters: FilterItem[] | null, page: (number | null), size: (number | null), sorts: SortItem[], config?: BaseServerConfig<any>): Promise<{ rows: LogGroupRow[], count: number }>
|
|
51
|
-
{
|
|
52
|
-
let filters_string_value: string = FilterItem.stringify(filters);
|
|
53
|
-
let sorts_string_value: string = SortItem.stringify(sorts);
|
|
54
|
-
let path = `/log/group/list`;
|
|
55
|
-
let { data } = await this.server._get<{ rows: LogGroupRow[], count: number }>(path, { filters: filters_string_value, page, size, sorts: sorts_string_value }, config);
|
|
56
|
-
return data;
|
|
57
|
-
}
|
|
58
|
-
async Validation(config?: BaseServerConfig<any>): Promise<SubscriptionValidation>
|
|
59
|
-
{
|
|
60
|
-
let path = `/log/group/validation`;
|
|
61
|
-
let { data } = await this.server._get<SubscriptionValidation>(path, {}, config);
|
|
62
|
-
return data;
|
|
63
|
-
}
|
|
64
|
-
async Usage(config?: BaseServerConfig<any>): Promise<{ subscribed: boolean, quota: { log_group_record_count: { value: number, unit: string }, log_record_size: { value: number, unit: string }, log_read_size: { value: number, unit: string } }, used: { log_group_record_count: { value: number, unit: string }, log_record_size: { value: number, unit: string }, log_read_size: { value: number, unit: string } } }>
|
|
65
|
-
{
|
|
66
|
-
let path = `/log/group/usage`;
|
|
67
|
-
let { data } = await this.server._get<{ subscribed: boolean, quota: { log_group_record_count: { value: number, unit: string }, log_record_size: { value: number, unit: string }, log_read_size: { value: number, unit: string } }, used: { log_group_record_count: { value: number, unit: string }, log_record_size: { value: number, unit: string }, log_read_size: { value: number, unit: string } } }>(path, {}, config);
|
|
68
|
-
return data;
|
|
69
|
-
}
|
|
70
|
-
async Get(id: string, config?: BaseServerConfig<any>): Promise<LogGroupFullRow>
|
|
71
|
-
{
|
|
72
|
-
let path = `/log/group/${id}`;
|
|
73
|
-
let { data } = await this.server._get<LogGroupFullRow>(path, {}, config);
|
|
74
|
-
return data;
|
|
75
|
-
}
|
|
76
|
-
async Create(body: LogGroupInputRow, config?: BaseServerConfig<any>): Promise<LogGroupRow>
|
|
77
|
-
{
|
|
78
|
-
let path = `/log/group`;
|
|
79
|
-
let { data } = await this.server._post<LogGroupRow>(path, {}, body, config);
|
|
80
|
-
return data;
|
|
81
|
-
}
|
|
82
|
-
async Update(id: string, body: LogGroupInputRow, config?: BaseServerConfig<any>): Promise<LogGroupRow>
|
|
83
|
-
{
|
|
84
|
-
let path = `/log/group/${id}`;
|
|
85
|
-
let { data } = await this.server._put<LogGroupRow>(path, {}, body, config);
|
|
86
|
-
return data;
|
|
87
|
-
}
|
|
88
|
-
async Delete(id: string, config?: BaseServerConfig<any>): Promise<void>
|
|
89
|
-
{
|
|
90
|
-
let path = `/log/group/${id}`;
|
|
91
|
-
await this.server._delete<void>(path, {}, config);
|
|
92
|
-
}
|
|
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 { BaseServerConfig } from "namirasoft-core";
|
|
22
|
+
import { FilterItem } from "namirasoft-core";
|
|
23
|
+
import { LogGroupFullRow } from "./row/LogGroupFullRow";
|
|
24
|
+
import { LogGroupInputRow } from "./row/LogGroupInputRow";
|
|
25
|
+
import { LogGroupRow } from "./row/LogGroupRow";
|
|
26
|
+
import { NamirasoftLogServer } from "./NamirasoftLogServer";
|
|
27
|
+
import { NamirasoftLogServerBase } from "./NamirasoftLogServerBase";
|
|
28
|
+
import { SortItem } from "namirasoft-core";
|
|
29
|
+
import { SubscriptionValidation } from "namirasoft-payment";
|
|
30
|
+
|
|
31
|
+
export class NamirasoftLogServerLogGroup extends NamirasoftLogServerBase
|
|
32
|
+
{
|
|
33
|
+
constructor(server: NamirasoftLogServer)
|
|
34
|
+
{
|
|
35
|
+
super(server);
|
|
36
|
+
this._CancelationCheck = this._CancelationCheck.bind(this);
|
|
37
|
+
this.List = this.List.bind(this);
|
|
38
|
+
this.Validation = this.Validation.bind(this);
|
|
39
|
+
this.Usage = this.Usage.bind(this);
|
|
40
|
+
this.Get = this.Get.bind(this);
|
|
41
|
+
this.Create = this.Create.bind(this);
|
|
42
|
+
this.Update = this.Update.bind(this);
|
|
43
|
+
this.Delete = this.Delete.bind(this);
|
|
44
|
+
}
|
|
45
|
+
async _CancelationCheck(user_id: string, config?: BaseServerConfig<any>): Promise<void>
|
|
46
|
+
{
|
|
47
|
+
let path = `/application/user/${user_id}/log/group/cancelation/condition`;
|
|
48
|
+
await this.server._get<void>(path, {}, config);
|
|
49
|
+
}
|
|
50
|
+
async List(filters: FilterItem[] | null, page: (number | null), size: (number | null), sorts: SortItem[], config?: BaseServerConfig<any>): Promise<{ rows: LogGroupRow[], count: number }>
|
|
51
|
+
{
|
|
52
|
+
let filters_string_value: string = FilterItem.stringify(filters);
|
|
53
|
+
let sorts_string_value: string = SortItem.stringify(sorts);
|
|
54
|
+
let path = `/log/group/list`;
|
|
55
|
+
let { data } = await this.server._get<{ rows: LogGroupRow[], count: number }>(path, { filters: filters_string_value, page, size, sorts: sorts_string_value }, config);
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
async Validation(config?: BaseServerConfig<any>): Promise<SubscriptionValidation>
|
|
59
|
+
{
|
|
60
|
+
let path = `/log/group/validation`;
|
|
61
|
+
let { data } = await this.server._get<SubscriptionValidation>(path, {}, config);
|
|
62
|
+
return data;
|
|
63
|
+
}
|
|
64
|
+
async Usage(config?: BaseServerConfig<any>): Promise<{ subscribed: boolean, quota: { log_group_record_count: { value: number, unit: string }, log_record_size: { value: number, unit: string }, log_read_size: { value: number, unit: string } }, used: { log_group_record_count: { value: number, unit: string }, log_record_size: { value: number, unit: string }, log_read_size: { value: number, unit: string } } }>
|
|
65
|
+
{
|
|
66
|
+
let path = `/log/group/usage`;
|
|
67
|
+
let { data } = await this.server._get<{ subscribed: boolean, quota: { log_group_record_count: { value: number, unit: string }, log_record_size: { value: number, unit: string }, log_read_size: { value: number, unit: string } }, used: { log_group_record_count: { value: number, unit: string }, log_record_size: { value: number, unit: string }, log_read_size: { value: number, unit: string } } }>(path, {}, config);
|
|
68
|
+
return data;
|
|
69
|
+
}
|
|
70
|
+
async Get(id: string, config?: BaseServerConfig<any>): Promise<LogGroupFullRow>
|
|
71
|
+
{
|
|
72
|
+
let path = `/log/group/${id}`;
|
|
73
|
+
let { data } = await this.server._get<LogGroupFullRow>(path, {}, config);
|
|
74
|
+
return data;
|
|
75
|
+
}
|
|
76
|
+
async Create(body: LogGroupInputRow, config?: BaseServerConfig<any>): Promise<LogGroupRow>
|
|
77
|
+
{
|
|
78
|
+
let path = `/log/group`;
|
|
79
|
+
let { data } = await this.server._post<LogGroupRow>(path, {}, body, config);
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
async Update(id: string, body: LogGroupInputRow, config?: BaseServerConfig<any>): Promise<LogGroupRow>
|
|
83
|
+
{
|
|
84
|
+
let path = `/log/group/${id}`;
|
|
85
|
+
let { data } = await this.server._put<LogGroupRow>(path, {}, body, config);
|
|
86
|
+
return data;
|
|
87
|
+
}
|
|
88
|
+
async Delete(id: string, config?: BaseServerConfig<any>): Promise<void>
|
|
89
|
+
{
|
|
90
|
+
let path = `/log/group/${id}`;
|
|
91
|
+
await this.server._delete<void>(path, {}, config);
|
|
92
|
+
}
|
|
93
93
|
};
|
package/src/StreamConsole.ts
CHANGED
|
@@ -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,68 @@
|
|
|
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
|
-
|
|
20
|
-
{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
+
console.log({ server })
|
|
19
|
+
}
|
|
20
|
+
write(log: Log, formated: { pre: string[], messages: string[], post: string[] }): void
|
|
21
|
+
{
|
|
22
|
+
if (process.env.NAMIRASOFT_STANDALNOE)
|
|
23
|
+
return;
|
|
24
|
+
|
|
25
|
+
console.log({ server: this.server });
|
|
26
|
+
let message = [...formated.pre, ...formated.messages, ...formated.post].join("\n");
|
|
27
|
+
let body = {
|
|
28
|
+
level: log.level.toString(),
|
|
29
|
+
log_group_id: this.log_group_id,
|
|
30
|
+
product_id: this.getProductID(),
|
|
31
|
+
message
|
|
32
|
+
};
|
|
33
|
+
this.queue.push(async () =>
|
|
34
|
+
{
|
|
35
|
+
if (this.user_id)
|
|
36
|
+
await this.server.log._CreateFor(this.user_id, body);
|
|
37
|
+
else
|
|
38
|
+
await this.server.log.Create(body);
|
|
39
|
+
});
|
|
40
|
+
this.processQueue();
|
|
41
|
+
}
|
|
42
|
+
private async processQueue()
|
|
43
|
+
{
|
|
44
|
+
if (this.isProcessing)
|
|
45
|
+
return;
|
|
46
|
+
this.isProcessing = true;
|
|
47
|
+
try
|
|
48
|
+
{
|
|
49
|
+
while (this.queue.length > 0)
|
|
50
|
+
{
|
|
51
|
+
const job = this.queue.shift();
|
|
52
|
+
if (job)
|
|
53
|
+
{
|
|
54
|
+
try
|
|
55
|
+
{
|
|
56
|
+
await job();
|
|
57
|
+
}
|
|
58
|
+
catch (err)
|
|
59
|
+
{
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} finally
|
|
64
|
+
{
|
|
65
|
+
this.isProcessing = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
65
68
|
}
|