kayvee 3.18.0 → 4.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 +147 -202
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/kayvee.d.ts +12 -0
- package/dist/kayvee.d.ts.map +1 -0
- package/{build/lib → dist}/kayvee.js +17 -30
- package/dist/logger/logger.d.ts +49 -0
- package/dist/logger/logger.d.ts.map +1 -0
- package/{build/lib → dist}/logger/logger.js +91 -83
- package/dist/middleware.d.ts +23 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +196 -0
- package/dist/package.json +89 -0
- package/dist/router/index.d.ts +23 -0
- package/dist/router/index.d.ts.map +1 -0
- package/{build/lib → dist}/router/index.js +33 -45
- package/package.json +63 -27
- package/.circleci/config.yml +0 -25
- package/.eslintrc.js +0 -124
- package/.github/workflows/notify-ci-status.yml +0 -20
- package/.nvmrc +0 -1
- package/.prettierrc.json +0 -1
- package/Makefile +0 -55
- package/benchmarks/data/.keep +0 -1
- package/benchmarks/data/corpus-basic.json +0 -22
- package/benchmarks/data/corpus-pathological.json +0 -22
- package/benchmarks/data/corpus-realistic.json +0 -22
- package/benchmarks/data/kvconfig-basic.yml +0 -7
- package/benchmarks/data/kvconfig-pathological.yml +0 -222
- package/benchmarks/data/kvconfig-realistic.yml +0 -39
- package/benchmarks/routing.js +0 -116
- package/build/lib/logger/helpers.js +0 -0
- package/build/lib/middleware.js +0 -274
- package/build/package.json +0 -53
- package/build/test/context_logger.js +0 -69
- package/build/test/kayvee.js +0 -36
- package/build/test/logger_test.js +0 -345
- package/build/test/middleware.js +0 -556
- package/build/test/router.js +0 -451
- package/index.js +0 -7
- package/lib/kayvee.ts +0 -73
- package/lib/logger/helpers.ts +0 -0
- package/lib/logger/logger.ts +0 -312
- package/lib/middleware.ts +0 -317
- package/lib/router/index.ts +0 -234
- package/lib/router/schema_definitions.json +0 -158
- package/test/context_logger.ts +0 -76
- package/test/kayvee.ts +0 -50
- package/test/kvconfig.yml +0 -14
- package/test/logger_test.ts +0 -378
- package/test/middleware.ts +0 -632
- package/test/router.ts +0 -558
- package/test/static/empty.css +0 -0
- package/test/static/js/empty.js +0 -0
- package/test/tests.json +0 -100
- package/tsconfig.json +0 -10
- /package/{build/lib → dist}/router/schema_definitions.json +0 -0
package/README.md
CHANGED
|
@@ -5,69 +5,111 @@ Package kayvee provides methods to output human and machine parseable strings.
|
|
|
5
5
|
|
|
6
6
|
Read the [Kayvee spec](https://github.com/Clever/kayvee) to learn more about the goals of Kayvee logging.
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Installation
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
```
|
|
11
|
+
npm install kayvee
|
|
12
|
+
```
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
### Logger
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
```ts
|
|
19
|
+
import * as kv from "kayvee";
|
|
20
|
+
|
|
21
|
+
const log = new kv.Logger("my-app");
|
|
22
|
+
|
|
23
|
+
// Title only
|
|
24
|
+
log.info("server-started");
|
|
25
|
+
log.warn("high-memory");
|
|
26
|
+
log.error("db-connection-failed");
|
|
27
|
+
log.critical("out-of-disk");
|
|
28
|
+
|
|
29
|
+
// Title + structured data
|
|
30
|
+
log.infoD("request-handled", { method: "GET", path: "/api/users", duration_ms: 42 });
|
|
31
|
+
log.errorD("db-query-failed", { table: "users", error: err.message });
|
|
16
32
|
```
|
|
17
33
|
|
|
18
|
-
|
|
34
|
+
The constructor signature is:
|
|
19
35
|
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
log.gaugeD("gauge-with-extra-data", 3, {user_id: "value", scope: "scope_system"})
|
|
36
|
+
```ts
|
|
37
|
+
new kv.Logger(source, logLevel?, formatter?, output?)
|
|
23
38
|
```
|
|
24
|
-
and structured logs:
|
|
25
39
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
- `source` (required) — identifies the application or component emitting the log
|
|
41
|
+
- `logLevel` — defaults to `process.env.KAYVEE_LOG_LEVEL` or `"debug"`
|
|
42
|
+
- `formatter` — defaults to `kv.format`
|
|
43
|
+
- `output` — defaults to `console.error`
|
|
44
|
+
|
|
45
|
+
You can also configure after construction:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
log.setLogLevel("warning");
|
|
49
|
+
log.setFormatter(kv.format);
|
|
50
|
+
log.setOutput(console.error);
|
|
29
51
|
```
|
|
30
52
|
|
|
31
|
-
|
|
53
|
+
#### Logging methods
|
|
54
|
+
|
|
55
|
+
Title only:
|
|
56
|
+
|
|
57
|
+
- `log.debug("title")`
|
|
58
|
+
- `log.info("title")`
|
|
59
|
+
- `log.warn("title")`
|
|
60
|
+
- `log.error("title")`
|
|
61
|
+
- `log.critical("title")`
|
|
62
|
+
|
|
63
|
+
Title + metadata:
|
|
32
64
|
|
|
33
|
-
|
|
65
|
+
- `log.debugD("title", { key: "value" })`
|
|
66
|
+
- `log.infoD("title", { key: "value" })`
|
|
67
|
+
- `log.warnD("title", { key: "value" })`
|
|
68
|
+
- `log.errorD("title", { key: "value" })`
|
|
69
|
+
- `log.criticalD("title", { key: "value" })`
|
|
34
70
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
71
|
+
#### Metrics
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
log.counter("counter-name") // defaults to value 1
|
|
75
|
+
log.counterD("counter-name", 5, { extra: "info" })
|
|
76
|
+
log.gauge("gauge-name", 100)
|
|
77
|
+
log.gaugeD("gauge-name", 100, { extra: "info" })
|
|
38
78
|
```
|
|
39
79
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
80
|
+
### Formatters
|
|
81
|
+
|
|
82
|
+
#### `kv.format(data)`
|
|
83
|
+
|
|
84
|
+
Converts a map to stringified JSON, automatically injecting Clever deploy environment variables (`_DEPLOY_ENV`, `_POD_ID`, etc.) when present.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
console.error(kv.format({ hello: "world" }));
|
|
88
|
+
// {"hello":"world"}
|
|
43
89
|
```
|
|
44
90
|
|
|
45
|
-
|
|
91
|
+
#### `kv.formatLog(source, level, title, data)`
|
|
46
92
|
|
|
47
|
-
|
|
93
|
+
Like `format`, but takes reserved logging params:
|
|
48
94
|
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
95
|
+
```ts
|
|
96
|
+
console.error(kv.formatLog("my-app", kv.INFO, "request-handled", { duration_ms: 42 }));
|
|
97
|
+
// {"duration_ms":42,"source":"my-app","level":"info","title":"request-handled"}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Log Routing
|
|
53
101
|
|
|
54
|
-
|
|
102
|
+
Log routing defines where log lines go once they enter Clever's logging pipeline. Routes are defined in `kvconfig.yml`.
|
|
55
103
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
104
|
+
```ts
|
|
105
|
+
// main.ts
|
|
106
|
+
import * as kv from "kayvee";
|
|
59
107
|
|
|
60
|
-
|
|
61
|
-
setImmediate(() => {
|
|
62
|
-
// Output structured data
|
|
63
|
-
log.infoD("DataResults", {"key": "value"}); // Sends slack message
|
|
108
|
+
kv.setGlobalRouting("./kvconfig.yml");
|
|
64
109
|
|
|
65
|
-
|
|
66
|
-
log.infoD("DataResults", {"shorter": "line"}); // will NOT send a slack message
|
|
110
|
+
const log = new kv.Logger("my-app");
|
|
67
111
|
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
};
|
|
112
|
+
log.infoD("DataResults", { key: "value" }); // triggers the route below
|
|
71
113
|
```
|
|
72
114
|
|
|
73
115
|
```yml
|
|
@@ -75,196 +117,99 @@ module.exports = (cb) => {
|
|
|
75
117
|
routes:
|
|
76
118
|
key-val:
|
|
77
119
|
matchers:
|
|
78
|
-
title: [
|
|
79
|
-
key: [
|
|
120
|
+
title: ["DataResults"]
|
|
121
|
+
key: ["value"]
|
|
80
122
|
output:
|
|
81
123
|
type: "notifications"
|
|
82
|
-
channel: "#
|
|
124
|
+
channel: "#my-channel"
|
|
83
125
|
icon: ":rocket:"
|
|
84
126
|
message: "%{key}"
|
|
85
|
-
user: "
|
|
127
|
+
user: "My App"
|
|
86
128
|
```
|
|
87
129
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
To ensure that your log-routing rules are correct, use `mockRouting` to temporarily mock out kayvee. The mock kayvee will record which rules and how often they were matched.
|
|
130
|
+
#### Testing log routing
|
|
91
131
|
|
|
132
|
+
Use `mockRouting` to verify routes in tests:
|
|
92
133
|
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
|
|
134
|
+
```ts
|
|
135
|
+
import * as kv from "kayvee";
|
|
136
|
+
import { main } from "./main";
|
|
96
137
|
|
|
97
|
-
const kv = require("../kayvee-js");
|
|
98
138
|
kv.setGlobalRouting("./kvconfig.yml");
|
|
99
139
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
let ruleMatches = kvdone();
|
|
107
|
-
assert.equal(ruleMatches["key-val"].length, 1);
|
|
108
|
-
});
|
|
140
|
+
kv.mockRouting(done => {
|
|
141
|
+
main(err => {
|
|
142
|
+
const ruleMatches = done();
|
|
143
|
+
assert.equal(ruleMatches["key-val"].length, 1);
|
|
144
|
+
});
|
|
109
145
|
});
|
|
110
146
|
```
|
|
111
147
|
|
|
112
|
-
For more information
|
|
113
|
-
|
|
114
|
-
## Testing
|
|
115
|
-
|
|
116
|
-
Run `make test` to execute the tests
|
|
117
|
-
|
|
118
|
-
## Change log
|
|
119
|
-
|
|
120
|
-
- v3.3.0 - Middleware log lines are now routable
|
|
121
|
-
- v3.2.0 - Exposed support for overriding the value field on metrics and alerts outputs
|
|
122
|
-
- v3.1.0 - Added support for matching on booleans and a wildcard ("*")
|
|
123
|
-
- v3.0.0 - Introduced log-routing
|
|
124
|
-
- v2.4.0 - Add middleware.
|
|
125
|
-
- v2.3.0 - Convert CoffeeScript to ES6 / Typescript.
|
|
126
|
-
- v2.0.0 - Implement `logger` functionality along with support for `gauge` and `counter` metrics
|
|
127
|
-
- v1.0.3 - Readme cleanup.
|
|
128
|
-
- v1.0.2 - Prints stringified JSON, published as Javascript lib to NPM.
|
|
129
|
-
- v0.0.1 - Initial release.
|
|
148
|
+
For more information see https://clever.atlassian.net/wiki/spaces/ENG/pages/90570917/Application+Log+Routing
|
|
130
149
|
|
|
131
|
-
|
|
150
|
+
### Middleware
|
|
132
151
|
|
|
133
|
-
|
|
152
|
+
Kayvee includes Express-compatible logging middleware. Because it depends on
|
|
153
|
+
express types, it is exported from the `kayvee/middleware` subpath rather than
|
|
154
|
+
the package root — so consumers that only use the logger (e.g. generated API
|
|
155
|
+
clients) don't need express installed:
|
|
134
156
|
|
|
135
|
-
|
|
157
|
+
```ts
|
|
158
|
+
import express from "express";
|
|
159
|
+
import { middleware } from "kayvee/middleware";
|
|
136
160
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
var log = new kayvee.Logger(source, logLvl = process.env.KAYVEE_LOG_LEVEL, formatter = kv.format, output = console.error)
|
|
161
|
+
const app = express();
|
|
162
|
+
app.use(middleware({ source: "my-app" }));
|
|
140
163
|
```
|
|
141
164
|
|
|
142
|
-
|
|
165
|
+
Additional options:
|
|
143
166
|
|
|
144
|
-
|
|
167
|
+
- `headers` — array of request header names to log (e.g. `["x-request-id"]`)
|
|
168
|
+
- `handlers` — array of `(req, res) => Record<string, string>` functions for custom fields
|
|
169
|
+
- `ignore_dir` — suppress `2xx` logs for static file requests; object with `directory` (absolute path) and `path` (express mount point, defaults to `/`)
|
|
145
170
|
|
|
146
|
-
```
|
|
147
|
-
|
|
171
|
+
```ts
|
|
172
|
+
app.use(middleware({
|
|
173
|
+
source: "my-app",
|
|
174
|
+
headers: ["x-request-id"],
|
|
175
|
+
handlers: [
|
|
176
|
+
(req, res) => ({ user_id: req.user?.id }),
|
|
177
|
+
],
|
|
178
|
+
}));
|
|
148
179
|
```
|
|
149
180
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
* `log.error("title")`
|
|
164
|
-
* `log.critical("title")`
|
|
165
|
-
|
|
166
|
-
Title + Metadata:
|
|
167
|
-
|
|
168
|
-
* `log.debugD("title" {key1: "value", key2: "val"})`
|
|
169
|
-
* `log.infoD("title" {key1: "value", key2: "val"})`
|
|
170
|
-
* `log.warnD("title" {key1: "value", key2: "val"})`
|
|
171
|
-
* `log.errorD("title" {key1: "value", key2: "val"})`
|
|
172
|
-
* `log.criticalD("title" {key1: "value", key2: "val"})`
|
|
173
|
-
|
|
174
|
-
#### kayvee/logger metrics
|
|
175
|
-
|
|
176
|
-
* `log.counter("counter-name")` defaults to value of `1`
|
|
177
|
-
* `log.gauge("gauge-name", 100)`
|
|
178
|
-
|
|
179
|
-
* `log.counterD("counter-with-data", 2, {extra: "info"})`
|
|
180
|
-
* `log.gaugeD("gauge-with-data", 2, {extra: "info"})`
|
|
181
|
-
|
|
182
|
-
### Formatters
|
|
183
|
-
|
|
184
|
-
#### format
|
|
185
|
-
|
|
186
|
-
```js
|
|
187
|
-
kayvee.format(data)
|
|
181
|
+
Log within a request handler using `req.log`:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
app.get("/things/:id", (req, res) => {
|
|
185
|
+
doTheThing((err, data) => {
|
|
186
|
+
if (err) {
|
|
187
|
+
req.log.errorD("do_the_thing_error", { error: err.message });
|
|
188
|
+
return res.sendStatus(500);
|
|
189
|
+
}
|
|
190
|
+
req.log.infoD("do_the_thing_success", { id: req.params.id });
|
|
191
|
+
res.json(data);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
188
194
|
```
|
|
189
|
-
Format converts a map to stringified json output
|
|
190
195
|
|
|
191
|
-
|
|
196
|
+
## Development
|
|
192
197
|
|
|
193
|
-
```js
|
|
194
|
-
kayvee.formatLog(source, level, title, data)
|
|
195
198
|
```
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
- `source` (string) - locality of the log; an application name or part of an application
|
|
200
|
-
- `level` (string) - available levels are
|
|
201
|
-
- "unknown
|
|
202
|
-
- "critical
|
|
203
|
-
- "error"
|
|
204
|
-
- "warning"
|
|
205
|
-
- "info"
|
|
206
|
-
- `title` (string) - the event that occurred
|
|
207
|
-
- `data` (object) - other parameters describing the event
|
|
208
|
-
|
|
209
|
-
### Middleware
|
|
210
|
-
|
|
211
|
-
Kayvee includes logging middleware, compatible with expressJS.
|
|
212
|
-
|
|
213
|
-
The middleware can be added most simply via
|
|
214
|
-
|
|
215
|
-
```js
|
|
216
|
-
var kayvee = require('kayvee');
|
|
217
|
-
|
|
218
|
-
var app = express();
|
|
219
|
-
app.use(kayvee.middleware({"source":"my-app"}));
|
|
199
|
+
make build # compile TypeScript to dist/
|
|
200
|
+
make test # run tests
|
|
201
|
+
make lint # lint
|
|
220
202
|
```
|
|
221
203
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
The middleware also supports further user configuration via the `options` object.
|
|
225
|
-
It prints the values of `headers` or the results of `handlers`.
|
|
226
|
-
If a value is `undefined`, the key will not be printed.
|
|
227
|
-
|
|
228
|
-
- `headers`
|
|
229
|
-
- type: array of strings
|
|
230
|
-
- each of these strings is a request header, e.g. `X-Request-Id`
|
|
231
|
-
- `handlers`
|
|
232
|
-
- type: an array of functions that return dicts of key-val pairs to be added to the logger's output.
|
|
233
|
-
These functions have the interface `(request, response) => { "key": "val" }`.
|
|
234
|
-
- `ignore_dir`
|
|
235
|
-
- type: object containing the keys `directory` and `path`
|
|
236
|
-
- `directory` is the absolute file path of the directory that contains static files. This is the path passed to `express.static`
|
|
237
|
-
- `path` is the express mount point for these files. Defaults to `/`.
|
|
238
|
-
This will ignore all requests with `statusCode < 400` to `path`/`file/path/in/dir`
|
|
239
|
-
|
|
240
|
-
For example, the below snippet causes the `X-Request-Id` request header and a param called `some_id` to be logged.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
```js
|
|
244
|
-
var kayvee = require('kayvee');
|
|
245
|
-
|
|
246
|
-
var app = express();
|
|
247
|
-
var options = {
|
|
248
|
-
source: "my-app",
|
|
249
|
-
headers: ["x-request-id"],
|
|
250
|
-
handlers: [
|
|
251
|
-
(req, res) => { return {"some_id": req.params.some_id}; }
|
|
252
|
-
],
|
|
253
|
-
};
|
|
254
|
-
app.use(kayvee.middleware(options));
|
|
255
|
-
```
|
|
204
|
+
## Change log
|
|
256
205
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
res.send(200);
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
```
|
|
206
|
+
- v4.0.0 - Rewritten in TypeScript with ESM source, CommonJS dist output; `dist/` replaces `build/`
|
|
207
|
+
- v3.3.0 - Middleware log lines are now routable
|
|
208
|
+
- v3.2.0 - Exposed support for overriding the value field on metrics and alerts outputs
|
|
209
|
+
- v3.1.0 - Added support for matching on booleans and a wildcard ("*")
|
|
210
|
+
- v3.0.0 - Introduced log-routing
|
|
211
|
+
- v2.4.0 - Add middleware
|
|
212
|
+
- v2.3.0 - Convert CoffeeScript to ES6 / Typescript
|
|
213
|
+
- v2.0.0 - Implement `logger` functionality along with support for `gauge` and `counter` metrics
|
|
214
|
+
- v1.0.2 - Prints stringified JSON, published as Javascript lib to NPM
|
|
215
|
+
- v0.0.1 - Initial release
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,MAAM,EACN,MAAM,IAAI,MAAM,EAChB,gBAAgB,EAChB,eAAe,EACf,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Rule = exports.Router = exports.mockRouting = exports.getGlobalRouter = exports.setGlobalRouting = exports.logger = exports.Logger = void 0;
|
|
18
|
+
__exportStar(require("./kayvee"), exports);
|
|
19
|
+
var logger_1 = require("./logger/logger");
|
|
20
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
21
|
+
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
22
|
+
Object.defineProperty(exports, "setGlobalRouting", { enumerable: true, get: function () { return logger_1.setGlobalRouting; } });
|
|
23
|
+
Object.defineProperty(exports, "getGlobalRouter", { enumerable: true, get: function () { return logger_1.getGlobalRouter; } });
|
|
24
|
+
Object.defineProperty(exports, "mockRouting", { enumerable: true, get: function () { return logger_1.mockRouting; } });
|
|
25
|
+
// middleware/ContextLogger are intentionally not re-exported here: they pull in
|
|
26
|
+
// express types, which would leak into the barrel's .d.ts. Use kayvee/middleware.
|
|
27
|
+
var router_1 = require("./router");
|
|
28
|
+
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_1.Router; } });
|
|
29
|
+
Object.defineProperty(exports, "Rule", { enumerable: true, get: function () { return router_1.Rule; } });
|
package/dist/kayvee.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function format(data: Record<string, unknown>): string;
|
|
2
|
+
export declare function formatLog(source?: string, level?: string, title?: string, data?: Record<string, unknown>): string;
|
|
3
|
+
export declare const LOG_LEVELS: {
|
|
4
|
+
readonly UNKNOWN: "unknown";
|
|
5
|
+
readonly CRITICAL: "critical";
|
|
6
|
+
readonly ERROR: "error";
|
|
7
|
+
readonly WARNING: "warning";
|
|
8
|
+
readonly INFO: "info";
|
|
9
|
+
readonly TRACE: "trace";
|
|
10
|
+
};
|
|
11
|
+
export declare const UNKNOWN: "unknown", CRITICAL: "critical", ERROR: "error", WARNING: "warning", INFO: "info", TRACE: "trace";
|
|
12
|
+
//# sourceMappingURL=kayvee.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kayvee.d.ts","sourceRoot":"","sources":["../lib/kayvee.ts"],"names":[],"mappings":"AAcA,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAY5D;AAED,wBAAgB,SAAS,CACvB,MAAM,SAAK,EACX,KAAK,SAAK,EACV,KAAK,SAAK,EACV,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACjC,MAAM,CAIR;AAED,eAAO,MAAM,UAAU;;;;;;;CAOb,CAAC;AAEX,eAAO,MAAQ,OAAO,aAAE,QAAQ,cAAE,KAAK,WAAE,OAAO,aAAE,IAAI,UAAE,KAAK,SAAe,CAAC"}
|
|
@@ -1,58 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TRACE = exports.INFO = exports.WARNING = exports.ERROR = exports.CRITICAL = exports.UNKNOWN = exports.LOG_LEVELS = void 0;
|
|
4
|
+
exports.format = format;
|
|
5
|
+
exports.formatLog = formatLog;
|
|
2
6
|
const deploy_env = process.env._DEPLOY_ENV;
|
|
3
7
|
const workflow_id = process.env._EXECUTION_NAME;
|
|
4
8
|
const pod_id = process.env._POD_ID;
|
|
5
9
|
const pod_shortname = process.env._POD_SHORTNAME;
|
|
6
10
|
const pod_region = process.env._POD_REGION;
|
|
7
11
|
const pod_account = process.env._POD_ACCOUNT;
|
|
8
|
-
|
|
9
|
-
function replaceErrors(key, value) {
|
|
12
|
+
function replaceErrors(_key, value) {
|
|
10
13
|
if (value instanceof Error) {
|
|
11
14
|
return value.toString();
|
|
12
15
|
}
|
|
13
16
|
return value;
|
|
14
17
|
}
|
|
15
|
-
// Converts a map to a string space-delimited key=val pairs
|
|
16
18
|
function format(data) {
|
|
17
19
|
if (deploy_env || workflow_id || pod_id || pod_shortname || pod_account || pod_region) {
|
|
18
20
|
const extras = {};
|
|
19
|
-
if (deploy_env)
|
|
21
|
+
if (deploy_env)
|
|
20
22
|
extras.deploy_env = deploy_env;
|
|
21
|
-
|
|
22
|
-
if (workflow_id) {
|
|
23
|
+
if (workflow_id)
|
|
23
24
|
extras.wf_id = workflow_id;
|
|
24
|
-
|
|
25
|
-
if (pod_id) {
|
|
25
|
+
if (pod_id)
|
|
26
26
|
extras["pod-id"] = pod_id;
|
|
27
|
-
|
|
28
|
-
if (pod_shortname) {
|
|
27
|
+
if (pod_shortname)
|
|
29
28
|
extras["pod-shortname"] = pod_shortname;
|
|
30
|
-
|
|
31
|
-
if (pod_region) {
|
|
29
|
+
if (pod_region)
|
|
32
30
|
extras["pod-region"] = pod_region;
|
|
33
|
-
|
|
34
|
-
if (pod_account) {
|
|
31
|
+
if (pod_account)
|
|
35
32
|
extras["pod-account"] = pod_account;
|
|
36
|
-
|
|
37
|
-
return JSON.stringify(_.extend(extras, data), replaceErrors);
|
|
33
|
+
return JSON.stringify(Object.assign(extras, data), replaceErrors);
|
|
38
34
|
}
|
|
39
35
|
return JSON.stringify(data, replaceErrors);
|
|
40
36
|
}
|
|
41
|
-
// Similar to format, but takes additional reserved params to promote logging best-practices
|
|
42
37
|
function formatLog(source = "", level = "", title = "", data = {}) {
|
|
43
|
-
|
|
44
|
-
if (!_.isObject(data)) {
|
|
45
|
-
info = {};
|
|
46
|
-
}
|
|
38
|
+
const info = typeof data === "object" && data !== null ? data : {};
|
|
47
39
|
const reserved = { source, level, title };
|
|
48
|
-
|
|
49
|
-
return format(_.extend({}, info, reserved));
|
|
40
|
+
return format(Object.assign({}, info, reserved));
|
|
50
41
|
}
|
|
51
|
-
|
|
52
|
-
format,
|
|
53
|
-
formatLog,
|
|
54
|
-
};
|
|
55
|
-
const LOG_LEVELS = {
|
|
42
|
+
exports.LOG_LEVELS = {
|
|
56
43
|
UNKNOWN: "unknown",
|
|
57
44
|
CRITICAL: "critical",
|
|
58
45
|
ERROR: "error",
|
|
@@ -60,4 +47,4 @@ const LOG_LEVELS = {
|
|
|
60
47
|
INFO: "info",
|
|
61
48
|
TRACE: "trace",
|
|
62
49
|
};
|
|
63
|
-
|
|
50
|
+
exports.UNKNOWN = exports.LOG_LEVELS.UNKNOWN, exports.CRITICAL = exports.LOG_LEVELS.CRITICAL, exports.ERROR = exports.LOG_LEVELS.ERROR, exports.WARNING = exports.LOG_LEVELS.WARNING, exports.INFO = exports.LOG_LEVELS.INFO, exports.TRACE = exports.LOG_LEVELS.TRACE;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Router } from "../router";
|
|
2
|
+
type Formatter = (data: Record<string, unknown>) => string;
|
|
3
|
+
type LogData = Record<string, unknown>;
|
|
4
|
+
export declare function setGlobalRouting(filename: string): void;
|
|
5
|
+
export declare function getGlobalRouter(): Router | undefined;
|
|
6
|
+
export declare class Logger {
|
|
7
|
+
static readonly Trace: "trace";
|
|
8
|
+
static readonly Debug: "debug";
|
|
9
|
+
static readonly Info: "info";
|
|
10
|
+
static readonly Warning: "warning";
|
|
11
|
+
static readonly Error: "error";
|
|
12
|
+
static readonly Critical: "critical";
|
|
13
|
+
static readonly LEVELS: string[];
|
|
14
|
+
static readonly METRICS: string[];
|
|
15
|
+
formatter: Formatter;
|
|
16
|
+
logLvl: string;
|
|
17
|
+
globals: LogData;
|
|
18
|
+
logWriter: (msg: string) => void;
|
|
19
|
+
logRouter: Router | null;
|
|
20
|
+
asyncLocalStorage: any;
|
|
21
|
+
constructor(source: string, logLvl?: string | null | undefined, formatter?: Formatter, output?: (msg: string) => void);
|
|
22
|
+
setAsyncLocalStorage(asyncLocalStorage: any): void;
|
|
23
|
+
setRouter(r: Router): void;
|
|
24
|
+
setConfig(source: string, logLvl: string, formatter: Formatter, output: (msg: string) => void): (msg: string) => void;
|
|
25
|
+
_validateLogLvl(logLvl: string | null | undefined): string;
|
|
26
|
+
setLogLevel(logLvl: string): string;
|
|
27
|
+
setFormatter(formatter: Formatter): Formatter;
|
|
28
|
+
setOutput(output: (msg: string) => void): (msg: string) => void;
|
|
29
|
+
trace(title: string): void;
|
|
30
|
+
debug(title: string): void;
|
|
31
|
+
info(title: string): void;
|
|
32
|
+
warn(title: string): void;
|
|
33
|
+
error(title: string): void;
|
|
34
|
+
critical(title: string): void;
|
|
35
|
+
counter(title: string): void;
|
|
36
|
+
gauge(title: string, value: number): void;
|
|
37
|
+
traceD(title: string, data: LogData): void;
|
|
38
|
+
debugD(title: string, data: LogData): void;
|
|
39
|
+
infoD(title: string, data: LogData): void;
|
|
40
|
+
warnD(title: string, data: LogData): void;
|
|
41
|
+
errorD(title: string, data: LogData): void;
|
|
42
|
+
criticalD(title: string, data: LogData): void;
|
|
43
|
+
counterD(title: string, value: number, data: LogData): void;
|
|
44
|
+
gaugeD(title: string, value: number, data: LogData): void;
|
|
45
|
+
_logWithLevel(logLvl: string, metadata: LogData, userdata: LogData): void;
|
|
46
|
+
}
|
|
47
|
+
export declare function mockRouting(cb: (done: () => Record<string, unknown[]>) => void): void;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../lib/logger/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,KAAK,SAAS,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;AAC3D,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAsBvC,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAGvD;AAED,wBAAgB,eAAe,IAAI,MAAM,GAAG,SAAS,CAEpD;AAED,qBAAa,MAAM;IACjB,MAAM,CAAC,QAAQ,CAAC,KAAK,UAAgB;IACrC,MAAM,CAAC,QAAQ,CAAC,KAAK,UAAgB;IACrC,MAAM,CAAC,QAAQ,CAAC,IAAI,SAAe;IACnC,MAAM,CAAC,QAAQ,CAAC,OAAO,YAAkB;IACzC,MAAM,CAAC,QAAQ,CAAC,KAAK,UAAgB;IACrC,MAAM,CAAC,QAAQ,CAAC,QAAQ,aAAmB;IAC3C,MAAM,CAAC,QAAQ,CAAC,MAAM,WAA2D;IACjF,MAAM,CAAC,QAAQ,CAAC,OAAO,WAAwB;IAE/C,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,CA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