@fougere/log 0.16.2-alpha.0 → 0.16.4-alpha.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.
@@ -0,0 +1,10 @@
1
+ import { type AppMiddleware, type Logger } from '@fougere/core';
2
+ /**
3
+ * Two lines a call — that it began, and what it cost — written under the frond that answers. A
4
+ * call from another process names the one that signed it.
5
+ *
6
+ * An op that CARRIES a line writes none: it is dispatched, so logging it announces a line inside
7
+ * the announcement of one — `Emission cycle: logLine → logLine`.
8
+ */
9
+ export declare function callLines(logger: Logger): AppMiddleware;
10
+ //# sourceMappingURL=CallLines.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CallLines.d.ts","sourceRoot":"","sources":["../src/CallLines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAE9E;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAqBvD"}
@@ -0,0 +1,30 @@
1
+ import { CARRIES_LINE } from '@fougere/core';
2
+ /**
3
+ * Two lines a call — that it began, and what it cost — written under the frond that answers. A
4
+ * call from another process names the one that signed it.
5
+ *
6
+ * An op that CARRIES a line writes none: it is dispatched, so logging it announces a line inside
7
+ * the announcement of one — `Emission cycle: logLine → logLine`.
8
+ */
9
+ export function callLines(logger) {
10
+ return async (context, next) => {
11
+ if (CARRIES_LINE.has(context.entity))
12
+ return next();
13
+ const log = context.frond ? logger.child(context.frond) : logger;
14
+ const call = `${context.handler ?? context.entity}.${context.operation}`;
15
+ const from = context.invocation?.caller ? ` ← ${context.invocation.caller}` : '';
16
+ const start = performance.now();
17
+ const cost = () => `(${(performance.now() - start).toFixed(1)}ms)`;
18
+ log.info(`${call}${from}`);
19
+ try {
20
+ const result = await next();
21
+ log.info(`${call} ${cost()}${from}`);
22
+ return result;
23
+ }
24
+ catch (error) {
25
+ log.error(`${call} ${cost()}${from}`, error);
26
+ throw error;
27
+ }
28
+ };
29
+ }
30
+ //# sourceMappingURL=CallLines.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CallLines.js","sourceRoot":"","sources":["../src/CallLines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAmC,MAAM,eAAe,CAAC;AAE9E;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,MAAc;IACtC,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC7B,IAAI,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;YAAE,OAAO,IAAI,EAAE,CAAC;QAEpD,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QACjE,MAAM,IAAI,GAAG,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACzE,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjF,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;QAEnE,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC;QAC3B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;YAC5B,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;YAErC,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,GAAG,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;YAC7C,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,16 @@
1
+ /**
2
+ * What is written about a call, and where a line GOES. The line itself is core's — the boot
3
+ * announces one before any frond exists, so naming it here would cost core an optional package's
4
+ * vocabulary — and the console is core's too: it writes every line whoever else took it.
5
+ *
6
+ * So this package holds the two lines every call writes, and a destination that sends a line
7
+ * SOMEWHERE ELSE. Stated and not scanned: `frond()` is what a published package hands over, so a
8
+ * consumer needs no TypeScript loader and no scan of its `node_modules`. The contract is written
9
+ * here for the same reason — nobody reads this handler's source at boot.
10
+ */
11
+ import { type Extension } from '@fougere/core';
1
12
  export { default as FileHandler, LogFile } from './FileHandler.js';
13
+ export { callLines } from './CallLines.js';
2
14
  /**
3
15
  * Lines to a file, one JSON object each. Leave it out and they only reach the console —
4
16
  * which is the whole difference from a logger you have to turn off.
@@ -8,9 +20,9 @@ export { default as FileHandler, LogFile } from './FileHandler.js';
8
20
  */
9
21
  export declare const logFrond: (path: string) => import("@fougere/core").FrondDescriptor;
10
22
  /**
11
- * The name `fronds: { '@fougere/log': './lines.jsonl' }` reaches — the last segment of the
12
- * specifier is the export, which is what the Nuxt module already assumes of `calls` and
13
- * `observability`.
23
+ * The name `fronds: { '@fougere/log': {} }` reaches — the last segment of the specifier is the
24
+ * export. An extension, so every process reading the config writes its calls, whatever `only:`
25
+ * it was started with; a path adds the file.
14
26
  */
