namirasoft-log 1.0.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/README.md +205 -0
- package/dist/BaseFormatter.d.ts +6 -0
- package/dist/BaseFormatter.js +28 -0
- package/dist/BaseFormatter.js.map +1 -0
- package/dist/FormatterFull.d.ts +6 -0
- package/dist/FormatterFull.js +33 -0
- package/dist/FormatterFull.js.map +1 -0
- package/dist/FormatterShort.d.ts +6 -0
- package/dist/FormatterShort.js +26 -0
- package/dist/FormatterShort.js.map +1 -0
- package/dist/IFormatter.d.ts +4 -0
- package/dist/IFormatter.js +3 -0
- package/dist/IFormatter.js.map +1 -0
- package/dist/ILogger.d.ts +15 -0
- package/dist/ILogger.js +3 -0
- package/dist/ILogger.js.map +1 -0
- package/dist/IStream.d.ts +4 -0
- package/dist/IStream.js +3 -0
- package/dist/IStream.js.map +1 -0
- package/dist/Log.d.ts +9 -0
- package/dist/Log.js +14 -0
- package/dist/Log.js.map +1 -0
- package/dist/LogLevel.d.ts +10 -0
- package/dist/LogLevel.js +15 -0
- package/dist/LogLevel.js.map +1 -0
- package/dist/Logger.d.ts +26 -0
- package/dist/Logger.js +108 -0
- package/dist/Logger.js.map +1 -0
- package/dist/NamirasoftLogServer.d.ts +2 -0
- package/dist/NamirasoftLogServer.js +7 -0
- package/dist/NamirasoftLogServer.js.map +1 -0
- package/dist/StreamConsole.d.ts +5 -0
- package/dist/StreamConsole.js +41 -0
- package/dist/StreamConsole.js.map +1 -0
- package/dist/StreamFile.d.ts +13 -0
- package/dist/StreamFile.js +79 -0
- package/dist/StreamFile.js.map +1 -0
- package/dist/StreamNamirasoftLog.d.ts +7 -0
- package/dist/StreamNamirasoftLog.js +23 -0
- package/dist/StreamNamirasoftLog.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/package.json +13 -0
- package/src/BaseFormatter.ts +28 -0
- package/src/FormatterFull.ts +22 -0
- package/src/FormatterShort.ts +15 -0
- package/src/IFormatter.ts +6 -0
- package/src/ILogger.ts +17 -0
- package/src/IStream.ts +5 -0
- package/src/Log.ts +18 -0
- package/src/LogLevel.ts +11 -0
- package/src/Logger.ts +89 -0
- package/src/NamirasoftLogServer.ts +3 -0
- package/src/StreamConsole.ts +31 -0
- package/src/StreamFile.ts +52 -0
- package/src/StreamNamirasoftLog.ts +14 -0
- package/src/index.ts +13 -0
- package/tsconfig.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
|
|
2
|
+
# Namirasoft TS SDK Log
|
|
3
|
+
|
|
4
|
+
**Namira Software Corporation Log Package**
|
|
5
|
+
is a powerful Node.js library designed to simplify the management of logging, error handling, and notifications within your applications. With a focus on flexibility and extensibility, this library empowers developers to effortlessly control how their applications log information, handle errors, and send notifications across various channels such as Telegram, email, SMS, and push notifications. Whether you need to track critical events, respond to unhandled exceptions, or deliver real-time alerts to different stakeholders, it provides a robust solution with a straightforward API. Customize the behavior to suit your unique use case and seamlessly integrate it into your projects to enhance both monitoring and communication capabilities. Streamline your development workflow and enhance the reliability of your applications with Namira Software Corporation Log Package.
|
|
6
|
+
[Namira Software Corporation](https://namirasoft.com)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
This library provides the following key features:
|
|
11
|
+
|
|
12
|
+
1. **Logging:** Log messages to various sources such as the console, files, database and [Namirasoft Log Server](https://log.namirasoft.com)
|
|
13
|
+
2. **Error Handling:** Catch all unhandled errors in your Node.js application.
|
|
14
|
+
3. **Notifications:** Send messages and alerts through different media (Email, SMS, Telegram, push notifications, and etc.) based on configurable conditions. You can find more here [Namirasoft Log Server](https://log.namirasoft.com)
|
|
15
|
+
|
|
16
|
+
You can customize the library's behavior and integrate it with various notification platforms to suit your specific use case.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install namirasoft-node
|
|
22
|
+
```
|
|
23
|
+
## Import
|
|
24
|
+
First you need to import it.
|
|
25
|
+
- JavaScript
|
|
26
|
+
```js
|
|
27
|
+
let Logger = require("namirasoft-node");
|
|
28
|
+
```
|
|
29
|
+
- TypeScript
|
|
30
|
+
```js
|
|
31
|
+
import { Logger } from "namirasoft-node";
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Make a Logger
|
|
35
|
+
To make a logger please use this:
|
|
36
|
+
|
|
37
|
+
- JavaScript
|
|
38
|
+
```js
|
|
39
|
+
let logger = new Logger();
|
|
40
|
+
```
|
|
41
|
+
- TypeScript
|
|
42
|
+
```js
|
|
43
|
+
let logger: Logger = new Logger();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
#### Normal Logging
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
logger.trace("This is a test for trace");
|
|
51
|
+
logger.verbose("This is a test for verbose");
|
|
52
|
+
logger.debug("This is a test for debug");
|
|
53
|
+
logger.info("This is a test for info");
|
|
54
|
+
logger.warning("This is a test for warning");
|
|
55
|
+
logger.error("This is a test for error");
|
|
56
|
+
logger.critical("This is a test for critical");
|
|
57
|
+
logger.fatal("This is a test for fatal");
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Grouping Logs
|
|
61
|
+
```js
|
|
62
|
+
logger.error("Out of stuck", "Payment");
|
|
63
|
+
logger.error("Can not find your account", "Account");
|
|
64
|
+
logger.warning("You account is not verified yet.", "Account");
|
|
65
|
+
logger.Info("Invoice has been paid successfully", "Payment");
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Extra and Stack information
|
|
69
|
+
```js
|
|
70
|
+
logger.debug("message", "group", "More details go here");
|
|
71
|
+
logger.error("message", "group", "More details go here");
|
|
72
|
+
logger.warning("message", "group", "More details go here");
|
|
73
|
+
logger.fatal("message", "group", "More details go here");
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### Loggin errors on catch
|
|
77
|
+
```js
|
|
78
|
+
try
|
|
79
|
+
{
|
|
80
|
+
// some bad codes here making error
|
|
81
|
+
}
|
|
82
|
+
catch(e)
|
|
83
|
+
{
|
|
84
|
+
logger.onCatchError(e);
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
```js
|
|
88
|
+
try
|
|
89
|
+
{
|
|
90
|
+
// some bad codes here making error
|
|
91
|
+
}
|
|
92
|
+
catch(e)
|
|
93
|
+
{
|
|
94
|
+
logger.onCatchCritical(e);
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
```js
|
|
98
|
+
try
|
|
99
|
+
{
|
|
100
|
+
// some bad codes here making error
|
|
101
|
+
}
|
|
102
|
+
catch(e)
|
|
103
|
+
{
|
|
104
|
+
logger.onCatchFatal(e);
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Error Handling
|
|
109
|
+
To handle all unhandled exceptions on the entire project:
|
|
110
|
+
```js
|
|
111
|
+
logger.initUncought();
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Streams
|
|
115
|
+
### Console
|
|
116
|
+
To add a stream on console which is the default stream use:
|
|
117
|
+
```js
|
|
118
|
+
import { StreamConsole } from "namirasoft-node";
|
|
119
|
+
|
|
120
|
+
logger.addStream(new StreamConsole());
|
|
121
|
+
```
|
|
122
|
+
### File
|
|
123
|
+
|
|
124
|
+
To add a stream on file:
|
|
125
|
+
```js
|
|
126
|
+
import { StreamFile} from "namirasoft-node";
|
|
127
|
+
let streamFile = new StreamFile("Your-Custom-Path"); // your can pss "" for argument
|
|
128
|
+
streamFile.seprateByDate = true; // this is the default value
|
|
129
|
+
streamFile.seprateByGroup = false; // this is the default value
|
|
130
|
+
streamFile.seprateByLevel = true; // this is the default value
|
|
131
|
+
logger.addStream(streamFile);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Namirasoft Log
|
|
135
|
+
To add a stream on Namirasoft Log API which gives which is the default stream use:
|
|
136
|
+
```js
|
|
137
|
+
import { StreamNamirasoftLog } from "namirasoft-node";
|
|
138
|
+
logger.addStream(new StreamNamirasoftLog("Your-Token"));
|
|
139
|
+
```
|
|
140
|
+
You can get your token [Here](https://log.namirasoft.com) after creating your account and project.
|
|
141
|
+
|
|
142
|
+
### Custom
|
|
143
|
+
It is also possible to create custom stream like for database:
|
|
144
|
+
|
|
145
|
+
fist create your custom class like
|
|
146
|
+
```ts
|
|
147
|
+
import { IStream } from "./IStream";
|
|
148
|
+
import { Log } from "./Log";
|
|
149
|
+
import { LogLevel } from './LogLevel';
|
|
150
|
+
|
|
151
|
+
export class MyCustomStream implements IStream
|
|
152
|
+
{
|
|
153
|
+
async write(log: Log, formated: string[]): Promise<void>
|
|
154
|
+
{
|
|
155
|
+
// save log or formated
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
Then add it to your logger
|
|
160
|
+
```ts
|
|
161
|
+
logger.addStream(new MyCustomStream());
|
|
162
|
+
```
|
|
163
|
+
You can get your token [Here](https://log.namirasoft.com) after creating your account and project.
|
|
164
|
+
|
|
165
|
+
## Formatters
|
|
166
|
+
|
|
167
|
+
### Full
|
|
168
|
+
To set a full formatter which is the default formatter use:
|
|
169
|
+
```js
|
|
170
|
+
import { FormatterFull } from "namirasoft-node";
|
|
171
|
+
logger.setFromatter(new FormatterFull());
|
|
172
|
+
```
|
|
173
|
+
### Short
|
|
174
|
+
To set a short formatter use:
|
|
175
|
+
```js
|
|
176
|
+
import { FormatterShort } from "namirasoft-node";
|
|
177
|
+
logger.setFromatter(new FormatterShort());
|
|
178
|
+
```
|
|
179
|
+
### Level-Based
|
|
180
|
+
To set a different formatter for each Log Level use:
|
|
181
|
+
```js
|
|
182
|
+
import { LogLevel, FormatterShort, FormatterFull } from "namirasoft-node";
|
|
183
|
+
|
|
184
|
+
logger.setCustomFormatter(LogLevel.Info, new FormatterShort());
|
|
185
|
+
logger.setCustomFormatter(LogLevel.Error, new FormatterFull());
|
|
186
|
+
```
|
|
187
|
+
### Custom
|
|
188
|
+
To make a custom formatter make a formatter class like:
|
|
189
|
+
```ts
|
|
190
|
+
import { BaseFormatter, IFormatter, Log } from "namirasoft-node";
|
|
191
|
+
|
|
192
|
+
export class MyCustomFormatter extends BaseFormatter implements IFormatter
|
|
193
|
+
{
|
|
194
|
+
async format(log: Log): Promise<string[]>
|
|
195
|
+
{
|
|
196
|
+
let ans: string[] = [];
|
|
197
|
+
ans.push(this.formatDateTime(log.date) + ": " + log.message);
|
|
198
|
+
return ans;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
Then add it to your logger
|
|
203
|
+
```ts
|
|
204
|
+
logger.addStream(new MyCustomFormatter());
|
|
205
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseFormatter = void 0;
|
|
4
|
+
class BaseFormatter {
|
|
5
|
+
formatDateTime(date) {
|
|
6
|
+
return this.formatDate(date) + " " + this.formatTime(date);
|
|
7
|
+
}
|
|
8
|
+
formatDate(date) {
|
|
9
|
+
const year = date.getFullYear();
|
|
10
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
11
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
12
|
+
return `${year}-${month}-${day}`;
|
|
13
|
+
}
|
|
14
|
+
formatTime(date) {
|
|
15
|
+
const hours = String(date.getHours()).padStart(2, '0');
|
|
16
|
+
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
17
|
+
const seconds = String(date.getSeconds()).padStart(2, '0');
|
|
18
|
+
return `${hours}:${minutes}:${seconds}`;
|
|
19
|
+
}
|
|
20
|
+
qoute(text, size, filler) {
|
|
21
|
+
let count = (size - text.length) / 2;
|
|
22
|
+
text = text.padStart(text.length + count, filler);
|
|
23
|
+
text = text.padEnd(size, filler);
|
|
24
|
+
return text;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.B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IAAI,KAAK,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,EAAE,MAAM,CAAC,CAAC;QAClD,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA3BD,sCA2BC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FormatterFull = void 0;
|
|
13
|
+
const BaseFormatter_1 = require("./BaseFormatter");
|
|
14
|
+
const LogLevel_1 = require("./LogLevel");
|
|
15
|
+
class FormatterFull extends BaseFormatter_1.BaseFormatter {
|
|
16
|
+
format(log) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
let ans = [];
|
|
19
|
+
ans.push(this.qoute(this.formatDateTime(log.date), 100, '-'));
|
|
20
|
+
ans.push("Level: " + LogLevel_1.LogLevel[log.level]);
|
|
21
|
+
if (log.group)
|
|
22
|
+
ans.push("Group: " + log.group);
|
|
23
|
+
ans.push("Message: " + log.message);
|
|
24
|
+
if (log.stack)
|
|
25
|
+
ans.push("Stack: " + log.stack);
|
|
26
|
+
ans.push(this.qoute("", 100, '-'));
|
|
27
|
+
ans.push("");
|
|
28
|
+
return ans;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.FormatterFull = FormatterFull;
|
|
33
|
+
//# sourceMappingURL=FormatterFull.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormatterFull.js","sourceRoot":"","sources":["../src/FormatterFull.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAgD;AAGhD,yCAAsC;AAEtC,MAAa,aAAc,SAAQ,6BAAa;IAEtC,MAAM,CAAC,GAAQ;;YAEjB,IAAI,GAAG,GAAa,EAAE,CAAC;YACvB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;YAC9D,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,mBAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YAC1C,IAAI,GAAG,CAAC,KAAK;gBACT,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;YACpC,GAAG,CAAC,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC;YACpC,IAAI,GAAG,CAAC,KAAK;gBACT,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;YACpC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;YACnC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACb,OAAO,GAAG,CAAC;QACf,CAAC;KAAA;CACJ;AAhBD,sCAgBC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FormatterShort = void 0;
|
|
13
|
+
const BaseFormatter_1 = require("./BaseFormatter");
|
|
14
|
+
class FormatterShort extends BaseFormatter_1.BaseFormatter {
|
|
15
|
+
format(log) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
let ans = [];
|
|
18
|
+
ans.push(this.formatDateTime(log.date) + ": " + [log.group, log.message].filter(m => m).join(" - "));
|
|
19
|
+
if (log.stack)
|
|
20
|
+
ans.push(log.stack);
|
|
21
|
+
return ans;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.FormatterShort = FormatterShort;
|
|
26
|
+
//# sourceMappingURL=FormatterShort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormatterShort.js","sourceRoot":"","sources":["../src/FormatterShort.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAgD;AAIhD,MAAa,cAAe,SAAQ,6BAAa;IAEvC,MAAM,CAAC,GAAQ;;YAEjB,IAAI,GAAG,GAAa,EAAE,CAAC;YACvB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YACrG,IAAI,GAAG,CAAC,KAAK;gBACT,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACxB,OAAO,GAAG,CAAC;QACf,CAAC;KAAA;CACJ;AAVD,wCAUC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IFormatter.js","sourceRoot":"","sources":["../src/IFormatter.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LogLevel } from "./LogLevel";
|
|
2
|
+
export interface ILogger {
|
|
3
|
+
log(level: LogLevel, message: string, group?: string, stack?: string): Promise<void>;
|
|
4
|
+
trace(message: string, group?: string, stack?: string): Promise<void>;
|
|
5
|
+
verbose(message: string, group?: string, stack?: string): Promise<void>;
|
|
6
|
+
debug(message: string, group?: string, stack?: string): Promise<void>;
|
|
7
|
+
info(message: string, group?: string, stack?: string): Promise<void>;
|
|
8
|
+
warning(message: string, group?: string, stack?: string): Promise<void>;
|
|
9
|
+
error(message: string, group?: string, stack?: string): Promise<void>;
|
|
10
|
+
critical(message: string, group?: string, stack?: string): Promise<void>;
|
|
11
|
+
fatal(message: string, group?: string, stack?: string): Promise<void>;
|
|
12
|
+
onCatchError(error: Error, group?: string): Promise<void>;
|
|
13
|
+
onCatchCritical(error: Error, group?: string): Promise<void>;
|
|
14
|
+
onCatchFatal(error: Error, group?: string): Promise<void>;
|
|
15
|
+
}
|
package/dist/ILogger.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILogger.js","sourceRoot":"","sources":["../src/ILogger.ts"],"names":[],"mappings":""}
|
package/dist/IStream.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IStream.js","sourceRoot":"","sources":["../src/IStream.ts"],"names":[],"mappings":""}
|
package/dist/Log.d.ts
ADDED
package/dist/Log.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Log = void 0;
|
|
4
|
+
class Log {
|
|
5
|
+
constructor(level, message, group, stack) {
|
|
6
|
+
this.date = new Date();
|
|
7
|
+
this.level = level;
|
|
8
|
+
this.message = message;
|
|
9
|
+
this.group = group !== null && group !== void 0 ? group : "";
|
|
10
|
+
this.stack = stack !== null && stack !== void 0 ? stack : "";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Log = Log;
|
|
14
|
+
//# sourceMappingURL=Log.js.map
|
package/dist/Log.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Log.js","sourceRoot":"","sources":["../src/Log.ts"],"names":[],"mappings":";;;AAEA,MAAa,GAAG;IAOZ,YAAY,KAAe,EAAE,OAAe,EAAE,KAAc,EAAE,KAAc;QAExE,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAC;IAC7B,CAAC;CACJ;AAfD,kBAeC"}
|
package/dist/LogLevel.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogLevel = void 0;
|
|
4
|
+
var LogLevel;
|
|
5
|
+
(function (LogLevel) {
|
|
6
|
+
LogLevel[LogLevel["Trace"] = 0] = "Trace";
|
|
7
|
+
LogLevel[LogLevel["Verbose"] = 1] = "Verbose";
|
|
8
|
+
LogLevel[LogLevel["Debug"] = 2] = "Debug";
|
|
9
|
+
LogLevel[LogLevel["Info"] = 3] = "Info";
|
|
10
|
+
LogLevel[LogLevel["Warning"] = 4] = "Warning";
|
|
11
|
+
LogLevel[LogLevel["Error"] = 5] = "Error";
|
|
12
|
+
LogLevel[LogLevel["Critical"] = 6] = "Critical";
|
|
13
|
+
LogLevel[LogLevel["Fatal"] = 7] = "Fatal";
|
|
14
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
15
|
+
//# sourceMappingURL=LogLevel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LogLevel.js","sourceRoot":"","sources":["../src/LogLevel.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAUX;AAVD,WAAY,QAAQ;IAEhB,yCAAO,CAAA;IACP,6CAAS,CAAA;IACT,yCAAO,CAAA;IACP,uCAAM,CAAA;IACN,6CAAS,CAAA;IACT,yCAAO,CAAA;IACP,+CAAU,CAAA;IACV,yCAAO,CAAA;AACX,CAAC,EAVW,QAAQ,wBAAR,QAAQ,QAUnB"}
|
package/dist/Logger.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IFormatter } from "./IFormatter";
|
|
2
|
+
import { ILogger } from "./ILogger";
|
|
3
|
+
import { IStream } from "./IStream";
|
|
4
|
+
import { LogLevel } from "./LogLevel";
|
|
5
|
+
export declare class Logger implements ILogger {
|
|
6
|
+
private defaultStream;
|
|
7
|
+
private formatter?;
|
|
8
|
+
private customFormatter;
|
|
9
|
+
private streams;
|
|
10
|
+
setFromatter(formatter: IFormatter): void;
|
|
11
|
+
setCustomFormatter(level: LogLevel, formatter: IFormatter): void;
|
|
12
|
+
addStream(stream: IStream): void;
|
|
13
|
+
log(level: LogLevel, message: string, group?: string, stack?: string): Promise<void>;
|
|
14
|
+
trace(message: string, group?: string, stack?: string): Promise<void>;
|
|
15
|
+
verbose(message: string, group?: string, stack?: string): Promise<void>;
|
|
16
|
+
debug(message: string, group?: string, stack?: string): Promise<void>;
|
|
17
|
+
info(message: string, group?: string, stack?: string): Promise<void>;
|
|
18
|
+
warning(message: string, group?: string, stack?: string): Promise<void>;
|
|
19
|
+
error(message: string, group?: string, stack?: string): Promise<void>;
|
|
20
|
+
critical(message: string, group?: string, stack?: string): Promise<void>;
|
|
21
|
+
fatal(message: string, group?: string, stack?: string): Promise<void>;
|
|
22
|
+
onCatchError(error: Error, group?: string): Promise<void>;
|
|
23
|
+
onCatchCritical(error: Error, group?: string): Promise<void>;
|
|
24
|
+
onCatchFatal(error: Error, group?: string): Promise<void>;
|
|
25
|
+
initUncought(): void;
|
|
26
|
+
}
|
package/dist/Logger.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Logger = void 0;
|
|
13
|
+
const FormatterFull_1 = require("./FormatterFull");
|
|
14
|
+
const Log_1 = require("./Log");
|
|
15
|
+
const LogLevel_1 = require("./LogLevel");
|
|
16
|
+
const StreamConsole_1 = require("./StreamConsole");
|
|
17
|
+
class Logger {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.defaultStream = new StreamConsole_1.StreamConsole();
|
|
20
|
+
this.formatter = new FormatterFull_1.FormatterFull();
|
|
21
|
+
this.customFormatter = {};
|
|
22
|
+
this.streams = [];
|
|
23
|
+
}
|
|
24
|
+
setFromatter(formatter) {
|
|
25
|
+
this.formatter = formatter;
|
|
26
|
+
}
|
|
27
|
+
setCustomFormatter(level, formatter) {
|
|
28
|
+
this.customFormatter[level] = formatter;
|
|
29
|
+
}
|
|
30
|
+
addStream(stream) {
|
|
31
|
+
this.streams.push(stream);
|
|
32
|
+
}
|
|
33
|
+
log(level, message, group, stack) {
|
|
34
|
+
var _a;
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
let log = new Log_1.Log(level, message, group, stack);
|
|
37
|
+
let formatted = [];
|
|
38
|
+
let formatter = (_a = this.customFormatter[level.toString()]) !== null && _a !== void 0 ? _a : this.formatter;
|
|
39
|
+
if (formatter)
|
|
40
|
+
formatted = yield formatter.format(log);
|
|
41
|
+
if (this.streams.length == 0)
|
|
42
|
+
this.defaultStream.write(log, formatted);
|
|
43
|
+
else {
|
|
44
|
+
let ps = this.streams.map(s => s.write(log, formatted));
|
|
45
|
+
yield Promise.all(ps);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
trace(message, group, stack) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
yield this.log(LogLevel_1.LogLevel.Trace, message, group, stack);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
verbose(message, group, stack) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
yield this.log(LogLevel_1.LogLevel.Verbose, message, group, stack);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
debug(message, group, stack) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
yield this.log(LogLevel_1.LogLevel.Debug, message, group, stack);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
info(message, group, stack) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
yield this.log(LogLevel_1.LogLevel.Info, message, group, stack);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
warning(message, group, stack) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
yield this.log(LogLevel_1.LogLevel.Warning, message, group, stack);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
error(message, group, stack) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
yield this.log(LogLevel_1.LogLevel.Error, message, group, stack);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
critical(message, group, stack) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
yield this.log(LogLevel_1.LogLevel.Critical, message, group, stack);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
fatal(message, group, stack) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
yield this.log(LogLevel_1.LogLevel.Fatal, message, group, stack);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
onCatchError(error, group) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
yield this.error(error.message, group, error.stack);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
onCatchCritical(error, group) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
yield this.critical(error.message, group, error.stack);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
onCatchFatal(error, group) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
yield this.fatal(error.message, group, error.stack);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
initUncought() {
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.Logger = Logger;
|
|
108
|
+
//# sourceMappingURL=Logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Log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C,GAAG,CAAC,mBAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC7D,CAAC;KAAA;IACK,KAAK,CAAC,OAAe,EAAE,KAAc,EAAE,KAAc;;YAEvD,MAAM,IAAI,CAAC,GAAG,CAAC,mBAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC1D,CAAC;KAAA;IACK,YAAY,CAAC,KAAY,EAAE,KAAc;;YAE3C,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC;KAAA;IACK,eAAe,CAAC,KAAY,EAAE,KAAc;;YAE9C,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3D,CAAC;KAAA;IACK,YAAY,CAAC,KAAY,EAAE,KAAc;;YAE3C,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC;KAAA;IACD,YAAY;IAEZ,CAAC;CACJ;AAhFD,wBAgFC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NamirasoftLogServer.js","sourceRoot":"","sources":["../src/NamirasoftLogServer.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAmB;CAE/B;AAFD,kDAEC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.StreamConsole = void 0;
|
|
13
|
+
const LogLevel_1 = require("./LogLevel");
|
|
14
|
+
class StreamConsole {
|
|
15
|
+
write(log, formated) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
formated.forEach(f => {
|
|
18
|
+
if (log.level == LogLevel_1.LogLevel.Trace)
|
|
19
|
+
console.trace(f);
|
|
20
|
+
else if (log.level == LogLevel_1.LogLevel.Verbose)
|
|
21
|
+
console.log(f);
|
|
22
|
+
else if (log.level == LogLevel_1.LogLevel.Debug)
|
|
23
|
+
console.debug(f);
|
|
24
|
+
else if (log.level == LogLevel_1.LogLevel.Info)
|
|
25
|
+
console.info(f);
|
|
26
|
+
else if (log.level == LogLevel_1.LogLevel.Warning)
|
|
27
|
+
console.warn(f);
|
|
28
|
+
else if (log.level == LogLevel_1.LogLevel.Error)
|
|
29
|
+
console.error(f);
|
|
30
|
+
else if (log.level == LogLevel_1.LogLevel.Critical)
|
|
31
|
+
console.error(f);
|
|
32
|
+
else if (log.level == LogLevel_1.LogLevel.Fatal)
|
|
33
|
+
console.error(f);
|
|
34
|
+
else
|
|
35
|
+
console.log(f);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.StreamConsole = StreamConsole;
|
|
41
|
+
//# sourceMappingURL=StreamConsole.js.map
|