mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-07-25 17:32:20 +00:00
♻️ Extract core and utils subpackages
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
pub(all) enum Level {
|
||||
Trace
|
||||
Debug
|
||||
Info
|
||||
Warn
|
||||
Error
|
||||
}
|
||||
|
||||
pub fn Level::priority(self : Level) -> Int {
|
||||
match self {
|
||||
Level::Trace => 10
|
||||
Level::Debug => 20
|
||||
Level::Info => 30
|
||||
Level::Warn => 40
|
||||
Level::Error => 50
|
||||
}
|
||||
}
|
||||
|
||||
pub fn Level::label(self : Level) -> String {
|
||||
match self {
|
||||
Level::Trace => "TRACE"
|
||||
Level::Debug => "DEBUG"
|
||||
Level::Info => "INFO"
|
||||
Level::Warn => "WARN"
|
||||
Level::Error => "ERROR"
|
||||
}
|
||||
}
|
||||
|
||||
pub fn Level::enabled(self : Level, min_level : Level) -> Bool {
|
||||
self.priority() >= min_level.priority()
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
import {
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
pub struct Field {
|
||||
key : String
|
||||
value : String
|
||||
}
|
||||
|
||||
pub fn field(key : String, value : String) -> Field {
|
||||
{ key, value }
|
||||
}
|
||||
|
||||
pub fn fields(entries : Array[(String, String)]) -> Array[Field] {
|
||||
entries.map(fn(entry) {
|
||||
field(entry.0, entry.1)
|
||||
})
|
||||
}
|
||||
|
||||
pub struct Record {
|
||||
level : Level
|
||||
timestamp_ms : UInt64
|
||||
target : String
|
||||
message : String
|
||||
fields : Array[Field]
|
||||
}
|
||||
|
||||
pub fn Record::new(
|
||||
level : Level,
|
||||
message : String,
|
||||
timestamp_ms~ : UInt64 = 0UL,
|
||||
target~ : String = "",
|
||||
fields~ : Array[Field] = [],
|
||||
) -> Record {
|
||||
{ level, timestamp_ms, target, message, fields }
|
||||
}
|
||||
|
||||
pub fn Field::with_value(self : Field, value : String) -> Field {
|
||||
field(self.key, value)
|
||||
}
|
||||
|
||||
pub fn Record::with_target(self : Record, target : String) -> Record {
|
||||
Record::new(
|
||||
self.level,
|
||||
self.message,
|
||||
timestamp_ms=self.timestamp_ms,
|
||||
target=target,
|
||||
fields=self.fields,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn Record::with_message(self : Record, message : String) -> Record {
|
||||
Record::new(
|
||||
self.level,
|
||||
message,
|
||||
timestamp_ms=self.timestamp_ms,
|
||||
target=self.target,
|
||||
fields=self.fields,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn Record::with_fields(self : Record, fields : Array[Field]) -> Record {
|
||||
Record::new(
|
||||
self.level,
|
||||
self.message,
|
||||
timestamp_ms=self.timestamp_ms,
|
||||
target=self.target,
|
||||
fields=fields,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn Record::copy(self : Record) -> Record {
|
||||
Record::new(
|
||||
self.level,
|
||||
self.message,
|
||||
timestamp_ms=self.timestamp_ms,
|
||||
target=self.target,
|
||||
fields=self.fields,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user