Skip to content

Commit

Permalink
Merge tag '0.4.3'
Browse files Browse the repository at this point in the history
LogTape 0.4.3
  • Loading branch information
dahlia committed Aug 22, 2024
2 parents 7c31444 + f0d095d commit 41495cd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
11 changes: 11 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ To be released.
[#8]: https://github.com/dahlia/logtape/pull/8


Version 0.4.3
-------------

Released on August 22, 2024.

- Fixed a bug where `getRotatingFileSink()` function had failed to create
a new log file when there's no log file to rotate yet. [[#9]]

[#9]: https://github.com/dahlia/logtape/issues/9


Version 0.4.2
-------------

Expand Down
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@std/assert": "jsr:@std/assert@^0.222.1",
"@std/async": "jsr:@std/async@^0.222.1",
"@std/fs": "jsr:@std/fs@^0.223.0",
"@std/path": "jsr:@std/path@^1.0.2",
"@std/testing": "jsr:@std/testing@^0.222.1",
"consolemock": "npm:consolemock@^1.1.0",
"which_runtime": "https://deno.land/x/[email protected]/mod.ts"
Expand Down
1 change: 1 addition & 0 deletions logtape/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export async function configure<
}

if ("process" in globalThis) { // @ts-ignore: It's fine to use process in Node
// deno-lint-ignore no-node-globals
process.on("exit", dispose);
} else { // @ts-ignore: It's fine to addEventListener() on the browser/Deno
addEventListener("unload", dispose);
Expand Down
13 changes: 13 additions & 0 deletions logtape/filesink.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assertEquals } from "@std/assert/assert-equals";
import { join } from "@std/path/join";
import { getFileSink, getRotatingFileSink } from "./filesink.deno.ts";
import { debug, error, fatal, info, warning } from "./fixtures.ts";
import type { Sink } from "./sink.ts";
Expand Down Expand Up @@ -89,6 +90,18 @@ Deno.test("getRotatingFileSink()", () => {
2023-11-14 22:13:20.000 +00:00 [INF] my-app·junk: Hello, 123 & 456!
`,
);

const dirPath = Deno.makeTempDirSync();
const path2 = join(dirPath, "log");
const sink2: Sink & Disposable = getRotatingFileSink(path2, {
maxSize: 150,
});
sink2(debug);
assertEquals(
Deno.readTextFileSync(path2),
"2023-11-14 22:13:20.000 +00:00 [DBG] my-app·junk: Hello, 123 & 456!\n",
);
sink2[Symbol.dispose]();
});

// cSpell: ignore filesink
8 changes: 7 additions & 1 deletion logtape/sink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,13 @@ export function getRotatingFileSink<TFile>(
const encoder = options.encoder ?? new TextEncoder();
const maxSize = options.maxSize ?? 1024 * 1024;
const maxFiles = options.maxFiles ?? 5;
let { size: offset } = options.statSync(path);
let offset: number = 0;
try {
const stat = options.statSync(path);
offset = stat.size;
} catch {
// Continue as the offset is already 0.
}
let fd = options.openSync(path);
function shouldRollover(bytes: Uint8Array): boolean {
return offset + bytes.length > maxSize;
Expand Down

0 comments on commit 41495cd

Please sign in to comment.