15
- export declare const log: typeof logFrond;
27
+ export declare const log: (path?: string) => Extension;
16
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,SAAU,MAAM,4CAoBpC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,GAAG,iBAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAkB,KAAK,SAAS,EAAe,MAAM,eAAe,CAAC;AAI5E,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,SAAU,MAAM,4CAoBpC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,GAAG,UAAW,MAAM,KAAG,SAMlC,CAAC"}
package/dist/index.js CHANGED
@@ -1,16 +1,18 @@
1
1
  /**
2
- * Where a log line GOES. The line itself is core's — the boot announces one before any
3
- * frond exists, so naming it there would cost core an optional package's vocabulary, and
4
- * the console is core's too: it writes every line whoever else took it.
2
+ * What is written about a call, and where a line GOES. The line itself is core's — the boot
3
+ * announces one before any frond exists, so naming it here would cost core an optional package's
4
+ * vocabulary — and the console is core's too: it writes every line whoever else took it.
5
5
  *
6
- * So what this package holds is a destination that sends a line SOMEWHERE ELSE. Stated and
7
- * not scanned: `frond()` is what a published package hands over, so a consumer needs no
8
- * TypeScript loader and no scan of its `node_modules`. The contract is written here for the
9
- * same reason — nobody reads this handler's source at boot.
6
+ * So this package holds the two lines every call writes, and a destination that sends a line
7
+ * SOMEWHERE ELSE. Stated and not scanned: `frond()` is what a published package hands over, so a
8
+ * consumer needs no TypeScript loader and no scan of its `node_modules`. The contract is written
9
+ * here for the same reason — nobody reads this handler's source at boot.
10
10
  */
11
11
  import { frond, LogLine } from '@fougere/core';
12
12
  import FileHandler, { LogFile } from './FileHandler.js';
13
+ import { callLines } from './CallLines.js';
13
14
  export { default as FileHandler, LogFile } from './FileHandler.js';
15
+ export { callLines } from './CallLines.js';
14
16
  /**
15
17
  * Lines to a file, one JSON object each. Leave it out and they only reach the console —
16
18
  * which is the whole difference from a logger you have to turn off.
@@ -39,9 +41,15 @@ export const logFrond = (path) => {
39
41
  });
40
42
  };
41
43
  /**
42
- * The name `fronds: { '@fougere/log': './lines.jsonl' }` reaches — the last segment of the
43
- * specifier is the export, which is what the Nuxt module already assumes of `calls` and
44
- * `observability`.
44
+ * The name `fronds: { '@fougere/log': {} }` reaches — the last segment of the specifier is the
45
+ * export. An extension, so every process reading the config writes its calls, whatever `only:`
46
+ * it was started with; a path adds the file.
45
47
  */
46
- export const log = logFrond;
48
+ export const log = (path) => ({
49
+ name: 'log',
50
+ ...(path ? { fronds: [logFrond(path)] } : {}),
51
+ up(app) {
52
+ app.use(callLines(app.container.resolve('Logger')));
53
+ },
54
+ });
47
55
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,WAAW,EAAE,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE;IACvC,MAAM,KAAM,SAAQ,WAAW;QAC7B;YACE,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3B,CAAC;KACF;IAED,OAAO,KAAK,CAAC,KAAK,EAAE;QAClB,QAAQ,EAAE,CAAC,OAAO,CAAC;Q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AI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,CAAC;qBAC5F;iBACF;aACF,CAAC;KACH,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,IAAa,EAAa,EAAE,CAAC,CAAC;IAChD,IAAI,EAAE,KAAK;IACX,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7C,EAAE,CAAC,GAAG;QACJ,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAS,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fougere/log",
3
- "version": "0.16.2-alpha.0",
4
- "description": "Logging for Fougere: a line is an announced fact, and a destination is a handler that accepts it. Ships the console one.",
3
+ "version": "0.16.4-alpha.0",
4
+ "description": "Logging for Fougere: two lines for every call, in every process, and a file destination for the lines.",
5
5
  "keywords": [
6
6
  "fougere",
7
7
  "typescript",
@@ -29,17 +29,17 @@
29
29
  "src"
30
30
  ],
