Add Int64 file rotation path and JSON roundtrip

This commit is contained in:
Nanaloveyuki
2026-07-05 21:31:52 +08:00
parent 93e9bd966d
commit e001315319
13 changed files with 368 additions and 23 deletions
+22 -3
View File
@@ -29,6 +29,14 @@ pub fn file_rotation(max_bytes : Int, max_backups? : Int = 1) -> FileRotation {
@utils.file_rotation(max_bytes, max_backups~)
}
///|
pub fn file_rotation_i64(
max_bytes : Int64,
max_backups? : Int = 1,
) -> FileRotation {
@utils.file_rotation_i64(max_bytes, max_backups~)
}
///|
pub fn native_files_supported() -> Bool {
native_files_supported_internal()
@@ -216,11 +224,21 @@ fn policy_rotation_equals_internal(
match (left, right) {
(None, None) => true
(Some(a), Some(b)) =>
a.max_bytes == b.max_bytes && a.max_backups == b.max_backups
a.max_bytes == b.max_bytes &&
a.max_backups == b.max_backups &&
a.native_wide_max_bytes == b.native_wide_max_bytes
_ => false
}
}
///|
fn rotation_max_bytes_internal(rotation : FileRotation) -> Int64 {
match rotation.native_wide_max_bytes {
Some(value) => value
None => rotation.max_bytes.to_int64()
}
}
///|
pub fn FileSink::state(self : FileSink) -> FileSinkState {
FileSinkState::new(
@@ -316,8 +334,9 @@ fn rotate_if_needed_internal(sink : FileSink, next_line_bytes : Int) -> Bool {
match sink.handle.val {
None => false
Some(handle) => {
let size = file_size_internal(handle)
if size + next_line_bytes <= rotation.max_bytes {
let size = file_size_i64_internal(handle)
let next_line = next_line_bytes.to_int64()
if size + next_line <= rotation_max_bytes_internal(rotation) {
true
} else {
let rotated = rotate_file_sink_internal(sink, rotation)