http-system-logger 1.0.3 → 1.0.4
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 +82 -0
- package/package.json +47 -35
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# HTTP System Logger
|
|
2
|
+
|
|
3
|
+
A lightweight and configurable logging library for Node.js applications, built with `winston` and `morgan`.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Console and file-based logging with daily rotation.
|
|
8
|
+
- HTTP request logging using `morgan`.
|
|
9
|
+
- Customizable log levels and formats.
|
|
10
|
+
- Supports structured JSON logs for better integration with log management systems.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Install the library and its dependencies:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install http-system-logger
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Logger Class
|
|
23
|
+
|
|
24
|
+
The `Logger` class provides methods for logging messages at different levels (`info`, `error`, `warn`, `debug`).
|
|
25
|
+
|
|
26
|
+
#### Example:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { Logger } from 'http-system-logger';
|
|
30
|
+
|
|
31
|
+
const logger = new Logger('MyAppContext');
|
|
32
|
+
|
|
33
|
+
// Log an informational message
|
|
34
|
+
logger.info('This is an info message');
|
|
35
|
+
|
|
36
|
+
// Log an error with a stack trace
|
|
37
|
+
logger.error('An error occurred', 'Error stack trace');
|
|
38
|
+
|
|
39
|
+
// Log a warning
|
|
40
|
+
logger.warn('This is a warning');
|
|
41
|
+
|
|
42
|
+
// Log a debug message
|
|
43
|
+
logger.debug('Debugging details');
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### HTTP Request Logging
|
|
47
|
+
|
|
48
|
+
The library includes a `httpLogger` middleware for logging HTTP requests in Express applications.
|
|
49
|
+
|
|
50
|
+
#### Example:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import express from 'express';
|
|
54
|
+
import { httpLogger } from 'http-system-logger';
|
|
55
|
+
|
|
56
|
+
const app = express();
|
|
57
|
+
|
|
58
|
+
// Use the HTTP logger middleware
|
|
59
|
+
app.use(httpLogger);
|
|
60
|
+
|
|
61
|
+
app.get('/', (req, res) => {
|
|
62
|
+
res.send('Hello, world!');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
app.listen(3000, () => {
|
|
66
|
+
console.log('Server is running on port 3000');
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Environment Variables
|
|
71
|
+
|
|
72
|
+
You can configure the logger using the following environment variables:
|
|
73
|
+
|
|
74
|
+
| Variable | Default Value | Description |
|
|
75
|
+
|--------------------|---------------|--------------------------------------------------|
|
|
76
|
+
| `LOG_DIR` | `logs` | Directory where log files are stored. |
|
|
77
|
+
| `LOG_MAX_SIZE` | `4m` | Maximum size of a log file before rotation. |
|
|
78
|
+
| `LOG_MAX_FILES` | `7d` | Maximum number of log files to retain. |
|
|
79
|
+
| `LOG_FILE_NAME` | `application` | Base name for log files. |
|
|
80
|
+
| `SERVICE_NAME` | `logger` | Default service name included in log metadata. |
|
|
81
|
+
|
|
82
|
+
|
package/package.json
CHANGED
|
@@ -1,35 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "http-system-logger",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
-
"build": "npx tsc"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"logger",
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "http-system-logger",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "A lightweight and configurable logging library for Node.js applications, built with winston and morgan.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
+
"build": "npx tsc",
|
|
13
|
+
"prepare": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"node-logger",
|
|
17
|
+
"logger",
|
|
18
|
+
"http-logger",
|
|
19
|
+
"winston",
|
|
20
|
+
"morgan",
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"author": "erik",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/buicuong1303/http-system-logger.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/buicuong1303/http-system-logger/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/buicuong1303/http-system-logger#README",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/express": "^4.17.21",
|
|
35
|
+
"@types/morgan": "^1.9.9",
|
|
36
|
+
"@types/node": "^20.12.5",
|
|
37
|
+
"@types/uuid": "^9.0.8",
|
|
38
|
+
"typescript": "^5.4.4"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"morgan": "^1.10.0",
|
|
42
|
+
"uuid": "^9.0.1",
|
|
43
|
+
"winston": "^3.13.0",
|
|
44
|
+
"winston-daily-rotate-file": "^5.0.0",
|
|
45
|
+
"winston-transport": "^4.7.0"
|
|
46
|
+
}
|
|
47
|
+
}
|