31
31
  "peerDependencies": {
32
- "@fougere/core": "^0.16.2-alpha.0",
33
- "@fougere/schema": "^0.16.2-alpha.0"
32
+ "@fougere/core": "^0.16.4-alpha.0",
33
+ "@fougere/schema": "^0.16.4-alpha.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@fougere/compiler": "0.16.2-alpha.0",
37
- "@fougere/container": "0.16.2-alpha.0",
38
- "@fougere/core": "0.16.2-alpha.0",
39
- "@fougere/schema": "0.16.2-alpha.0",
36
+ "@fougere/compiler": "0.16.4-alpha.0",
37
+ "@fougere/container": "0.16.4-alpha.0",
38
+ "@fougere/core": "0.16.4-alpha.0",
39
+ "@fougere/schema": "0.16.4-alpha.0",
40
40
  "vitest": "^4.1.0",
41
41
  "jiti": "^2.6.1",
42
- "@fougere/testing": "0.16.2-alpha.0"
42
+ "@fougere/testing": "0.16.4-alpha.0"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public"
@@ -0,0 +1,31 @@
1
+ import { CARRIES_LINE, type AppMiddleware, type Logger } from '@fougere/core';
2
+
3
+ /**
4
+ * Two lines a call — that it began, and what it cost — written under the frond that answers. A
5
+ * call from another process names the one that signed it.
6
+ *
7
+ * An op that CARRIES a line writes none: it is dispatched, so logging it announces a line inside
8
+ * the announcement of one — `Emission cycle: logLine → logLine`.
9
+ */
10
+ export function callLines(logger: Logger): AppMiddleware {
11
+ return async (context, next) => {
12
+ if (CARRIES_LINE.has(context.entity)) return next();
13
+
14
+ const log = context.frond ? logger.child(context.frond) : logger;
15
+ const call = `${context.handler ?? context.entity}.${context.operation}`;
16
+ const from = context.invocation?.caller ? ` ← ${context.invocation.caller}` : '';
17
+ const start = performance.now();
18
+ const cost = () => `(${(performance.now() - start).toFixed(1)}ms)`;
19
+
20
+ log.info(`${call}${from}`);
21
+ try {
22
+ const result = await next();
23
+ log.info(`${call} ${cost()}${from}`);
24
+
25
+ return result;
26
+ } catch (error) {
27
+ log.error(`${call} ${cost()}${from}`, error);
28
+ throw error;
29
+ }
30
+ };
31
+ }
package/src/index.ts CHANGED
@@ -1,17 +1,19 @@
1
1
  /**
2
- * Where a log line GOES. The line itself is core's — the boot announces one before any
3
- * frond exists, so naming it there would cost core an optional package's vocabulary, and
4
- * the console is core's too: it writes every line whoever else took it.
2
+ * What is written about a call, and where a line GOES. The line itself is core's — the boot
3
+ * announces one before any frond exists, so naming it here would cost core an optional package's
4
+ * vocabulary — and the console is core's too: it writes every line whoever else took it.
5
5
  *
6
- * So what this package holds is a destination that sends a line SOMEWHERE ELSE. Stated and
7
- * not scanned: `frond()` is what a published package hands over, so a consumer needs no
8
- * TypeScript loader and no scan of its `node_modules`. The contract is written here for the
9
- * same reason — nobody reads this handler's source at boot.
6
+ * So this package holds the two lines every call writes, and a destination that sends a line
7
+ * SOMEWHERE ELSE. Stated and not scanned: `frond()` is what a published package hands over, so a
8
+ * consumer needs no TypeScript loader and no scan of its `node_modules`. The contract is written
9
+ * here for the same reason — nobody reads this handler's source at boot.
10
10
  */
11
- import { frond, LogLine } from '@fougere/core';
11
+ import { frond, LogLine, type Extension, type Logger } from '@fougere/core';
12
12
  import FileHandler, { LogFile } from './FileHandler.js';
13
+ import { callLines } from './CallLines.js';
13
14
 
14
15
  export { default as FileHandler, LogFile } from './FileHandler.js';
16
+ export { callLines } from './CallLines.js';
15
17
 
16
18
  /**
17
19
  * Lines to a file, one JSON object each. Leave it out and they only reach the console —
@@ -43,8 +45,14 @@ export const logFrond = (path: string) => {
43
45
  };
44
46
 
45
47
  /**
46
- * The name `fronds: { '@fougere/log': './lines.jsonl' }` reaches — the last segment of the
47
- * specifier is the export, which is what the Nuxt module already assumes of `calls` and
48
- * `observability`.
48
+ * The name `fronds: { '@fougere/log': {} }` reaches — the last segment of the specifier is the
49
+ * export. An extension, so every process reading the config writes its calls, whatever `only:`
50
+ * it was started with; a path adds the file.
49
51
  */
50
- export const log = logFrond;
52
+ export const log = (path?: string): Extension => ({
53
+ name: 'log',
54
+ ...(path ? { fronds: [logFrond(path)] } : {}),
55
+ up(app) {
56
+ app.use(callLines(app.container.resolve<Logger>('Logger')));
57
+ },
58
+ });