kayvee 3.17.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.
Files changed (61) hide show
  1. package/README.md +147 -202
  2. package/dist/index.d.ts +4 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +29 -0
  5. package/dist/kayvee.d.ts +12 -0
  6. package/dist/kayvee.d.ts.map +1 -0
  7. package/dist/kayvee.js +50 -0
  8. package/dist/logger/logger.d.ts +49 -0
  9. package/dist/logger/logger.d.ts.map +1 -0
  10. package/dist/logger/logger.js +237 -0
  11. package/dist/middleware.d.ts +23 -0
  12. package/dist/middleware.d.ts.map +1 -0
  13. package/dist/middleware.js +196 -0
  14. package/dist/package.json +89 -0
  15. package/dist/router/index.d.ts +23 -0
  16. package/dist/router/index.d.ts.map +1 -0
  17. package/dist/router/index.js +184 -0
  18. package/package.json +64 -24
  19. package/.circleci/config.yml +0 -25
  20. package/.eslintrc.yml +0 -44
  21. package/.nvmrc +0 -1
  22. package/.prettierrc.json +0 -1
  23. package/Makefile +0 -56
  24. package/benchmarks/data/.keep +0 -1
  25. package/benchmarks/data/corpus-basic.json +0 -22
  26. package/benchmarks/data/corpus-pathological.json +0 -22
  27. package/benchmarks/data/corpus-realistic.json +0 -22
  28. package/benchmarks/data/kvconfig-basic.yml +0 -7
  29. package/benchmarks/data/kvconfig-pathological.yml +0 -222
  30. package/benchmarks/data/kvconfig-realistic.yml +0 -39
  31. package/benchmarks/routing.js +0 -116
  32. package/build/lib/kayvee.js +0 -67
  33. package/build/lib/logger/helpers.js +0 -0
  34. package/build/lib/logger/logger.js +0 -221
  35. package/build/lib/middleware.js +0 -302
  36. package/build/lib/router/index.js +0 -198
  37. package/build/package.json +0 -49
  38. package/build/test/context_logger.js +0 -77
  39. package/build/test/kayvee.js +0 -36
  40. package/build/test/logger_test.js +0 -334
  41. package/build/test/middleware.js +0 -557
  42. package/build/test/router.js +0 -311
  43. package/index.js +0 -7
  44. package/lib/kayvee.ts +0 -73
  45. package/lib/logger/helpers.ts +0 -0
  46. package/lib/logger/logger.ts +0 -296
  47. package/lib/middleware.ts +0 -317
  48. package/lib/router/index.ts +0 -234
  49. package/lib/router/schema_definitions.json +0 -158
  50. package/test/context_logger.ts +0 -76
  51. package/test/kayvee.ts +0 -50
  52. package/test/kvconfig.yml +0 -14
  53. package/test/logger_test.ts +0 -378
  54. package/test/middleware.ts +0 -632
  55. package/test/router.ts +0 -558
  56. package/test/static/empty.css +0 -0
  57. package/test/static/js/empty.js +0 -0
  58. package/test/tests.json +0 -100
  59. package/tsconfig.json +0 -10
  60. package/tslint.json +0 -134
  61. /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
- ## Example: kayvee/logger
8
+ ## Installation
9
9
 
10
- Initialization:
10
+ ```
11
+ npm install kayvee
12
+ ```
11
13
 
12
- ```js
13
- var kayvee = require("kayvee");
14
+ ## Usage
15
+
16
+ ### Logger
14
17
 
15
- var log = new kayvee.logger("logger-source");
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
- Use it to write metrics:
34
+ The constructor signature is:
19
35
 
20
- ```js
21
- log.gauge("gauge-simple", 18)
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
- ```js
27
- log.infoD("non-metric-log", {"msg": "this is my info", user: "user-id", group: "group-id"})
28
- log.error("this is an error with no extra structured metadata")
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
- ## Example: Kayvee Internals
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
- Here's are two examples snippets that log a kayvee formatted string:
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
- ```js
36
- console.error(kayvee.format({"hello":"world"}));
37
- # {"hello":"world"}
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
- ```js
41
- console.error(kayvee.formatLog("test_source", kayvee.INFO, "title", {"foo" : 1, "bar" : "baz"}));
42
- # {"foo":1,"bar":"baz","source":"test_source","level":"info","title":"title"}
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
- ## Example: Kayvee Log Routing
91
+ #### `kv.formatLog(source, level, title, data)`
46
92
 
47
- Log routing is a mechanism for defining where log lines should go once they've entered Clever's logging pipeline. Routes are defined in a yaml file called kvconfig.yml. Here's an example of a log routing rule that sends a slack message:
93
+ Like `format`, but takes reserved logging params:
48
94
 
49
- ```js
50
- // main.js
51
- const kv = require("../kayvee-js");
52
- kv.setGlobalRouting("./kvconfig.yml");
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
- const log = new kv.logger("myApp");
102
+ Log routing defines where log lines go once they enter Clever's logging pipeline. Routes are defined in `kvconfig.yml`.
55
103
 
