mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-07-30 06:26:38 +00:00
🔊 Update 1.0.0
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
///|
|
||||
pub(all) enum Level {
|
||||
Trace
|
||||
Debug
|
||||
@@ -6,6 +7,7 @@ pub(all) enum Level {
|
||||
Error
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Level::priority(self : Level) -> Int {
|
||||
match self {
|
||||
Level::Trace => 10
|
||||
@@ -16,6 +18,7 @@ pub fn Level::priority(self : Level) -> Int {
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Level::label(self : Level) -> String {
|
||||
match self {
|
||||
Level::Trace => "TRACE"
|
||||
@@ -26,6 +29,7 @@ pub fn Level::label(self : Level) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Level::enabled(self : Level, min_level : Level) -> Bool {
|
||||
self.priority() >= min_level.priority()
|
||||
}
|
||||
|
||||
+16
-8
@@ -1,18 +1,20 @@
|
||||
///|
|
||||
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)
|
||||
})
|
||||
entries.map(fn(entry) { field(entry.0, entry.1) })
|
||||
}
|
||||
|
||||
///|
|
||||
pub struct Record {
|
||||
level : Level
|
||||
timestamp_ms : UInt64
|
||||
@@ -21,30 +23,34 @@ pub struct Record {
|
||||
fields : Array[Field]
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Record::new(
|
||||
level : Level,
|
||||
message : String,
|
||||
timestamp_ms~ : UInt64 = 0UL,
|
||||
target~ : String = "",
|
||||
fields~ : Array[Field] = [],
|
||||
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,
|
||||
target~,
|
||||
fields=self.fields,
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Record::with_message(self : Record, message : String) -> Record {
|
||||
Record::new(
|
||||
self.level,
|
||||
@@ -55,16 +61,18 @@ pub fn Record::with_message(self : Record, message : String) -> Record {
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
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,
|
||||
fields~,
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Record::copy(self : Record) -> Record {
|
||||
Record::new(
|
||||
self.level,
|
||||
|
||||
Reference in New Issue
Block a user