@fougere/log 0.9.0-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.
- package/LICENSE +21 -0
- package/dist/FileHandler.d.ts +25 -0
- package/dist/FileHandler.d.ts.map +1 -0
- package/dist/FileHandler.js +31 -0
- package/dist/FileHandler.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
- package/src/FileHandler.ts +28 -0
- package/src/index.ts +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fougere contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Fact, LogLine } from '@fougere/core';
|
|
2
|
+
/** Where the lines land, and the only thing this destination is configured with. */
|
|
3
|
+
export declare class LogFile {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
constructor(path: string);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* One JSON object per line, appended to a file — the shape a collector tails.
|
|
9
|
+
*
|
|
10
|
+
* A destination sends a line ELSEWHERE: the console is core's, written whoever else took
|
|
11
|
+
* the line, so a handler that printed would say everything twice.
|
|
12
|
+
*
|
|
13
|
+
* It announces NOTHING. A destination that logs is a ring, and the emission refuses it by
|
|
14
|
+
* name where `onLog`'s try/catch used to swallow it.
|
|
15
|
+
*
|
|
16
|
+
* In `src/` and not under a `fronds/` directory: that name is what a SCAN reads, and this
|
|
17
|
+
* frond is stated, because a published package is read by no scanner.
|
|
18
|
+
*/
|
|
19
|
+
export default class FileHandler {
|
|
20
|
+
private file;
|
|
21
|
+
constructor(file: LogFile);
|
|
22
|
+
/** Append one line. */
|
|
23
|
+
record(line: Fact<LogLine>): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=FileHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileHandler.d.ts","sourceRoot":"","sources":["../src/FileHandler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAEnD,oFAAoF;AACpF,qBAAa,OAAO;IACN,QAAQ,CAAC,IAAI,EAAE,MAAM;IAAjC,YAAqB,IAAI,EAAE,MAAM,EAAI;CACtC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAClB,OAAO,CAAC,IAAI;IAAxB,YAAoB,IAAI,EAAE,OAAO,EAAI;IAErC,uBAAuB;IACjB,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { appendFile } from 'node:fs/promises';
|
|
2
|
+
/** Where the lines land, and the only thing this destination is configured with. */
|
|
3
|
+
export class LogFile {
|
|
4
|
+
path;
|
|
5
|
+
constructor(path) {
|
|
6
|
+
this.path = path;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* One JSON object per line, appended to a file — the shape a collector tails.
|
|
11
|
+
*
|
|
12
|
+
* A destination sends a line ELSEWHERE: the console is core's, written whoever else took
|
|
13
|
+
* the line, so a handler that printed would say everything twice.
|
|
14
|
+
*
|
|
15
|
+
* It announces NOTHING. A destination that logs is a ring, and the emission refuses it by
|
|
16
|
+
* name where `onLog`'s try/catch used to swallow it.
|
|
17
|
+
*
|
|
18
|
+
* In `src/` and not under a `fronds/` directory: that name is what a SCAN reads, and this
|
|
19
|
+
* frond is stated, because a published package is read by no scanner.
|
|
20
|
+
*/
|
|
21
|
+
export default class FileHandler {
|
|
22
|
+
file;
|
|
23
|
+
constructor(file) {
|
|
24
|
+
this.file = file;
|
|
25
|
+
}
|
|
26
|
+
/** Append one line. */
|
|
27
|
+
async record(line) {
|
|
28
|
+
await appendFile(this.file.path, `${JSON.stringify(line)}\n`, 'utf8');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=FileHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileHandler.js","sourceRoot":"","sources":["../src/FileHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,oFAAoF;AACpF,MAAM,OAAO,OAAO;IACG,IAAI;IAAzB,YAAqB,IAAY;oBAAZ,IAAI;IAAW,CAAC;CACtC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IACV,IAAI;IAAxB,YAAoB,IAAa;oBAAb,IAAI;IAAY,CAAC;IAErC,uBAAuB;IACvB,KAAK,CAAC,MAAM,CAAC,IAAmB;QAC9B,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxE,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default as FileHandler, LogFile } from './FileHandler.js';
|
|
2
|
+
/**
|
|
3
|
+
* Lines to a file, one JSON object each. Leave it out and they only reach the console —
|
|
4
|
+
* which is the whole difference from a logger you have to turn off.
|
|
5
|
+
*
|
|
6
|
+
* The path is closed over by a subclass rather than registered: a frond states classes, and
|
|
7
|
+
* a value it should be constructed with has no key to answer under.
|
|
8
|
+
*/
|
|
9
|
+
export declare const logFrond: (path: string) => import("@fougere/core").FrondDescriptor;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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.
|
|
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.
|
|
10
|
+
*/
|
|
11
|
+
import { frond, LogLine } from '@fougere/core';
|
|
12
|
+
import FileHandler, { LogFile } from './FileHandler.js';
|
|
13
|
+
export { default as FileHandler, LogFile } from './FileHandler.js';
|
|
14
|
+
/**
|
|
15
|
+
* Lines to a file, one JSON object each. Leave it out and they only reach the console —
|
|
16
|
+
* which is the whole difference from a logger you have to turn off.
|
|
17
|
+
*
|
|
18
|
+
* The path is closed over by a subclass rather than registered: a frond states classes, and
|
|
19
|
+
* a value it should be constructed with has no key to answer under.
|
|
20
|
+
*/
|
|
21
|
+
export const logFrond = (path) => {
|
|
22
|
+
class Lines extends FileHandler {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(new LogFile(path));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return frond('log', {
|
|
28
|
+
entities: [LogLine],
|
|
29
|
+
handlers: [{
|
|
30
|
+
ctor: Lines,
|
|
31
|
+
deps: [],
|
|
32
|
+
operations: {
|
|
33
|
+
record: {
|
|
34
|
+
input: LogLine,
|
|
35
|
+
binding: [{ name: 'line', optional: false, source: { kind: 'fact', factName: 'logLine' } }],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}],
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;QACnB,QAAQ,EAAE,CAAC;gBACT,IAAI,EAAE,KAAK;gBACX,IAAI,EAAE,EAAE;gBACR,UAAU,EAAE;oBACV,MAAM,EAAE;wBACN,KAAK,EAAE,OAAO;wBACd,OAAO,EAAE,CAAC,EAAE,IAAI,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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fougere/log",
|
|
3
|
+
"version": "0.9.0-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.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"fougere",
|
|
7
|
+
"typescript",
|
|
8
|
+
"logging",
|
|
9
|
+
"observability"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/chok/fougere.git",
|
|
15
|
+
"directory": "packages/log"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"src"
|
|
30
|
+
],
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@fougere/core": "^0.9.0-alpha.0",
|
|
33
|
+
"@fougere/schema": "^0.9.0-alpha.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"vitest": "^4.1.0",
|
|
37
|
+
"jiti": "^2.6.1",
|
|
38
|
+
"@fougere/compiler": "0.9.0-alpha.0",
|
|
39
|
+
"@fougere/container": "0.9.0-alpha.0",
|
|
40
|
+
"@fougere/testing": "0.9.0-alpha.0",
|
|
41
|
+
"@fougere/core": "0.9.0-alpha.0",
|
|
42
|
+
"@fougere/schema": "0.9.0-alpha.0"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "rm -rf dist && tsc",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"typecheck": "tsc --noEmit -p tsconfig.test.json"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { appendFile } from 'node:fs/promises';
|
|
2
|
+
import type { Fact, LogLine } from '@fougere/core';
|
|
3
|
+
|
|
4
|
+
/** Where the lines land, and the only thing this destination is configured with. */
|
|
5
|
+
export class LogFile {
|
|
6
|
+
constructor(readonly path: string) {}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* One JSON object per line, appended to a file — the shape a collector tails.
|
|
11
|
+
*
|
|
12
|
+
* A destination sends a line ELSEWHERE: the console is core's, written whoever else took
|
|
13
|
+
* the line, so a handler that printed would say everything twice.
|
|
14
|
+
*
|
|
15
|
+
* It announces NOTHING. A destination that logs is a ring, and the emission refuses it by
|
|
16
|
+
* name where `onLog`'s try/catch used to swallow it.
|
|
17
|
+
*
|
|
18
|
+
* In `src/` and not under a `fronds/` directory: that name is what a SCAN reads, and this
|
|
19
|
+
* frond is stated, because a published package is read by no scanner.
|
|
20
|
+
*/
|
|
21
|
+
export default class FileHandler {
|
|
22
|
+
constructor(private file: LogFile) {}
|
|
23
|
+
|
|
24
|
+
/** Append one line. */
|
|
25
|
+
async record(line: Fact<LogLine>): Promise<void> {
|
|
26
|
+
await appendFile(this.file.path, `${JSON.stringify(line)}\n`, 'utf8');
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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.
|
|
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.
|
|
10
|
+
*/
|
|
11
|
+
import { frond, LogLine } from '@fougere/core';
|
|
12
|
+
import FileHandler, { LogFile } from './FileHandler.js';
|
|
13
|
+
|
|
14
|
+
export { default as FileHandler, LogFile } from './FileHandler.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Lines to a file, one JSON object each. Leave it out and they only reach the console —
|
|
18
|
+
* which is the whole difference from a logger you have to turn off.
|
|
19
|
+
*
|
|
20
|
+
* The path is closed over by a subclass rather than registered: a frond states classes, and
|
|
21
|
+
* a value it should be constructed with has no key to answer under.
|
|
22
|
+
*/
|
|
23
|
+
export const logFrond = (path: string) => {
|
|
24
|
+
class Lines extends FileHandler {
|
|
25
|
+
constructor() {
|
|
26
|
+
super(new LogFile(path));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return frond('log', {
|
|
31
|
+
entities: [LogLine],
|
|
32
|
+
handlers: [{
|
|
33
|
+
ctor: Lines,
|
|
34
|
+
deps: [],
|
|
35
|
+
operations: {
|
|
36
|
+
record: {
|
|
37
|
+
input: LogLine,
|
|
38
|
+
binding: [{ name: 'line', optional: false, source: { kind: 'fact', factName: 'logLine' } }],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
}],
|
|
42
|
+
});
|
|
43
|
+
};
|