56
- module.exports = (cb) => {
57
- // Simple debugging
58
- log.debug("Service has started");
104
+ ```ts
105
+ // main.ts
106
+ import * as kv from "kayvee";
59
107
 
60
- // Do something async
61
- setImmediate(() => {
62
- // Output structured data
63
- log.infoD("DataResults", {"key": "value"}); // Sends slack message
108
+ kv.setGlobalRouting("./kvconfig.yml");
64
109
 
65
- // You can use an object to send arbitrary key value pairs
66
- log.infoD("DataResults", {"shorter": "line"}); // will NOT send a slack message
110
+ const log = new kv.Logger("my-app");
67
111
 
68
- cb(null);
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: [ "DataResults", "QueryResults" ]
79
- key: [ "value" ]
120
+ title: ["DataResults"]
121
+ key: ["value"]
80
122
  output:
81
123
  type: "notifications"
82
- channel: "#distribution"
124
+ channel: "#my-channel"
83
125
  icon: ":rocket:"
84
126
  message: "%{key}"
85
- user: "Flight Tracker"
127
+ user: "My App"
86
128
  ```
87
129
 
88
- ### Testing
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
- ```js
94
- // main-test.js
95
- const assert = require("assert");
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
- const main = require("./main");
101
-
102
- kv.mockRouting(kvdone => { // Don't nest kv.mockRouting calls!!
103
- main(err => {
104
- assert.ifError(err);
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 on log routing see https://clever.atlassian.net/wiki/spaces/ENG/pages/90570917/Application+Log+Routing
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
- ## Usage
150
+ ### Middleware
132
151
 
133
- ### Logger
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
- #### kayvee/logger constructor
157
+ ```ts
158
+ import express from "express";
159
+ import { middleware } from "kayvee/middleware";
136
160
 
137
- ```js
138
- # only source is required
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
- An environment variable named `KAYVEE_LOG_LEVEL` can be used instead of setting `logLvl` in the application.
165
+ Additional options:
143
166
 
144
- #### kayvee/logger setConfig
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
- ```js
147
- log.setConfig(source, logLvl, formatter, output)
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
- You can also individually set the `config` using:
151
-
152
- * `setLogLevel`: defaults to `LOG_LEVELS.Debug`
153
- * `setFormatter`: defaults to `kv.format`
154
- * `setOutput`: defaults to `console.error`
155
-
156
- #### kayvee/logger logging
157
-
158
- Titles only:
159
-
160
- * `log.debug("title")`
161
- * `log.info("title")`
162
- * `log.warn("title")`
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
- #### formatLog
196
+ ## Development
192
197
 
193
- ```js
194
- kayvee.formatLog(source, level, title, data)
195
198
  ```
196
- `formatLog` is similar to `format`, but takes additional reserved params to promote
197
- logging best-practices
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
- Note that `source` is a required field, since it clarifies which application is emitting the logs.
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
- You can also log with the request context using `req.log`. For example:
258
-
259
- ```js
260
- myRouteHandler(req, res) {
261
- doTheThing((err, data) => {
262
- if (err) {
263
- req.log.errorD("do_the_thing_error", {error: err.message});
264
- res.send(500);
265
- }
266
- req.log.infoD("do_the_thing_success", {response: data});
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
@@ -0,0 +1,4 @@
1
+ export * from "./kayvee";
2
+ export { Logger, Logger as logger, setGlobalRouting, getGlobalRouter, mockRouting, } from "./logger/logger";
3
+ export { Router, Rule } from "./router";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -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; } });
@@ -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"}
package/dist/kayvee.js ADDED
@@ -0,0 +1,50 @@
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;
6
+ const deploy_env = process.env._DEPLOY_ENV;
7
+ const workflow_id = process.env._EXECUTION_NAME;
8
+ const pod_id = process.env._POD_ID;
9
+ const pod_shortname = process.env._POD_SHORTNAME;
10
+ const pod_region = process.env._POD_REGION;
11
+ const pod_account = process.env._POD_ACCOUNT;
12
+ function replaceErrors(_key, value) {
13
+ if (value instanceof Error) {
14
+ return value.toString();
15
+ }
16
+ return value;
17
+ }
18
+ function format(data) {
19
+ if (deploy_env || workflow_id || pod_id || pod_shortname || pod_account || pod_region) {
20
+ const extras = {};
21
+ if (deploy_env)
22
+ extras.deploy_env = deploy_env;
23
+ if (workflow_id)
24
+ extras.wf_id = workflow_id;
25
+ if (pod_id)
26
+ extras["pod-id"] = pod_id;
27
+ if (pod_shortname)
28
+ extras["pod-shortname"] = pod_shortname;
29
+ if (pod_region)
30
+ extras["pod-region"] = pod_region;
31
+ if (pod_account)
32
+ extras["pod-account"] = pod_account;
33
+ return JSON.stringify(Object.assign(extras, data), replaceErrors);
34
+ }
35
+ return JSON.stringify(data, replaceErrors);
36
+ }
37
+ function formatLog(source = "", level = "", title = "", data = {}) {
38
+ const info = typeof data === "object" && data !== null ? data : {};
39
+ const reserved = { source, level, title };
40
+ return format(Object.assign({}, info, reserved));
41
+ }
42
+ exports.LOG_LEVELS = {
43
+ UNKNOWN: "unknown",
44
+ CRITICAL: "critical",
45
+ ERROR: "error",
46
+ WARNING: "warning",
47
+ INFO: "info",
48
+ TRACE: "trace",
49
+ };
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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