@extk/logger-cloudwatch 0.1.1 → 0.1.2
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 +97 -97
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +37 -37
package/README.md
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/badge/extk%E2%9A%A1-expressive-blue?style=for-the-badge&labelColor=1a1a2e&color=4361ee">
|
|
4
|
-
<img alt="extk/expressive logo" src="https://img.shields.io/badge/extk%E2%9A%A1-expressive-blue?style=for-the-badge&labelColor=f0f0f0&color=4361ee">
|
|
5
|
-
</picture>
|
|
6
|
-
</p>
|
|
7
|
-
|
|
8
|
-
# @extk/logger-cloudwatch
|
|
9
|
-
|
|
10
|
-
Opinionated winston loggers with AWS CloudWatch support.
|
|
11
|
-
|
|
12
|
-
## Install
|
|
13
|
-
|
|
14
|
-
```sh
|
|
15
|
-
npm install @extk/logger-cloudwatch
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Loggers
|
|
19
|
-
|
|
20
|
-
### `getCloudwatchLogger(opts)`
|
|
21
|
-
|
|
22
|
-
Streams JSON logs to AWS CloudWatch. Each process gets its own log stream named `YYYY-MM-DD/pid-<pid>`. Creates the log group if it doesn't exist.
|
|
23
|
-
|
|
24
|
-
```ts
|
|
25
|
-
import { getCloudwatchLogger } from '@extk/logger-cloudwatch';
|
|
26
|
-
|
|
27
|
-
const logger = getCloudwatchLogger({
|
|
28
|
-
aws: {
|
|
29
|
-
region: 'us-east-1',
|
|
30
|
-
logGroup: '/my-app/production',
|
|
31
|
-
credentials: {
|
|
32
|
-
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
33
|
-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
logger.info('Request handled', { userId: 123 });
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Optionally attach a context function to merge fields into every log entry:
|
|
42
|
-
|
|
43
|
-
```ts
|
|
44
|
-
const logger = getCloudwatchLogger({
|
|
45
|
-
aws: { ... },
|
|
46
|
-
contextFn: (info) => {
|
|
47
|
-
info['service'] = 'payments';
|
|
48
|
-
return info;
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
| Option | Description |
|
|
54
|
-
|-------------------|-------------|
|
|
55
|
-
| `aws.region` | AWS region |
|
|
56
|
-
| `aws.logGroup` | CloudWatch log group name |
|
|
57
|
-
| `aws.credentials` | `accessKeyId` + `secretAccessKey
|
|
58
|
-
| `contextFn` | Optional transform to add fields to every entry |
|
|
59
|
-
|
|
60
|
-
### `getConsoleLogger()`
|
|
61
|
-
|
|
62
|
-
Logs to stdout. Intended for development or simple services.
|
|
63
|
-
|
|
64
|
-
```ts
|
|
65
|
-
import { getConsoleLogger } from '@extk/logger-cloudwatch';
|
|
66
|
-
|
|
67
|
-
const logger = getConsoleLogger();
|
|
68
|
-
logger.info('Server started');
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### `getFileLogger(name?)`
|
|
72
|
-
|
|
73
|
-
Writes to `./logs/<name>.log`. Cached — calling with the same name returns the same instance.
|
|
74
|
-
|
|
75
|
-
```ts
|
|
76
|
-
import { getFileLogger } from '@extk/logger-cloudwatch';
|
|
77
|
-
|
|
78
|
-
const logger = getFileLogger('app');
|
|
79
|
-
logger.error(new Error('Something went wrong'));
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
| Option | Default |
|
|
83
|
-
|--------|---------|
|
|
84
|
-
| `name` | `'app'` |
|
|
85
|
-
| Output | `./logs/<name>.log` |
|
|
86
|
-
| Level | `debug` |
|
|
87
|
-
|
|
88
|
-
## Log format
|
|
89
|
-
|
|
90
|
-
Console and file loggers use a human-readable format:
|
|
91
|
-
|
|
92
|
-
```
|
|
93
|
-
DD/MM/YYYY HH:mm:ss[LEVEL]: message
|
|
94
|
-
DD/MM/YYYY HH:mm:ss[ERROR]: Error: something\n at ... ← stack trace for errors
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
CloudWatch receives structured JSON with `timestamp`, `level`, `message`, and any extra fields.
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/badge/extk%E2%9A%A1-expressive-blue?style=for-the-badge&labelColor=1a1a2e&color=4361ee">
|
|
4
|
+
<img alt="extk/expressive logo" src="https://img.shields.io/badge/extk%E2%9A%A1-expressive-blue?style=for-the-badge&labelColor=f0f0f0&color=4361ee">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
# @extk/logger-cloudwatch
|
|
9
|
+
|
|
10
|
+
Opinionated winston loggers with AWS CloudWatch support.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install @extk/logger-cloudwatch
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Loggers
|
|
19
|
+
|
|
20
|
+
### `getCloudwatchLogger(opts)`
|
|
21
|
+
|
|
22
|
+
Streams JSON logs to AWS CloudWatch. Each process gets its own log stream named `YYYY-MM-DD/pid-<pid>`. Creates the log group if it doesn't exist.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { getCloudwatchLogger } from '@extk/logger-cloudwatch';
|
|
26
|
+
|
|
27
|
+
const logger = getCloudwatchLogger({
|
|
28
|
+
aws: {
|
|
29
|
+
region: 'us-east-1',
|
|
30
|
+
logGroup: '/my-app/production',
|
|
31
|
+
credentials: {
|
|
32
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
33
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
logger.info('Request handled', { userId: 123 });
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Optionally attach a context function to merge fields into every log entry:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
const logger = getCloudwatchLogger({
|
|
45
|
+
aws: { ... },
|
|
46
|
+
contextFn: (info) => {
|
|
47
|
+
info['service'] = 'payments';
|
|
48
|
+
return info;
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Option | Description |
|
|
54
|
+
|-------------------|-------------|
|
|
55
|
+
| `aws.region` | AWS region |
|
|
56
|
+
| `aws.logGroup` | CloudWatch log group name |
|
|
57
|
+
| `aws.credentials` | Optional `accessKeyId` + `secretAccessKey`. Omit to use the AWS default credential chain (e.g. an EC2 instance role) |
|
|
58
|
+
| `contextFn` | Optional transform to add fields to every entry |
|
|
59
|
+
|
|
60
|
+
### `getConsoleLogger()`
|
|
61
|
+
|
|
62
|
+
Logs to stdout. Intended for development or simple services.
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { getConsoleLogger } from '@extk/logger-cloudwatch';
|
|
66
|
+
|
|
67
|
+
const logger = getConsoleLogger();
|
|
68
|
+
logger.info('Server started');
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### `getFileLogger(name?)`
|
|
72
|
+
|
|
73
|
+
Writes to `./logs/<name>.log`. Cached — calling with the same name returns the same instance.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { getFileLogger } from '@extk/logger-cloudwatch';
|
|
77
|
+
|
|
78
|
+
const logger = getFileLogger('app');
|
|
79
|
+
logger.error(new Error('Something went wrong'));
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
| Option | Default |
|
|
83
|
+
|--------|---------|
|
|
84
|
+
| `name` | `'app'` |
|
|
85
|
+
| Output | `./logs/<name>.log` |
|
|
86
|
+
| Level | `debug` |
|
|
87
|
+
|
|
88
|
+
## Log format
|
|
89
|
+
|
|
90
|
+
Console and file loggers use a human-readable format:
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
DD/MM/YYYY HH:mm:ss[LEVEL]: message
|
|
94
|
+
DD/MM/YYYY HH:mm:ss[ERROR]: Error: something\n at ... ← stack trace for errors
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
CloudWatch receives structured JSON with `timestamp`, `level`, `message`, and any extra fields.
|
package/dist/index.d.mts
CHANGED
|
@@ -9,10 +9,11 @@ type options = {
|
|
|
9
9
|
aws: {
|
|
10
10
|
region: string;
|
|
11
11
|
logGroup: string;
|
|
12
|
-
|
|
12
|
+
/** Omit to use the AWS SDK default credential chain (EC2/ECS role, env vars, profile). */
|
|
13
|
+
credentials?: {
|
|
13
14
|
accessKeyId: string;
|
|
14
15
|
secretAccessKey: string;
|
|
15
|
-
};
|
|
16
|
+
} | undefined;
|
|
16
17
|
};
|
|
17
18
|
contextFn?: winston.Logform.TransformFunction;
|
|
18
19
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -9,10 +9,11 @@ type options = {
|
|
|
9
9
|
aws: {
|
|
10
10
|
region: string;
|
|
11
11
|
logGroup: string;
|
|
12
|
-
|
|
12
|
+
/** Omit to use the AWS SDK default credential chain (EC2/ECS role, env vars, profile). */
|
|
13
|
+
credentials?: {
|
|
13
14
|
accessKeyId: string;
|
|
14
15
|
secretAccessKey: string;
|
|
15
|
-
};
|
|
16
|
+
} | undefined;
|
|
16
17
|
};
|
|
17
18
|
contextFn?: winston.Logform.TransformFunction;
|
|
18
19
|
};
|
package/dist/index.js
CHANGED
|
@@ -100,8 +100,8 @@ var getCloudwatchLogger = (opts) => {
|
|
|
100
100
|
logGroupName: opts.aws.logGroup,
|
|
101
101
|
logStreamName: `${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}/pid-${process.pid}`,
|
|
102
102
|
awsRegion: opts.aws.region,
|
|
103
|
-
awsAccessKeyId: opts.aws.credentials
|
|
104
|
-
awsSecretKey: opts.aws.credentials
|
|
103
|
+
awsAccessKeyId: opts.aws.credentials?.accessKeyId,
|
|
104
|
+
awsSecretKey: opts.aws.credentials?.secretAccessKey,
|
|
105
105
|
jsonMessage: true,
|
|
106
106
|
ensureLogGroup: true
|
|
107
107
|
})
|
package/dist/index.mjs
CHANGED
|
@@ -64,8 +64,8 @@ var getCloudwatchLogger = (opts) => {
|
|
|
64
64
|
logGroupName: opts.aws.logGroup,
|
|
65
65
|
logStreamName: `${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}/pid-${process.pid}`,
|
|
66
66
|
awsRegion: opts.aws.region,
|
|
67
|
-
awsAccessKeyId: opts.aws.credentials
|
|
68
|
-
awsSecretKey: opts.aws.credentials
|
|
67
|
+
awsAccessKeyId: opts.aws.credentials?.accessKeyId,
|
|
68
|
+
awsSecretKey: opts.aws.credentials?.secretAccessKey,
|
|
69
69
|
jsonMessage: true,
|
|
70
70
|
ensureLogGroup: true
|
|
71
71
|
})
|
package/package.json
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@extk/logger-cloudwatch",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"type": "commonjs",
|
|
5
|
-
"publishConfig": {
|
|
6
|
-
"access": "public"
|
|
7
|
-
},
|
|
8
|
-
"files": [
|
|
9
|
-
"dist"
|
|
10
|
-
],
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"types": "./dist/index.d.ts",
|
|
14
|
-
"import": "./dist/index.mjs",
|
|
15
|
-
"require": "./dist/index.js"
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"engines": {
|
|
19
|
-
"node": ">=22.0.0"
|
|
20
|
-
},
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "tsup",
|
|
23
|
-
"prepublishOnly": "npm run build"
|
|
24
|
-
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"winston": "^3.11.0",
|
|
27
|
-
"winston-cloudwatch": "^6.3.0"
|
|
28
|
-
},
|
|
29
|
-
"license": "ISC",
|
|
30
|
-
"description": "AWS CloudWatch logger",
|
|
31
|
-
"repository": {
|
|
32
|
-
"type": "git",
|
|
33
|
-
"url": "https://github.com/sergeytangyan/extk-logger",
|
|
34
|
-
"directory": "packages/cloudwatch"
|
|
35
|
-
},
|
|
36
|
-
"homepage": "https://github.com/sergeytangyan/extk-logger/tree/main/packages/cloudwatch#readme"
|
|
37
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@extk/logger-cloudwatch",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=22.0.0"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"winston": "^3.11.0",
|
|
27
|
+
"winston-cloudwatch": "^6.3.0"
|
|
28
|
+
},
|
|
29
|
+
"license": "ISC",
|
|
30
|
+
"description": "AWS CloudWatch logger",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/sergeytangyan/extk-logger",
|
|
34
|
+
"directory": "packages/cloudwatch"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/sergeytangyan/extk-logger/tree/main/packages/cloudwatch#readme"
|
|
37
|
+
}
|