2 Commits
Author SHA1 Message Date
ge 662f9e9a6f make it work with latest V, bump version 2026-11-19 13:29:10 +03:00
ge 9d9c5a48b1 Add tests 2026-05-02 05:45:10 +03:00
3 changed files with 43 additions and 10 deletions

No files matched your search

+7 -9
View File
@@ -9,8 +9,7 @@ import x.json2 as json
pub interface RecordHandler { pub interface RecordHandler {
mut: mut:
// handle method must prepare the Record for writing and write it. handle(rec Record) ! // handle method must prepare the Record for writing and write it.
handle(rec Record) !
} }
pub enum Level { pub enum Level {
@@ -28,12 +27,11 @@ pub type Value = i8
| i32 | i32
| i64 | i64
| int | int
| isize
| u8 | u8
| u16 | u16
| u32 | u32
| u64 | u64
| usize | uint
| f32 | f32
| f64 | f64
| string | string
@@ -49,12 +47,11 @@ pub fn (v Value) str() string {
i32 { v.str() } i32 { v.str() }
i64 { v.str() } i64 { v.str() }
int { v.str() } int { v.str() }
isize { v.str() }
u8 { v.str() } u8 { v.str() }
u16 { v.str() } u16 { v.str() }
u32 { v.str() } u32 { v.str() }
u64 { v.str() } u64 { v.str() }
usize { v.str() } uint { v.str() }
f32 { v.str() } f32 { v.str() }
f64 { v.str() } f64 { v.str() }
string { v.str() } string { v.str() }
@@ -431,6 +428,7 @@ pub fn (mut h TextHandler) handle(rec Record) ! {
} }
} }
} }
if i + 1 != rec.fields.len { if i + 1 != rec.fields.len {
if i in [0, 1] { if i in [0, 1] {
buf.write_byte(` `) buf.write_byte(` `)
@@ -506,11 +504,11 @@ fn check_is_empty[T](val T) ?bool {
return false return false
} }
} $else $if val is ?string { } $else $if val is ?string {
return val ? != '' return val? != ''
} $else $if val is ?int { } $else $if val is ?int {
return val ? != 0 return val? != 0
} $else $if val is ?f64 || val is ?f32 { } $else $if val is ?f64 || val is ?f32 {
return val ? != 0.0 return val? != 0.0
} }
return true return true
} }
+35
View File
@@ -0,0 +1,35 @@
import structlog
struct Simple {
foo int
bar string
}
fn test_struct_adapter() {
assert structlog.struct_adapter(Simple{10, 'fooo'}) == [
structlog.Field{'foo', 10},
structlog.Field{'bar', 'fooo'},
]
}
/* FIXME
enum SomeEnum {
one
two
three
}
struct WithEnum {
foo int
bar string
some_enum SomeEnum
}
fn test_struct_adapter_with_enum() {
assert structlog.struct_adapter(WithEnum{10, 'fooo', .two}) == [
structlog.Field{'foo', 10},
structlog.Field{'bar', 'fooo'},
structlog.Field{'some_enum', 'two'},
]
}
*/
+1 -1
View File
@@ -1,7 +1,7 @@
Module { Module {
name: 'structlog' name: 'structlog'
description: 'Structured logs' description: 'Structured logs'
version: '0.4.0' version: '0.4.1'
license: 'MIT' license: 'MIT'
dependencies: [] dependencies: []
} }