mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-31 16:12:20 +00:00
♻️ Extract core and utils subpackages
This commit is contained in:
+8
-48
@@ -1,69 +1,29 @@
|
||||
pub type RecordPatch = (Record) -> Record
|
||||
pub type RecordPatch = @utils.RecordPatch
|
||||
|
||||
pub fn identity_patch() -> RecordPatch {
|
||||
fn(rec) { rec }
|
||||
@utils.identity_patch()
|
||||
}
|
||||
|
||||
pub fn set_target(target : String) -> RecordPatch {
|
||||
fn(rec) {
|
||||
{ ..rec, target }
|
||||
}
|
||||
@utils.set_target(target)
|
||||
}
|
||||
|
||||
pub fn prefix_message(prefix : String) -> RecordPatch {
|
||||
fn(rec) {
|
||||
{ ..rec, message: "\{prefix}\{rec.message}" }
|
||||
}
|
||||
@utils.prefix_message(prefix)
|
||||
}
|
||||
|
||||
pub fn append_fields(extra_fields : Array[Field]) -> RecordPatch {
|
||||
fn(rec) {
|
||||
if extra_fields.length() == 0 {
|
||||
rec
|
||||
} else if rec.fields.length() == 0 {
|
||||
{ ..rec, fields: extra_fields }
|
||||
} else {
|
||||
{ ..rec, fields: rec.fields + extra_fields }
|
||||
}
|
||||
}
|
||||
@utils.append_fields(extra_fields)
|
||||
}
|
||||
|
||||
pub fn redact_field(key : String, placeholder~ : String = "***") -> RecordPatch {
|
||||
fn(rec) {
|
||||
{
|
||||
..rec,
|
||||
fields: rec.fields.map(fn(field) {
|
||||
if field.key == key {
|
||||
{ ..field, value: placeholder }
|
||||
} else {
|
||||
field
|
||||
}
|
||||
}),
|
||||
}
|
||||
}
|
||||
@utils.redact_field(key, placeholder=placeholder)
|
||||
}
|
||||
|
||||
pub fn redact_fields(keys : Array[String], placeholder~ : String = "***") -> RecordPatch {
|
||||
fn(rec) {
|
||||
{
|
||||
..rec,
|
||||
fields: rec.fields.map(fn(field) {
|
||||
if keys.contains(field.key) {
|
||||
{ ..field, value: placeholder }
|
||||
} else {
|
||||
field
|
||||
}
|
||||
}),
|
||||
}
|
||||
}
|
||||
@utils.redact_fields(keys, placeholder=placeholder)
|
||||
}
|
||||
|
||||
pub fn compose_patches(patches : Array[RecordPatch]) -> RecordPatch {
|
||||
fn(rec) {
|
||||
let mut current = rec
|
||||
for patch in patches {
|
||||
current = patch(current)
|
||||
}
|
||||
current
|
||||
}
|
||||
@utils.compose_patches(patches)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user