opencode-logger 0.1.4 → 0.2.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 CHANGED
@@ -24,4 +24,33 @@ and add:
24
24
  }
25
25
  ```
26
26
 
27
+ ## Configuration
28
+
29
+ You can customize the log directory and filename using environment variables.
30
+
31
+ | Variable | Description | Default |
32
+ |----------|-------------|---------|
33
+ | `OPENCODE_LOGGER_DIR` | The directory where logs are stored. Can be absolute or relative to project root. | `logs/opencode` |
34
+ | `OPENCODE_LOGGER_FILENAME` | The filename for the log file. | `log.jsonl` |
35
+
36
+
37
+
38
+ ### Setting via CLI
39
+
40
+ You can set them when starting the Opencode client:
41
+
42
+ ```bash
43
+ OPENCODE_LOGGER_DIR=/tmp/my-logs opencode
44
+ ```
45
+
46
+ ### Setting by exporting ENV variables
47
+
48
+ Or export them, for example in your `~/.bashrc`
49
+
50
+ ```bash
51
+ export OPENCODE_LOGGER_DIR=/tmp/my-logs
52
+ export OPENCODE_LOGGER_FILENAME=custom-name.jsonl
53
+ ```
54
+
55
+
27
56
 
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Directory where logs will be stored relative to the project root.
3
3
  */
4
- export declare const LOG_DIRECTORY = "logs/opencode";
4
+ export declare const DEFAULT_LOG_DIRECTORY = "logs/opencode";
5
5
  /**
6
6
  * Filename for the log file.
7
7
  */
8
- export declare const LOG_FILENAME = "log.jsonl";
8
+ export declare const DEFAULT_LOG_FILENAME = "log.jsonl";
9
9
  /**
10
10
  * List of event types supported by the logger plugin.
11
11
  * These events correspond to various lifecycle hooks and actions within the Opencode environment.
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C;;GAEG;AACH,eAAO,MAAM,YAAY,cAAc,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,gBAAgB,yiBA4BnB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AAErD;;GAEG;AACH,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,yiBA4BnB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC"}
package/dist/constants.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Directory where logs will be stored relative to the project root.
3
3
  */
4
- export const LOG_DIRECTORY = "logs/opencode";
4
+ export const DEFAULT_LOG_DIRECTORY = "logs/opencode";
5
5
  /**
6
6
  * Filename for the log file.
7
7
  */
8
- export const LOG_FILENAME = "log.jsonl";
8
+ export const DEFAULT_LOG_FILENAME = "log.jsonl";
9
9
  /**
10
10
  * List of event types supported by the logger plugin.
11
11
  * These events correspond to various lifecycle hooks and actions within the Opencode environment.
@@ -19,6 +19,8 @@ export declare class FileLogger {
19
19
  * @param projectRoot - The absolute path to the root of the project.
20
20
  */
21
21
  constructor(projectRoot: string);
22
+ private resolveLogDirectory;
23
+ private getLogFilename;
22
24
  /**
23
25
  * Initializes the logger by ensuring the log directory exists.
24
26
  * This method should be called before attempting to log any events.
@@ -1 +1 @@
1
- {"version":3,"file":"file-logger.d.ts","sourceRoot":"","sources":["../src/file-logger.ts"],"names":[],"mappings":"AAIA;;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;IAE5B;;;OAGG;gBACS,WAAW,EAAE,MAAM;IAI/B;;;OAGG;IACG,IAAI;IAWV;;;;OAIG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;CAe7C"}
1
+ {"version":3,"file":"file-logger.d.ts","sourceRoot":"","sources":["../src/file-logger.ts"],"names":[],"mappings":"AAIA;;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;IAE5B;;;OAGG;gBACS,WAAW,EAAE,MAAM;IAO/B,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,cAAc;IAKtB;;;OAGG;IACG,IAAI;IAWV;;;;OAIG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;CAe7C"}
@@ -1,6 +1,6 @@
1
1
  import { appendFile, mkdir } from "node:fs/promises";
2
- import { join } from "node:path";
3
- import { LOG_DIRECTORY, LOG_FILENAME } from "./constants.js";
2
+ import { isAbsolute, join, resolve } from "node:path";
3
+ import { DEFAULT_LOG_DIRECTORY, DEFAULT_LOG_FILENAME } from "./constants.js";
4
4
  /**
5
5
  * Handles initialization of the log directory and writing log entries to the file system.
6
6
  */
@@ -11,7 +11,23 @@ export class FileLogger {
11
11
  * @param projectRoot - The absolute path to the root of the project.
12
12
  */
13
13
  constructor(projectRoot) {
14
- this.logFilePath = join(projectRoot, LOG_DIRECTORY, LOG_FILENAME);
14
+ const logDir = this.resolveLogDirectory(projectRoot);
15
+ const logFilename = this.getLogFilename();
16
+ this.logFilePath = join(logDir, logFilename);
17
+ }
18
+ resolveLogDirectory(projectRoot) {
19
+ const logDir =
20
+ // biome-ignore lint/complexity/useLiteralKeys: process.env access
21
+ process.env["OPENCODE_LOGGER_DIR"] ||
22
+ join(projectRoot, DEFAULT_LOG_DIRECTORY);
23
+ // If logDir is absolute, use it directly. Otherwise, resolve it relative to projectRoot
24
+ // Note: The default join(projectRoot, DEFAULT_LOG_DIRECTORY) above already handles the relative default case,
25
+ // but we check isAbsolute here specifically for the ENV var case if the user passed a relative path.
26
+ return isAbsolute(logDir) ? logDir : resolve(projectRoot, logDir);
27
+ }
28
+ getLogFilename() {
29
+ // biome-ignore lint/complexity/useLiteralKeys: process.env access
30
+ return process.env["OPENCODE_LOGGER_FILENAME"] || DEFAULT_LOG_FILENAME;
15
31
  }
16
32
  /**
17
33
  * Initializes the logger by ensuring the log directory exists.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "opencode-logger",
3
3
  "main": "dist/index.js",
4
4
  "types": "dist/index.d.ts",
5
- "version": "0.1.4",
5
+ "version": "0.2.0",
6
6
  "repository": {
7
7
  "url": "https://github.com/radekBednarik/opencode-logger.git"
8
8
  },