opencode-logger 0.2.3 → 0.3.1
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 +18 -1
- package/dist/file-logger.d.ts.map +1 -1
- package/dist/file-logger.js +1 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/utils.d.ts +14 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +34 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -26,12 +26,13 @@ and add:
|
|
|
26
26
|
|
|
27
27
|
## Configuration
|
|
28
28
|
|
|
29
|
-
You can customize the log directory and
|
|
29
|
+
You can customize the log directory, filename, and logging scope using environment variables.
|
|
30
30
|
|
|
31
31
|
| Variable | Description | Default |
|
|
32
32
|
|----------|-------------|---------|
|
|
33
33
|
| `OPENCODE_LOGGER_DIR` | The directory where logs are stored. Can be absolute or relative to project root. | `logs/opencode` |
|
|
34
34
|
| `OPENCODE_LOGGER_FILENAME` | The filename for the log file. | `log.jsonl` |
|
|
35
|
+
| `OPENCODE_LOGGER_SCOPE` | Comma-separated list of event types to log. Supports wildcards (e.g., `session.*`). | `*` (Log all events) |
|
|
35
36
|
|
|
36
37
|
|
|
37
38
|
|
|
@@ -52,5 +53,21 @@ export OPENCODE_LOGGER_DIR=/tmp/my-logs
|
|
|
52
53
|
export OPENCODE_LOGGER_FILENAME=custom-name.jsonl
|
|
53
54
|
```
|
|
54
55
|
|
|
56
|
+
### Logging Scope
|
|
57
|
+
|
|
58
|
+
You can filter which events are logged using the `OPENCODE_LOGGER_SCOPE` environment variable.
|
|
59
|
+
It accepts a comma-separated string of event types or patterns.
|
|
60
|
+
|
|
61
|
+
- `*` (Default): Logs all events.
|
|
62
|
+
- `session.*`: Logs all events starting with `session.` (e.g., `session.created`, `session.updated`).
|
|
63
|
+
- `command.executed,file.edited`: Logs only these specific events.
|
|
64
|
+
|
|
65
|
+
**Example:**
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
export OPENCODE_LOGGER_SCOPE="session.*,command.executed"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
|
|
55
72
|
|
|
56
73
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-logger.d.ts","sourceRoot":"","sources":["../src/file-logger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,uFAAuF;IACvF,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,OAAO,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,UAAU;IACtB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAc;IAEjC;;;;OAIG;gBACS,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW;IAQzD,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,cAAc;IAKtB;;;OAGG;IACG,IAAI;
|
|
1
|
+
{"version":3,"file":"file-logger.d.ts","sourceRoot":"","sources":["../src/file-logger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,uFAAuF;IACvF,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,OAAO,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,UAAU;IACtB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAc;IAEjC;;;;OAIG;gBACS,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW;IAQzD,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,cAAc;IAKtB;;;OAGG;IACG,IAAI;IASV;;;;OAIG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;CAwB7C"}
|
package/dist/file-logger.js
CHANGED
|
@@ -40,29 +40,9 @@ export class FileLogger {
|
|
|
40
40
|
try {
|
|
41
41
|
const dirPath = join(this.logFilePath, "..");
|
|
42
42
|
await mkdir(dirPath, { recursive: true });
|
|
43
|
-
// NOTE: this opencode log call causes
|
|
44
|
-
// the application to hang on start.
|
|
45
|
-
// Did not see anything in the internal logs,
|
|
46
|
-
// so this is disabled for the moment
|
|
47
|
-
/* await this.pluginInput.client.app.log({
|
|
48
|
-
body: {
|
|
49
|
-
service: "opencode-logger",
|
|
50
|
-
level: "info",
|
|
51
|
-
message: "Plugin initialized!",
|
|
52
|
-
},
|
|
53
|
-
}); */
|
|
54
43
|
}
|
|
55
44
|
catch (error) {
|
|
56
|
-
|
|
57
|
-
body: {
|
|
58
|
-
service: "opencode-logger",
|
|
59
|
-
level: "error",
|
|
60
|
-
message: "Failed to create log directory.",
|
|
61
|
-
extra: {
|
|
62
|
-
error,
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
});
|
|
45
|
+
console.error(`[Opencode-logger]: Failed to initialize.\n${error}`);
|
|
66
46
|
}
|
|
67
47
|
}
|
|
68
48
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAKzD;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE,MAmB1B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SUPPORTED_EVENTS } from "./constants.js";
|
|
2
2
|
import { FileLogger } from "./file-logger.js";
|
|
3
|
+
import { shouldLogEvent } from "./utils.js";
|
|
3
4
|
/**
|
|
4
5
|
* The main Opencode Logger plugin entry point.
|
|
5
6
|
* Initializes the file logger and registers hooks for supported events.
|
|
@@ -13,7 +14,9 @@ export const loggerPlugin = async (ctx) => {
|
|
|
13
14
|
console.log("[Opencode Logger] Plugin initialized!");
|
|
14
15
|
const hooks = {
|
|
15
16
|
event: async ({ event }) => {
|
|
16
|
-
if (SUPPORTED_EVENTS.includes(event.type)
|
|
17
|
+
if (SUPPORTED_EVENTS.includes(event.type) &&
|
|
18
|
+
// biome-ignore lint/complexity/useLiteralKeys: process.env access
|
|
19
|
+
shouldLogEvent(event.type, process.env["OPENCODE_LOGGER_SCOPE"])) {
|
|
17
20
|
await logger.log(event.type, event);
|
|
18
21
|
}
|
|
19
22
|
},
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a specific event type should be logged based on the configured scope.
|
|
3
|
+
*
|
|
4
|
+
* The scope is a comma-separated string that can contain:
|
|
5
|
+
* 1. "*" to allow all events.
|
|
6
|
+
* 2. Specific event names (e.g., "session.created").
|
|
7
|
+
* 3. Group wildcards ending in ".*" (e.g., "session.*").
|
|
8
|
+
*
|
|
9
|
+
* @param eventType - The type of the event to check.
|
|
10
|
+
* @param scope - The configuration string defining allowed events.
|
|
11
|
+
* @returns True if the event should be logged, false otherwise.
|
|
12
|
+
*/
|
|
13
|
+
export declare function shouldLogEvent(eventType: string, scope?: string): boolean;
|
|
14
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CA0BzE"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a specific event type should be logged based on the configured scope.
|
|
3
|
+
*
|
|
4
|
+
* The scope is a comma-separated string that can contain:
|
|
5
|
+
* 1. "*" to allow all events.
|
|
6
|
+
* 2. Specific event names (e.g., "session.created").
|
|
7
|
+
* 3. Group wildcards ending in ".*" (e.g., "session.*").
|
|
8
|
+
*
|
|
9
|
+
* @param eventType - The type of the event to check.
|
|
10
|
+
* @param scope - The configuration string defining allowed events.
|
|
11
|
+
* @returns True if the event should be logged, false otherwise.
|
|
12
|
+
*/
|
|
13
|
+
export function shouldLogEvent(eventType, scope) {
|
|
14
|
+
if (!scope || scope === "*" || scope.trim() === "") {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
const allowedPatterns = scope.split(",").map((s) => s.trim());
|
|
18
|
+
for (const pattern of allowedPatterns) {
|
|
19
|
+
if (pattern === "*") {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
// Check for wildcard group (e.g., "session.*")
|
|
23
|
+
if (pattern.endsWith(".*")) {
|
|
24
|
+
const prefix = pattern.slice(0, -2);
|
|
25
|
+
if (eventType.startsWith(`${prefix}.`)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (pattern === eventType) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"name": "opencode-logger",
|
|
3
3
|
"main": "dist/index.js",
|
|
4
4
|
"types": "dist/index.d.ts",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.3.1",
|
|
6
6
|
"repository": {
|
|
7
|
-
"url": "https://github.com/radekBednarik/opencode-logger.git"
|
|
7
|
+
"url": "git+https://github.com/radekBednarik/opencode-logger.git"
|
|
8
8
|
},
|
|
9
9
|
"author": {
|
|
10
10
|
"url": "https://radekbednarik.com",
|