From da744cb32120a0643c312edb522505fe049ead72 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Mon, 15 Jul 2024 14:52:50 +0900 Subject: [PATCH 1/3] Version bump [ci skip] --- CHANGES.md | 6 ++++++ deno.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index c2a91fc..42f8810 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,12 @@ LogTape changelog ================= +Version 0.4.3 +------------- + +To be released. + + Version 0.4.2 ------------- diff --git a/deno.json b/deno.json index 0885330..e3969c9 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@logtape/logtape", - "version": "0.4.2", + "version": "0.4.3", "exports": "./logtape/mod.ts", "imports": { "@deno/dnt": "jsr:@deno/dnt@^0.41.1", From 18836e0dbc3ac23c9ce62af4a4b78c1aa537616d Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Thu, 22 Aug 2024 17:12:41 +0900 Subject: [PATCH 2/3] Fix bug preventing log file creation in getRotatingFileSink() Fix https://github.com/dahlia/logtape/issues/9 --- CHANGES.md | 5 +++++ deno.json | 1 + logtape/config.ts | 1 + logtape/filesink.test.ts | 13 +++++++++++++ logtape/sink.ts | 8 +++++++- 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 42f8810..f4bec3e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,11 @@ Version 0.4.3 To be released. + - 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 ------------- diff --git a/deno.json b/deno.json index e3969c9..154057e 100644 --- a/deno.json +++ b/deno.json @@ -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/which_runtime@0.2.0/mod.ts" diff --git a/logtape/config.ts b/logtape/config.ts index acd983c..eb5cf28 100644 --- a/logtape/config.ts +++ b/logtape/config.ts @@ -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); diff --git a/logtape/filesink.test.ts b/logtape/filesink.test.ts index 7fb387a..c1f2042 100644 --- a/logtape/filesink.test.ts +++ b/logtape/filesink.test.ts @@ -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"; @@ -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 diff --git a/logtape/sink.ts b/logtape/sink.ts index 55d3434..66f2f7f 100644 --- a/logtape/sink.ts +++ b/logtape/sink.ts @@ -249,7 +249,13 @@ export function getRotatingFileSink( 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; From f0d095df35c6572158224686a4797bf39e2fa942 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Thu, 22 Aug 2024 17:13:08 +0900 Subject: [PATCH 3/3] Release 0.4.3 --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index f4bec3e..23c9e5b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,7 +6,7 @@ LogTape changelog Version 0.4.3 ------------- -To be released. +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]]