Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(shared): preserve files outside log rotation naming #27503

Mergedmacodev00(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/27503/headmerged by maria-rcks View on GitHub

Showing 2 changed files with 38 additions and 5 deletions.

x
0 of 2 viewed, 2 left
30 additions and 1 deletionpackages/shared/src/logging.test.tsModified
View file
@@ -33,7 +33,36 @@
});
​
-effectIt.layer(NodeServices.layer)("asynchronous rotating file sink", (it) => {
+effectIt.layer(NodeServices.layer)("rotating file sinks", (it) => {
+ it.effect.each(["synchronous", "asynchronous"] as const)(
+ "%s startup prunes only canonical rotation suffixes",
+ (mode) =>
+ Effect.gen(function* () {
+ const directory = makeTempDirectory();
+ const filePath = NodePath.join(directory, "debug.log");
+ const retained = ["1", "3", "04", "4.0", "4e0", "0x4", "+4", "notes"];
+ for (const suffix of [...retained, "4", "50"]) {
+ NodeFS.writeFileSync(`${filePath}.${suffix}`, suffix);
+ }
+ const options = { filePath, maxBytes: 100, maxFiles: 3 };
+​
+ const sink =
+ mode === "synchronous"
+ ? new RotatingFileSink(options)
+ : yield* makeAsyncRotatingFileSink(options);
+ if (sink instanceof RotatingFileSink) sink.write("current");
+ else yield* sink.write("current");
+​
+ expect(NodeFS.readdirSync(directory).sort()).toEqual(
+ ["debug.log", ...retained.map((suffix) => `debug.log.${suffix}`)].sort(),
+ );
+ expect(NodeFS.readFileSync(filePath, "utf8")).toBe("current");
+ for (const suffix of retained) {