mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-07-30 15:04:48 +00:00
🔊 Update 1.0.0
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
///|
|
||||
pub struct RuntimeFileState {
|
||||
file : FileSinkState
|
||||
queued : Bool
|
||||
@@ -5,16 +6,20 @@ pub struct RuntimeFileState {
|
||||
dropped_count : Int
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn RuntimeFileState::new(
|
||||
file : FileSinkState,
|
||||
queued~ : Bool = false,
|
||||
pending_count~ : Int = 0,
|
||||
dropped_count~ : Int = 0,
|
||||
queued? : Bool = false,
|
||||
pending_count? : Int = 0,
|
||||
dropped_count? : Int = 0,
|
||||
) -> RuntimeFileState {
|
||||
{ file, queued, pending_count, dropped_count }
|
||||
}
|
||||
|
||||
fn file_sink_policy_to_json_value(policy : FileSinkPolicy) -> @json_parser.JsonValue {
|
||||
///|
|
||||
fn file_sink_policy_to_json_value(
|
||||
policy : FileSinkPolicy,
|
||||
) -> @json_parser.JsonValue {
|
||||
let obj : Map[String, @json_parser.JsonValue] = {
|
||||
"append": @json_parser.JsonValue::Bool(policy.append),
|
||||
"auto_flush": @json_parser.JsonValue::Bool(policy.auto_flush),
|
||||
@@ -26,11 +31,18 @@ fn file_sink_policy_to_json_value(policy : FileSinkPolicy) -> @json_parser.JsonV
|
||||
@json_parser.JsonValue::Object(obj)
|
||||
}
|
||||
|
||||
pub fn file_sink_policy_to_json(policy : FileSinkPolicy) -> @json_parser.JsonValue {
|
||||
///|
|
||||
pub fn file_sink_policy_to_json(
|
||||
policy : FileSinkPolicy,
|
||||
) -> @json_parser.JsonValue {
|
||||
file_sink_policy_to_json_value(policy)
|
||||
}
|
||||
|
||||
pub fn stringify_file_sink_policy(policy : FileSinkPolicy, pretty~ : Bool = false) -> String {
|
||||
///|
|
||||
pub fn stringify_file_sink_policy(
|
||||
policy : FileSinkPolicy,
|
||||
pretty? : Bool = false,
|
||||
) -> String {
|
||||
let value = file_sink_policy_to_json_value(policy)
|
||||
if pretty {
|
||||
@json_parser.stringify_pretty(value, 2)
|
||||
@@ -39,16 +51,27 @@ pub fn stringify_file_sink_policy(policy : FileSinkPolicy, pretty~ : Bool = fals
|
||||
}
|
||||
}
|
||||
|
||||
fn file_sink_state_to_json_value(state : FileSinkState) -> @json_parser.JsonValue {
|
||||
///|
|
||||
fn file_sink_state_to_json_value(
|
||||
state : FileSinkState,
|
||||
) -> @json_parser.JsonValue {
|
||||
let obj : Map[String, @json_parser.JsonValue] = {
|
||||
"path": @json_parser.JsonValue::String(state.path),
|
||||
"available": @json_parser.JsonValue::Bool(state.available),
|
||||
"append": @json_parser.JsonValue::Bool(state.append),
|
||||
"auto_flush": @json_parser.JsonValue::Bool(state.auto_flush),
|
||||
"open_failures": @json_parser.JsonValue::Number(state.open_failures.to_double()),
|
||||
"write_failures": @json_parser.JsonValue::Number(state.write_failures.to_double()),
|
||||
"flush_failures": @json_parser.JsonValue::Number(state.flush_failures.to_double()),
|
||||
"rotation_failures": @json_parser.JsonValue::Number(state.rotation_failures.to_double()),
|
||||
"open_failures": @json_parser.JsonValue::Number(
|
||||
state.open_failures.to_double(),
|
||||
),
|
||||
"write_failures": @json_parser.JsonValue::Number(
|
||||
state.write_failures.to_double(),
|
||||
),
|
||||
"flush_failures": @json_parser.JsonValue::Number(
|
||||
state.flush_failures.to_double(),
|
||||
),
|
||||
"rotation_failures": @json_parser.JsonValue::Number(
|
||||
state.rotation_failures.to_double(),
|
||||
),
|
||||
}
|
||||
match state.rotation {
|
||||
None => obj["rotation"] = @json_parser.JsonValue::Null
|
||||
@@ -57,11 +80,16 @@ fn file_sink_state_to_json_value(state : FileSinkState) -> @json_parser.JsonValu
|
||||
@json_parser.JsonValue::Object(obj)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn file_sink_state_to_json(state : FileSinkState) -> @json_parser.JsonValue {
|
||||
file_sink_state_to_json_value(state)
|
||||
}
|
||||
|
||||
pub fn stringify_file_sink_state(state : FileSinkState, pretty~ : Bool = false) -> String {
|
||||
///|
|
||||
pub fn stringify_file_sink_state(
|
||||
state : FileSinkState,
|
||||
pretty? : Bool = false,
|
||||
) -> String {
|
||||
let value = file_sink_state_to_json_value(state)
|
||||
if pretty {
|
||||
@json_parser.stringify_pretty(value, 2)
|
||||
@@ -70,16 +98,27 @@ pub fn stringify_file_sink_state(state : FileSinkState, pretty~ : Bool = false)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn runtime_file_state_to_json(state : RuntimeFileState) -> @json_parser.JsonValue {
|
||||
///|
|
||||
pub fn runtime_file_state_to_json(
|
||||
state : RuntimeFileState,
|
||||
) -> @json_parser.JsonValue {
|
||||
@json_parser.JsonValue::Object({
|
||||
"file": file_sink_state_to_json_value(state.file),
|
||||
"queued": @json_parser.JsonValue::Bool(state.queued),
|
||||
"pending_count": @json_parser.JsonValue::Number(state.pending_count.to_double()),
|
||||
"dropped_count": @json_parser.JsonValue::Number(state.dropped_count.to_double()),
|
||||
"pending_count": @json_parser.JsonValue::Number(
|
||||
state.pending_count.to_double(),
|
||||
),
|
||||
"dropped_count": @json_parser.JsonValue::Number(
|
||||
state.dropped_count.to_double(),
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn stringify_runtime_file_state(state : RuntimeFileState, pretty~ : Bool = false) -> String {
|
||||
///|
|
||||
pub fn stringify_runtime_file_state(
|
||||
state : RuntimeFileState,
|
||||
pretty? : Bool = false,
|
||||
) -> String {
|
||||
let value = runtime_file_state_to_json(state)
|
||||
if pretty {
|
||||
@json_parser.stringify_pretty(value, 2)
|
||||
|
||||
Reference in New Issue
Block a user