♻️ migrate to core json

This commit is contained in:
Nanaloveyuki
2026-07-17 21:19:11 +08:00
parent bcfb35d7ae
commit a58a0747bb
49 changed files with 533 additions and 601 deletions
+5 -9
View File
@@ -39,7 +39,7 @@ pub fn parse_logger_config_text(
}
///|
pub fn queue_config_to_json(queue : QueueConfig) -> @json_parser.JsonValue {
pub fn queue_config_to_json(queue : QueueConfig) -> Json {
@config_model.queue_config_to_json(queue)
}
@@ -52,9 +52,7 @@ pub fn stringify_queue_config(
}
///|
pub fn text_formatter_config_to_json(
config : TextFormatterConfig,
) -> @json_parser.JsonValue {
pub fn text_formatter_config_to_json(config : TextFormatterConfig) -> Json {
@config_model.text_formatter_config_to_json(config)
}
@@ -67,14 +65,12 @@ pub fn stringify_text_formatter_config(
}
///|
pub fn file_rotation_config_to_json(
config : FileRotation,
) -> @json_parser.JsonValue {
pub fn file_rotation_config_to_json(config : FileRotation) -> Json {
@file_model.file_rotation_config_to_json(config)
}
///|
pub fn sink_config_to_json(config : SinkConfig) -> @json_parser.JsonValue {
pub fn sink_config_to_json(config : SinkConfig) -> Json {
@config_model.sink_config_to_json(config)
}
@@ -87,7 +83,7 @@ pub fn stringify_sink_config(
}
///|
pub fn logger_config_to_json(config : LoggerConfig) -> @json_parser.JsonValue {
pub fn logger_config_to_json(config : LoggerConfig) -> Json {
@config_model.logger_config_to_json(config)
}
+88 -116
View File
@@ -170,102 +170,84 @@ pub fn default_logger_config() -> LoggerConfig {
///|
fn expect_object(
value : @json_parser.JsonValue,
value : Json,
context : String,
) -> Map[String, @json_parser.JsonValue] raise ConfigError {
match value.as_object() {
Some(obj) => obj
None => raise ConfigError::InvalidConfig("Expected object at " + context)
) -> Map[String, Json] raise ConfigError {
match value {
Json::Object(obj) => obj
_ => raise ConfigError::InvalidConfig("Expected object at " + context)
}
}
///|
fn get_string(
obj : Map[String, @json_parser.JsonValue],
obj : Map[String, Json],
key : String,
default? : String = "",
) -> String raise ConfigError {
match obj.get(key) {
None => default
Some(value) =>
match value.as_string() {
Some(text) => text
None =>
raise ConfigError::InvalidConfig("Expected string at key " + key)
}
Some(Json::String(text)) => text
Some(_) => raise ConfigError::InvalidConfig("Expected string at key " + key)
}
}
///|
fn get_optional_string(
obj : Map[String, @json_parser.JsonValue],
obj : Map[String, Json],
key : String,
) -> String? raise ConfigError {
match obj.get(key) {
None => None
Some(value) =>
match value.as_string() {
Some(text) => Some(text)
None =>
raise ConfigError::InvalidConfig("Expected string at key " + key)
}
Some(Json::String(text)) => Some(text)
Some(_) => raise ConfigError::InvalidConfig("Expected string at key " + key)
}
}
///|
fn get_bool(
obj : Map[String, @json_parser.JsonValue],
obj : Map[String, Json],
key : String,
default~ : Bool,
) -> Bool raise ConfigError {
match obj.get(key) {
None => default
Some(value) =>
match value.as_bool() {
Some(flag) => flag
None => raise ConfigError::InvalidConfig("Expected bool at key " + key)
}
Some(Json::True) => true
Some(Json::False) => false
Some(_) => raise ConfigError::InvalidConfig("Expected bool at key " + key)
}
}
///|
fn get_int(
obj : Map[String, @json_parser.JsonValue],
obj : Map[String, Json],
key : String,
default~ : Int,
) -> Int raise ConfigError {
match obj.get(key) {
None => default
Some(value) =>
match value.as_number() {
Some(number) => number.to_int()
None =>
raise ConfigError::InvalidConfig("Expected number at key " + key)
}
Some(Json::Number(number, ..)) => number.to_int()
Some(_) => raise ConfigError::InvalidConfig("Expected number at key " + key)
}
}
///|
fn get_optional_int64_string(
obj : Map[String, @json_parser.JsonValue],
obj : Map[String, Json],
key : String,
) -> Int64? raise ConfigError {
match obj.get(key) {
None => None
Some(value) =>
match value.as_string() {
Some(text) =>
Some(
@string.parse_int64(text) catch {
_ =>
raise ConfigError::InvalidConfig(
"Expected int64 string at key " + key,
)
},
)
None =>
raise ConfigError::InvalidConfig("Expected string at key " + key)
}
Some(Json::String(text)) =>
Some(
@string.parse_int64(text) catch {
_ =>
raise ConfigError::InvalidConfig(
"Expected int64 string at key " + key,
)
},
)
Some(_) => raise ConfigError::InvalidConfig("Expected string at key " + key)
}
}
@@ -355,7 +337,7 @@ fn sink_kind_label(kind : SinkKind) -> String {
///|
fn parse_text_formatter_config(
value : @json_parser.JsonValue,
value : Json,
) -> TextFormatterConfig raise ConfigError {
let obj = expect_object(value, "text_formatter")
TextFormatterConfig::new(
@@ -388,7 +370,7 @@ fn parse_text_formatter_config(
///|
fn parse_text_style_config(
value : @json_parser.JsonValue,
value : Json,
context : String,
) -> @formatting.TextStyle raise ConfigError {
let obj = expect_object(value, context)
@@ -404,7 +386,7 @@ fn parse_text_style_config(
///|
fn parse_style_tags_config(
value : @json_parser.JsonValue,
value : Json,
) -> Map[String, @formatting.TextStyle] raise ConfigError {
let obj = expect_object(value, "text_formatter.style_tags")
let style_tags : Map[String, @formatting.TextStyle] = Map([])
@@ -418,9 +400,7 @@ fn parse_style_tags_config(
}
///|
fn parse_queue_config(
value : @json_parser.JsonValue,
) -> QueueConfig raise ConfigError {
fn parse_queue_config(value : Json) -> QueueConfig raise ConfigError {
let obj = expect_object(value, "queue")
QueueConfig::new(
get_int(obj, "max_pending", default=0),
@@ -430,7 +410,7 @@ fn parse_queue_config(
///|
fn parse_file_rotation_config(
value : @json_parser.JsonValue,
value : Json,
) -> @file_model.FileRotation raise ConfigError {
let obj = expect_object(value, "sink.rotation")
let max_backups = get_int(obj, "max_backups", default=1)
@@ -446,9 +426,7 @@ fn parse_file_rotation_config(
}
///|
fn parse_sink_config(
value : @json_parser.JsonValue,
) -> SinkConfig raise ConfigError {
fn parse_sink_config(value : Json) -> SinkConfig raise ConfigError {
let obj = expect_object(value, "sink")
let kind = parse_sink_kind(get_string(obj, "kind", default="console"))
let formatter = match obj.get("text_formatter") {
@@ -480,7 +458,7 @@ fn parse_sink_config(
pub fn parse_logger_config_text(
input : String,
) -> LoggerConfig raise ConfigError {
let root = @json_parser.parse(input) catch {
let root = @json.parse(input) catch {
e => raise ConfigError::InvalidConfig("Invalid JSON: " + e.to_string())
}
let obj = expect_object(root, "root")
@@ -500,10 +478,10 @@ pub fn parse_logger_config_text(
}
///|
pub fn queue_config_to_json(queue : QueueConfig) -> @json_parser.JsonValue {
@json_parser.JsonValue::Object({
"max_pending": @json_parser.JsonValue::Number(queue.max_pending.to_double()),
"overflow": @json_parser.JsonValue::String(
pub fn queue_config_to_json(queue : QueueConfig) -> Json {
Json::object({
"max_pending": Json::number(queue.max_pending.to_double()),
"overflow": Json::string(
match queue.overflow {
@queue_model.QueueOverflowPolicy::DropNewest => "DropNewest"
@queue_model.QueueOverflowPolicy::DropOldest => "DropOldest"
@@ -519,76 +497,70 @@ pub fn stringify_queue_config(
) -> String {
let value = queue_config_to_json(queue)
if pretty {
@json_parser.stringify_pretty(value, 2)
value.stringify(indent=2)
} else {
@json_parser.stringify(value)
value.stringify()
}
}
///|
pub fn text_formatter_config_to_json(
config : TextFormatterConfig,
) -> @json_parser.JsonValue {
let obj : Map[String, @json_parser.JsonValue] = {
"show_timestamp": @json_parser.JsonValue::Bool(config.show_timestamp),
"show_level": @json_parser.JsonValue::Bool(config.show_level),
"show_target": @json_parser.JsonValue::Bool(config.show_target),
"show_fields": @json_parser.JsonValue::Bool(config.show_fields),
"separator": @json_parser.JsonValue::String(config.separator),
"field_separator": @json_parser.JsonValue::String(config.field_separator),
"template": @json_parser.JsonValue::String(config.template),
"color_mode": @json_parser.JsonValue::String(
@formatting.color_mode_label(config.color_mode),
),
"color_support": @json_parser.JsonValue::String(
pub fn text_formatter_config_to_json(config : TextFormatterConfig) -> Json {
let obj : Map[String, Json] = {
"show_timestamp": Json::boolean(config.show_timestamp),
"show_level": Json::boolean(config.show_level),
"show_target": Json::boolean(config.show_target),
"show_fields": Json::boolean(config.show_fields),
"separator": Json::string(config.separator),
"field_separator": Json::string(config.field_separator),
"template": Json::string(config.template),
"color_mode": Json::string(@formatting.color_mode_label(config.color_mode)),
"color_support": Json::string(
@formatting.color_support_label(config.color_support),
),
"style_markup": @json_parser.JsonValue::String(
"style_markup": Json::string(
@formatting.style_markup_mode_label(config.style_markup),
),
"target_style_markup": @json_parser.JsonValue::String(
"target_style_markup": Json::string(
@formatting.style_markup_mode_label(config.target_style_markup),
),
"fields_style_markup": @json_parser.JsonValue::String(
"fields_style_markup": Json::string(
@formatting.style_markup_mode_label(config.fields_style_markup),
),
}
if config.style_tags.length() != 0 {
obj["style_tags"] = style_tags_config_to_json(config.style_tags)
}
@json_parser.JsonValue::Object(obj)
Json::object(obj)
}
///|
fn text_style_config_to_json(
style : @formatting.TextStyle,
) -> @json_parser.JsonValue {
let obj : Map[String, @json_parser.JsonValue] = {
"bold": @json_parser.JsonValue::Bool(style.bold),
"dim": @json_parser.JsonValue::Bool(style.dim),
"italic": @json_parser.JsonValue::Bool(style.italic),
"underline": @json_parser.JsonValue::Bool(style.underline),
fn text_style_config_to_json(style : @formatting.TextStyle) -> Json {
let obj : Map[String, Json] = {
"bold": Json::boolean(style.bold),
"dim": Json::boolean(style.dim),
"italic": Json::boolean(style.italic),
"underline": Json::boolean(style.underline),
}
match style.fg {
Some(value) => obj["fg"] = @json_parser.JsonValue::String(value)
Some(value) => obj["fg"] = Json::string(value)
None => ()
}
match style.bg {
Some(value) => obj["bg"] = @json_parser.JsonValue::String(value)
Some(value) => obj["bg"] = Json::string(value)
None => ()
}
@json_parser.JsonValue::Object(obj)
Json::object(obj)
}
///|
fn style_tags_config_to_json(
style_tags : Map[String, @formatting.TextStyle],
) -> @json_parser.JsonValue {
let obj : Map[String, @json_parser.JsonValue] = Map([])
) -> Json {
let obj : Map[String, Json] = Map([])
for name, style in style_tags {
obj[name] = text_style_config_to_json(style)
}
@json_parser.JsonValue::Object(obj)
Json::object(obj)
}
///|
@@ -598,19 +570,19 @@ pub fn stringify_text_formatter_config(
) -> String {
let value = text_formatter_config_to_json(config)
if pretty {
@json_parser.stringify_pretty(value, 2)
value.stringify(indent=2)
} else {
@json_parser.stringify(value)
value.stringify()
}
}
///|
pub fn sink_config_to_json(config : SinkConfig) -> @json_parser.JsonValue {
let obj : Map[String, @json_parser.JsonValue] = {
"kind": @json_parser.JsonValue::String(sink_kind_label(config.kind)),
"path": @json_parser.JsonValue::String(config.path),
"append": @json_parser.JsonValue::Bool(config.append),
"auto_flush": @json_parser.JsonValue::Bool(config.auto_flush),
pub fn sink_config_to_json(config : SinkConfig) -> Json {
let obj : Map[String, Json] = {
"kind": Json::string(sink_kind_label(config.kind)),
"path": Json::string(config.path),
"append": Json::boolean(config.append),
"auto_flush": Json::boolean(config.auto_flush),
"text_formatter": text_formatter_config_to_json(config.text_formatter),
}
match config.rotation {
@@ -618,7 +590,7 @@ pub fn sink_config_to_json(config : SinkConfig) -> @json_parser.JsonValue {
Some(rotation) =>
obj["rotation"] = @file_model.file_rotation_config_to_json(rotation)
}
@json_parser.JsonValue::Object(obj)
Json::object(obj)
}
///|
@@ -628,25 +600,25 @@ pub fn stringify_sink_config(
) -> String {
let value = sink_config_to_json(config)
if pretty {
@json_parser.stringify_pretty(value, 2)
value.stringify(indent=2)
} else {
@json_parser.stringify(value)
value.stringify()
}
}
///|
pub fn logger_config_to_json(config : LoggerConfig) -> @json_parser.JsonValue {
let obj : Map[String, @json_parser.JsonValue] = {
"min_level": @json_parser.JsonValue::String(config.min_level.label()),
"target": @json_parser.JsonValue::String(config.target),
"timestamp": @json_parser.JsonValue::Bool(config.timestamp),
pub fn logger_config_to_json(config : LoggerConfig) -> Json {
let obj : Map[String, Json] = {
"min_level": Json::string(config.min_level.label()),
"target": Json::string(config.target),
"timestamp": Json::boolean(config.timestamp),
"sink": sink_config_to_json(config.sink),
}
match config.queue {
None => ()
Some(queue) => obj["queue"] = queue_config_to_json(queue)
}
@json_parser.JsonValue::Object(obj)
Json::object(obj)
}
///|
@@ -656,8 +628,8 @@ pub fn stringify_logger_config(
) -> String {
let value = logger_config_to_json(config)
if pretty {
@json_parser.stringify_pretty(value, 2)
value.stringify(indent=2)
} else {
@json_parser.stringify(value)
value.stringify()
}
}
+1 -1
View File
@@ -3,6 +3,6 @@ import {
"Nanaloveyuki/BitLogger/src/file_model",
"Nanaloveyuki/BitLogger/src/formatting",
"Nanaloveyuki/BitLogger/src/queue_model",
"maria/json_parser",
"moonbitlang/core/json",
"moonbitlang/core/string",
}
+4 -5
View File
@@ -6,7 +6,6 @@ import {
"Nanaloveyuki/BitLogger/src/file_model",
"Nanaloveyuki/BitLogger/src/formatting",
"Nanaloveyuki/BitLogger/src/queue_model",
"maria/json_parser",
}
// Values
@@ -16,13 +15,13 @@ pub fn default_sink_config() -> SinkConfig
pub fn default_text_formatter_config() -> TextFormatterConfig
pub fn logger_config_to_json(LoggerConfig) -> @json_parser.JsonValue
pub fn logger_config_to_json(LoggerConfig) -> Json
pub fn parse_logger_config_text(String) -> LoggerConfig raise ConfigError
pub fn queue_config_to_json(QueueConfig) -> @json_parser.JsonValue
pub fn queue_config_to_json(QueueConfig) -> Json
pub fn sink_config_to_json(SinkConfig) -> @json_parser.JsonValue
pub fn sink_config_to_json(SinkConfig) -> Json
pub fn stringify_logger_config(LoggerConfig, pretty? : Bool) -> String
@@ -32,7 +31,7 @@ pub fn stringify_sink_config(SinkConfig, pretty? : Bool) -> String
pub fn stringify_text_formatter_config(TextFormatterConfig, pretty? : Bool) -> String
pub fn text_formatter_config_to_json(TextFormatterConfig) -> @json_parser.JsonValue
pub fn text_formatter_config_to_json(TextFormatterConfig) -> Json
// Errors
pub(all) suberror ConfigError {
+28 -43
View File
@@ -1,34 +1,27 @@
///|
pub fn file_rotation_config_to_json(
config : FileRotation,
) -> @json_parser.JsonValue {
let obj : Map[String, @json_parser.JsonValue] = {
"max_bytes": @json_parser.JsonValue::Number(config.max_bytes.to_double()),
"max_backups": @json_parser.JsonValue::Number(
config.max_backups.to_double(),
),
pub fn file_rotation_config_to_json(config : FileRotation) -> Json {
let obj : Map[String, Json] = {
"max_bytes": Json::number(config.max_bytes.to_double()),
"max_backups": Json::number(config.max_backups.to_double()),
}
match config.native_wide_max_bytes {
Some(value) =>
obj["max_bytes_i64"] = @json_parser.JsonValue::String(value.to_string())
Some(value) => obj["max_bytes_i64"] = Json::string(value.to_string())
None => ()
}
@json_parser.JsonValue::Object(obj)
Json::object(obj)
}
///|
pub fn file_sink_policy_to_json(
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),
pub fn file_sink_policy_to_json(policy : FileSinkPolicy) -> Json {
let obj : Map[String, Json] = {
"append": Json::boolean(policy.append),
"auto_flush": Json::boolean(policy.auto_flush),
}
match policy.rotation {
None => obj["rotation"] = @json_parser.JsonValue::Null
None => obj["rotation"] = Json::null()
Some(rotation) => obj["rotation"] = file_rotation_config_to_json(rotation)
}
@json_parser.JsonValue::Object(obj)
Json::object(obj)
}
///|
@@ -38,37 +31,29 @@ pub fn stringify_file_sink_policy(
) -> String {
let value = file_sink_policy_to_json(policy)
if pretty {
@json_parser.stringify_pretty(value, 2)
value.stringify(indent=2)
} else {
@json_parser.stringify(value)
value.stringify()
}
}
///|
pub fn file_sink_state_to_json(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(),
),
pub fn file_sink_state_to_json(state : FileSinkState) -> Json {
let obj : Map[String, Json] = {
"path": Json::string(state.path),
"available": Json::boolean(state.available),
"append": Json::boolean(state.append),
"auto_flush": Json::boolean(state.auto_flush),
"open_failures": Json::number(state.open_failures.to_double()),
"write_failures": Json::number(state.write_failures.to_double()),
"flush_failures": Json::number(state.flush_failures.to_double()),
"rotation_failures": Json::number(state.rotation_failures.to_double()),
}
match state.rotation {
None => obj["rotation"] = @json_parser.JsonValue::Null
None => obj["rotation"] = Json::null()
Some(rotation) => obj["rotation"] = file_rotation_config_to_json(rotation)
}
@json_parser.JsonValue::Object(obj)
Json::object(obj)
}
///|
@@ -78,8 +63,8 @@ pub fn stringify_file_sink_state(
) -> String {
let value = file_sink_state_to_json(state)
if pretty {
@json_parser.stringify_pretty(value, 2)
value.stringify(indent=2)
} else {
@json_parser.stringify(value)
value.stringify()
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
import {
"maria/json_parser",
"moonbitlang/core/json",
}
+4 -8
View File
@@ -1,22 +1,18 @@
// Generated using `moon info`, DON'T EDIT IT
package "Nanaloveyuki/BitLogger/src/file_model"
import {
"maria/json_parser",
}
// Values
pub fn file_rotation(Int, max_backups? : Int) -> FileRotation
pub fn file_rotation_config_to_json(FileRotation) -> @json_parser.JsonValue
pub fn file_rotation_config_to_json(FileRotation) -> Json
pub fn file_rotation_i64(Int64, max_backups? : Int) -> FileRotation
pub fn file_sink_policy_to_json(FileSinkPolicy) -> @json_parser.JsonValue
pub fn file_sink_policy_to_json(FileSinkPolicy) -> Json
pub fn file_sink_state_to_json(FileSinkState) -> @json_parser.JsonValue
pub fn file_sink_state_to_json(FileSinkState) -> Json
pub fn runtime_file_state_to_json(RuntimeFileState) -> @json_parser.JsonValue
pub fn runtime_file_state_to_json(RuntimeFileState) -> Json
pub fn stringify_file_sink_policy(FileSinkPolicy, pretty? : Bool) -> String
+7 -13
View File
@@ -17,18 +17,12 @@ pub fn RuntimeFileState::new(
}
///|
pub fn runtime_file_state_to_json(
state : RuntimeFileState,
) -> @json_parser.JsonValue {
@json_parser.JsonValue::Object({
pub fn runtime_file_state_to_json(state : RuntimeFileState) -> Json {
Json::object({
"file": file_sink_state_to_json(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(),
),
"queued": Json::boolean(state.queued),
"pending_count": Json::number(state.pending_count.to_double()),
"dropped_count": Json::number(state.dropped_count.to_double()),
})
}
@@ -39,8 +33,8 @@ pub fn stringify_runtime_file_state(
) -> String {
let value = runtime_file_state_to_json(state)
if pretty {
@json_parser.stringify_pretty(value, 2)
value.stringify(indent=2)
} else {
@json_parser.stringify(value)
value.stringify()
}
}
+32
View File
@@ -0,0 +1,32 @@
///|
fn Json::expect_json_object(self : Json) -> Map[String, Json] {
match self {
Json::Object(value) => value
_ => abort("Expected JSON object")
}
}
///|
fn Json::expect_json_number(self : Json) -> Double {
match self {
Json::Number(value, ..) => value
_ => abort("Expected JSON number")
}
}
///|
fn Json::expect_json_string(self : Json) -> String {
match self {
Json::String(value) => value
_ => abort("Expected JSON string")
}
}
///|
fn Json::expect_json_bool(self : Json) -> Bool {
match self {
Json::True => true
Json::False => false
_ => abort("Expected JSON bool")
}
}
+67 -74
View File
@@ -43,11 +43,7 @@ test "config subtype json helpers stringify stable shapes" {
content="{\"kind\":\"file\",\"path\":\"logs/demo.log\",\"append\":false,\"auto_flush\":false,\"text_formatter\":{\"show_timestamp\":false,\"show_level\":true,\"show_target\":true,\"show_fields\":true,\"separator\":\" \",\"field_separator\":\" \",\"template\":\"\",\"color_mode\":\"auto\",\"color_support\":\"truecolor\",\"style_markup\":\"full\",\"target_style_markup\":\"disabled\",\"fields_style_markup\":\"disabled\"},\"rotation\":{\"max_bytes\":128,\"max_backups\":2}}",
)
inspect(
@json_parser.stringify(
file_rotation_config_to_json(
file_rotation_i64(4294967296L, max_backups=2),
),
),
file_rotation_config_to_json(file_rotation_i64(4294967296L, max_backups=2)).stringify(),
content="{\"max_bytes\":2147483647,\"max_backups\":2,\"max_bytes_i64\":\"4294967296\"}",
)
}
@@ -57,17 +53,17 @@ test "config json helpers export stable structured shapes" {
let queue_json = queue_config_to_json(
QueueConfig::new(8, overflow=QueueOverflowPolicy::DropOldest),
)
let queue_obj = queue_json.as_object().unwrap()
let queue_obj = queue_json.expect_json_object()
inspect(
@json_parser.stringify(queue_json),
queue_json.stringify(),
content="{\"max_pending\":8,\"overflow\":\"DropOldest\"}",
)
inspect(
queue_obj.get("max_pending").unwrap().as_number().unwrap().to_int(),
queue_obj.get("max_pending").unwrap().expect_json_number().to_int(),
content="8",
)
inspect(
queue_obj.get("overflow").unwrap().as_string().unwrap(),
queue_obj.get("overflow").unwrap().expect_json_string(),
content="DropOldest",
)
@@ -88,55 +84,54 @@ test "config json helpers export stable structured shapes" {
style_tags={ "accent": text_style(fg=Some("#4cc9f0"), bold=true) },
),
)
let formatter_obj = formatter_json.as_object().unwrap()
let formatter_obj = formatter_json.expect_json_object()
let style_tags_obj = formatter_obj
.get("style_tags")
.unwrap()
.as_object()
.unwrap()
let accent_obj = style_tags_obj.get("accent").unwrap().as_object().unwrap()
.expect_json_object()
let accent_obj = style_tags_obj.get("accent").unwrap().expect_json_object()
inspect(
formatter_obj.get("show_timestamp").unwrap().as_bool().unwrap(),
formatter_obj.get("show_timestamp").unwrap().expect_json_bool(),
content="false",
)
inspect(
formatter_obj.get("show_target").unwrap().as_bool().unwrap(),
formatter_obj.get("show_target").unwrap().expect_json_bool(),
content="false",
)
inspect(
formatter_obj.get("separator").unwrap().as_string().unwrap(),
formatter_obj.get("separator").unwrap().expect_json_string(),
content=" | ",
)
inspect(
formatter_obj.get("field_separator").unwrap().as_string().unwrap(),
formatter_obj.get("field_separator").unwrap().expect_json_string(),
content=",",
)
inspect(
formatter_obj.get("template").unwrap().as_string().unwrap(),
formatter_obj.get("template").unwrap().expect_json_string(),
content="[{level}] {message} :: {fields}",
)
inspect(
formatter_obj.get("color_mode").unwrap().as_string().unwrap(),
formatter_obj.get("color_mode").unwrap().expect_json_string(),
content="always",
)
inspect(
formatter_obj.get("color_support").unwrap().as_string().unwrap(),
formatter_obj.get("color_support").unwrap().expect_json_string(),
content="basic",
)
inspect(
formatter_obj.get("style_markup").unwrap().as_string().unwrap(),
formatter_obj.get("style_markup").unwrap().expect_json_string(),
content="builtin",
)
inspect(
formatter_obj.get("target_style_markup").unwrap().as_string().unwrap(),
formatter_obj.get("target_style_markup").unwrap().expect_json_string(),
content="builtin",
)
inspect(
formatter_obj.get("fields_style_markup").unwrap().as_string().unwrap(),
formatter_obj.get("fields_style_markup").unwrap().expect_json_string(),
content="disabled",
)
inspect(accent_obj.get("bold").unwrap().as_bool().unwrap(), content="true")
inspect(accent_obj.get("fg").unwrap().as_string().unwrap(), content="#4cc9f0")
inspect(accent_obj.get("bold").unwrap().expect_json_bool(), content="true")
inspect(accent_obj.get("fg").unwrap().expect_json_string(), content="#4cc9f0")
let sink_json = sink_config_to_json(
SinkConfig::new(
@@ -151,37 +146,36 @@ test "config json helpers export stable structured shapes" {
),
),
)
let sink_obj = sink_json.as_object().unwrap()
let sink_obj = sink_json.expect_json_object()
let sink_formatter_obj = sink_obj
.get("text_formatter")
.unwrap()
.as_object()
.unwrap()
let rotation_obj = sink_obj.get("rotation").unwrap().as_object().unwrap()
inspect(sink_obj.get("kind").unwrap().as_string().unwrap(), content="file")
.expect_json_object()
let rotation_obj = sink_obj.get("rotation").unwrap().expect_json_object()
inspect(sink_obj.get("kind").unwrap().expect_json_string(), content="file")
inspect(
sink_obj.get("path").unwrap().as_string().unwrap(),
sink_obj.get("path").unwrap().expect_json_string(),
content="logs/demo.log",
)
inspect(sink_obj.get("append").unwrap().as_bool().unwrap(), content="false")
inspect(sink_obj.get("append").unwrap().expect_json_bool(), content="false")
inspect(
sink_obj.get("auto_flush").unwrap().as_bool().unwrap(),
sink_obj.get("auto_flush").unwrap().expect_json_bool(),
content="false",
)
inspect(
sink_formatter_obj.get("show_timestamp").unwrap().as_bool().unwrap(),
sink_formatter_obj.get("show_timestamp").unwrap().expect_json_bool(),
content="false",
)
inspect(
sink_formatter_obj.get("color_mode").unwrap().as_string().unwrap(),
sink_formatter_obj.get("color_mode").unwrap().expect_json_string(),
content="auto",
)
inspect(
rotation_obj.get("max_bytes").unwrap().as_number().unwrap().to_int(),
rotation_obj.get("max_bytes").unwrap().expect_json_number().to_int(),
content="128",
)
inspect(
rotation_obj.get("max_backups").unwrap().as_number().unwrap().to_int(),
rotation_obj.get("max_backups").unwrap().expect_json_number().to_int(),
content="2",
)
inspect(rotation_obj.get("max_bytes_i64") is None, content="true")
@@ -189,17 +183,17 @@ test "config json helpers export stable structured shapes" {
let wide_rotation_json = file_rotation_config_to_json(
file_rotation_i64(4294967296L, max_backups=3),
)
let wide_rotation_obj = wide_rotation_json.as_object().unwrap()
let wide_rotation_obj = wide_rotation_json.expect_json_object()
inspect(
wide_rotation_obj.get("max_bytes").unwrap().as_number().unwrap().to_int(),
wide_rotation_obj.get("max_bytes").unwrap().expect_json_number().to_int(),
content="2147483647",
)
inspect(
wide_rotation_obj.get("max_backups").unwrap().as_number().unwrap().to_int(),
wide_rotation_obj.get("max_backups").unwrap().expect_json_number().to_int(),
content="3",
)
inspect(
wide_rotation_obj.get("max_bytes_i64").unwrap().as_string().unwrap(),
wide_rotation_obj.get("max_bytes_i64").unwrap().expect_json_string(),
content="4294967296",
)
@@ -212,28 +206,28 @@ test "config json helpers export stable structured shapes" {
queue=Some(QueueConfig::new(8, overflow=QueueOverflowPolicy::DropNewest)),
),
)
let logger_obj = logger_json.as_object().unwrap()
let logger_sink_obj = logger_obj.get("sink").unwrap().as_object().unwrap()
let logger_queue_obj = logger_obj.get("queue").unwrap().as_object().unwrap()
let logger_obj = logger_json.expect_json_object()
let logger_sink_obj = logger_obj.get("sink").unwrap().expect_json_object()
let logger_queue_obj = logger_obj.get("queue").unwrap().expect_json_object()
inspect(
logger_obj.get("min_level").unwrap().as_string().unwrap(),
logger_obj.get("min_level").unwrap().expect_json_string(),
content="WARN",
)
inspect(logger_obj.get("target").unwrap().as_string().unwrap(), content="api")
inspect(logger_obj.get("target").unwrap().expect_json_string(), content="api")
inspect(
logger_obj.get("timestamp").unwrap().as_bool().unwrap(),
logger_obj.get("timestamp").unwrap().expect_json_bool(),
content="true",
)
inspect(
logger_sink_obj.get("kind").unwrap().as_string().unwrap(),
logger_sink_obj.get("kind").unwrap().expect_json_string(),
content="text_console",
)
inspect(
logger_queue_obj.get("max_pending").unwrap().as_number().unwrap().to_int(),
logger_queue_obj.get("max_pending").unwrap().expect_json_number().to_int(),
content="8",
)
inspect(
logger_queue_obj.get("overflow").unwrap().as_string().unwrap(),
logger_queue_obj.get("overflow").unwrap().expect_json_string(),
content="DropNewest",
)
}
@@ -242,81 +236,80 @@ test "config json helpers export stable structured shapes" {
test "logger config json export materializes parsed omitted defaults" {
let parsed = parse_logger_config_text("{}")
let logger_json = logger_config_to_json(parsed)
let logger_obj = logger_json.as_object().unwrap()
let sink_obj = logger_obj.get("sink").unwrap().as_object().unwrap()
let logger_obj = logger_json.expect_json_object()
let sink_obj = logger_obj.get("sink").unwrap().expect_json_object()
let formatter_obj = sink_obj
.get("text_formatter")
.unwrap()
.as_object()
.unwrap()
.expect_json_object()
inspect(
@json_parser.stringify(logger_json),
logger_json.stringify(),
content="{\"min_level\":\"INFO\",\"target\":\"\",\"timestamp\":false,\"sink\":{\"kind\":\"console\",\"path\":\"\",\"append\":true,\"auto_flush\":true,\"text_formatter\":{\"show_timestamp\":true,\"show_level\":true,\"show_target\":true,\"show_fields\":true,\"separator\":\" \",\"field_separator\":\" \",\"template\":\"\",\"color_mode\":\"never\",\"color_support\":\"truecolor\",\"style_markup\":\"full\",\"target_style_markup\":\"disabled\",\"fields_style_markup\":\"disabled\"}}}",
)
inspect(
logger_obj.get("min_level").unwrap().as_string().unwrap(),
logger_obj.get("min_level").unwrap().expect_json_string(),
content="INFO",
)
inspect(logger_obj.get("target").unwrap().as_string().unwrap(), content="")
inspect(logger_obj.get("target").unwrap().expect_json_string(), content="")
inspect(
logger_obj.get("timestamp").unwrap().as_bool().unwrap(),
logger_obj.get("timestamp").unwrap().expect_json_bool(),
content="false",
)
inspect(logger_obj.get("queue") is None, content="true")
inspect(sink_obj.get("kind").unwrap().as_string().unwrap(), content="console")
inspect(sink_obj.get("path").unwrap().as_string().unwrap(), content="")
inspect(sink_obj.get("append").unwrap().as_bool().unwrap(), content="true")
inspect(sink_obj.get("kind").unwrap().expect_json_string(), content="console")
inspect(sink_obj.get("path").unwrap().expect_json_string(), content="")
inspect(sink_obj.get("append").unwrap().expect_json_bool(), content="true")
inspect(
sink_obj.get("auto_flush").unwrap().as_bool().unwrap(),
sink_obj.get("auto_flush").unwrap().expect_json_bool(),
content="true",
)
inspect(
formatter_obj.get("show_timestamp").unwrap().as_bool().unwrap(),
formatter_obj.get("show_timestamp").unwrap().expect_json_bool(),
content="true",
)
inspect(
formatter_obj.get("show_level").unwrap().as_bool().unwrap(),
formatter_obj.get("show_level").unwrap().expect_json_bool(),
content="true",
)
inspect(
formatter_obj.get("show_target").unwrap().as_bool().unwrap(),
formatter_obj.get("show_target").unwrap().expect_json_bool(),
content="true",
)
inspect(
formatter_obj.get("show_fields").unwrap().as_bool().unwrap(),
formatter_obj.get("show_fields").unwrap().expect_json_bool(),
content="true",
)
inspect(
formatter_obj.get("separator").unwrap().as_string().unwrap(),
formatter_obj.get("separator").unwrap().expect_json_string(),
content=" ",
)
inspect(
formatter_obj.get("field_separator").unwrap().as_string().unwrap(),
formatter_obj.get("field_separator").unwrap().expect_json_string(),
content=" ",
)
inspect(
formatter_obj.get("template").unwrap().as_string().unwrap(),
formatter_obj.get("template").unwrap().expect_json_string(),
content="",
)
inspect(
formatter_obj.get("color_mode").unwrap().as_string().unwrap(),
formatter_obj.get("color_mode").unwrap().expect_json_string(),
content="never",
)
inspect(
formatter_obj.get("color_support").unwrap().as_string().unwrap(),
formatter_obj.get("color_support").unwrap().expect_json_string(),
content="truecolor",
)
inspect(
formatter_obj.get("style_markup").unwrap().as_string().unwrap(),
formatter_obj.get("style_markup").unwrap().expect_json_string(),
content="full",
)
inspect(
formatter_obj.get("target_style_markup").unwrap().as_string().unwrap(),
formatter_obj.get("target_style_markup").unwrap().expect_json_string(),
content="disabled",
)
inspect(
formatter_obj.get("fields_style_markup").unwrap().as_string().unwrap(),
formatter_obj.get("fields_style_markup").unwrap().expect_json_string(),
content="disabled",
)
inspect(formatter_obj.get("style_tags") is None, content="true")
-1
View File
@@ -9,7 +9,6 @@ import {
"Nanaloveyuki/BitLogger/src/queue_model",
"Nanaloveyuki/BitLogger/src/runtime",
"Nanaloveyuki/BitLogger/src/sink_graph",
"maria/json_parser",
"moonbitlang/core/array",
"moonbitlang/core/builtin",
"moonbitlang/core/env",
+8 -9
View File
@@ -10,7 +10,6 @@ import {
"Nanaloveyuki/BitLogger/src/queue_model",
"Nanaloveyuki/BitLogger/src/runtime",
"Nanaloveyuki/BitLogger/src/sink_graph",
"maria/json_parser",
}
// Values
@@ -70,15 +69,15 @@ pub fn file(String, min_level? : @core.Level, target? : String, timestamp? : Boo
pub fn file_rotation(Int, max_backups? : Int) -> @file_model.FileRotation
pub fn file_rotation_config_to_json(@file_model.FileRotation) -> @json_parser.JsonValue
pub fn file_rotation_config_to_json(@file_model.FileRotation) -> Json
pub fn file_rotation_i64(Int64, max_backups? : Int) -> @file_model.FileRotation
pub fn file_sink(String, append? : Bool, auto_flush? : Bool, rotation? : @file_model.FileRotation?, formatter? : (@core.Record) -> String) -> @file_runtime.FileSink
pub fn file_sink_policy_to_json(@file_model.FileSinkPolicy) -> @json_parser.JsonValue
pub fn file_sink_policy_to_json(@file_model.FileSinkPolicy) -> Json
pub fn file_sink_state_to_json(@file_model.FileSinkState) -> @json_parser.JsonValue
pub fn file_sink_state_to_json(@file_model.FileSinkState) -> Json
pub fn[S] filter_sink(S, (@core.Record) -> Bool) -> @sink_graph.FilterSink[S]
@@ -106,7 +105,7 @@ pub fn level_at_least(@core.Level) -> (@core.Record) -> Bool
pub fn log(@core.Level, String, fields? : Array[@core.Field]) -> Unit
pub fn logger_config_to_json(@config_model.LoggerConfig) -> @json_parser.JsonValue
pub fn logger_config_to_json(@config_model.LoggerConfig) -> Json
pub fn message_contains(String) -> (@core.Record) -> Bool
@@ -126,7 +125,7 @@ pub fn[S] patch_sink(S, (@core.Record) -> @core.Record) -> @sink_graph.PatchSink
pub fn prefix_message(String) -> (@core.Record) -> @core.Record
pub fn queue_config_to_json(@config_model.QueueConfig) -> @json_parser.JsonValue
pub fn queue_config_to_json(@config_model.QueueConfig) -> Json
pub fn[S] queued_sink(S, max_pending? : Int, overflow? : @queue_model.QueueOverflowPolicy) -> @sink_graph.QueuedSink[S]
@@ -136,7 +135,7 @@ pub fn redact_fields(Array[String], placeholder? : String) -> (@core.Record) ->
pub fn reset_global_style_tag_registry() -> Unit
pub fn runtime_file_state_to_json(@file_model.RuntimeFileState) -> @json_parser.JsonValue
pub fn runtime_file_state_to_json(@file_model.RuntimeFileState) -> Json
pub fn set_default_min_level(@core.Level) -> Unit
@@ -146,7 +145,7 @@ pub fn set_global_style_tag_registry(@formatting.StyleTagRegistry) -> Unit
pub fn set_target(String) -> (@core.Record) -> @core.Record
pub fn sink_config_to_json(@config_model.SinkConfig) -> @json_parser.JsonValue
pub fn sink_config_to_json(@config_model.SinkConfig) -> Json
pub fn[A, B] split_by_level(A, B, min_level? : @core.Level) -> @sink_graph.SplitSink[A, B]
@@ -182,7 +181,7 @@ pub fn text_console_sink(@formatting.TextFormatter) -> @sink_graph.FormattedCons
pub fn text_formatter(show_timestamp? : Bool, show_level? : Bool, show_target? : Bool, show_fields? : Bool, separator? : String, field_separator? : String, template? : String, color_mode? : @formatting.ColorMode, color_support? : @formatting.ColorSupport, style_markup? : @formatting.StyleMarkupMode, target_style_markup? : @formatting.StyleMarkupMode, fields_style_markup? : @formatting.StyleMarkupMode, style_tags? : @formatting.StyleTagRegistry?) -> @formatting.TextFormatter
pub fn text_formatter_config_to_json(@config_model.TextFormatterConfig) -> @json_parser.JsonValue
pub fn text_formatter_config_to_json(@config_model.TextFormatterConfig) -> Json
pub fn text_style(fg? : String?, bg? : String?, bold? : Bool, dim? : Bool, italic? : Bool, underline? : Bool) -> @formatting.TextStyle
+1 -1
View File
@@ -4,5 +4,5 @@ import {
"Nanaloveyuki/BitLogger/src/file_model",
"Nanaloveyuki/BitLogger/src/formatting",
"Nanaloveyuki/BitLogger/src/sink_graph",
"maria/json_parser",
"moonbitlang/core/json",
}
+1 -2
View File
@@ -7,7 +7,6 @@ import {
"Nanaloveyuki/BitLogger/src/file_model",
"Nanaloveyuki/BitLogger/src/file_runtime",
"Nanaloveyuki/BitLogger/src/sink_graph",
"maria/json_parser",
}
// Values
@@ -15,7 +14,7 @@ pub fn apply_queue_config(RuntimeSink, @config_model.QueueConfig) -> RuntimeSink
pub fn build_runtime_sink(@config_model.SinkConfig) -> RuntimeSink
pub fn runtime_file_state_to_json(@file_model.RuntimeFileState) -> @json_parser.JsonValue
pub fn runtime_file_state_to_json(@file_model.RuntimeFileState) -> Json
pub fn stringify_runtime_file_state(@file_model.RuntimeFileState, pretty? : Bool) -> String
+1 -3
View File
@@ -55,9 +55,7 @@ pub struct RuntimeSinkProgress {
}
///|
pub fn runtime_file_state_to_json(
state : RuntimeFileState,
) -> @json_parser.JsonValue {
pub fn runtime_file_state_to_json(state : RuntimeFileState) -> Json {
@file_model.runtime_file_state_to_json(state)
}
+50 -63
View File
@@ -3,17 +3,17 @@ test "file state json helpers stringify stable snapshots" {
let rotation_json = file_rotation_config_to_json(
file_rotation(64, max_backups=2),
)
let rotation_obj = rotation_json.as_object().unwrap()
let rotation_obj = rotation_json.expect_json_object()
inspect(
@json_parser.stringify(rotation_json),
rotation_json.stringify(),
content="{\"max_bytes\":64,\"max_backups\":2}",
)
inspect(
rotation_obj.get("max_bytes").unwrap().as_number().unwrap().to_int(),
rotation_obj.get("max_bytes").unwrap().expect_json_number().to_int(),
content="64",
)
inspect(
rotation_obj.get("max_backups").unwrap().as_number().unwrap().to_int(),
rotation_obj.get("max_backups").unwrap().expect_json_number().to_int(),
content="2",
)
inspect(rotation_obj.get("max_bytes_i64") is None, content="true")
@@ -21,9 +21,9 @@ test "file state json helpers stringify stable snapshots" {
let wide_rotation_json = file_rotation_config_to_json(
file_rotation_i64(4294967296L, max_backups=2),
)
let wide_rotation_obj = wide_rotation_json.as_object().unwrap()
let wide_rotation_obj = wide_rotation_json.expect_json_object()
inspect(
wide_rotation_obj.get("max_bytes_i64").unwrap().as_string().unwrap(),
wide_rotation_obj.get("max_bytes_i64").unwrap().expect_json_string(),
content="4294967296",
)
@@ -40,51 +40,50 @@ test "file state json helpers stringify stable snapshots" {
rotation_failures=4,
),
)
let plain_obj = plain.as_object().unwrap()
let plain_obj = plain.expect_json_object()
let plain_rotation_obj = plain_obj
.get("rotation")
.unwrap()
.as_object()
.unwrap()
.expect_json_object()
inspect(
@json_parser.stringify(plain),
plain.stringify(),
content="{\"path\":\"logs/demo.log\",\"available\":true,\"append\":false,\"auto_flush\":true,\"open_failures\":1,\"write_failures\":2,\"flush_failures\":3,\"rotation_failures\":4,\"rotation\":{\"max_bytes\":64,\"max_backups\":2}}",
)
inspect(
plain_obj.get("path").unwrap().as_string().unwrap(),
plain_obj.get("path").unwrap().expect_json_string(),
content="logs/demo.log",
)
inspect(
plain_obj.get("available").unwrap().as_bool().unwrap(),
plain_obj.get("available").unwrap().expect_json_bool(),
content="true",
)
inspect(plain_obj.get("append").unwrap().as_bool().unwrap(), content="false")
inspect(plain_obj.get("append").unwrap().expect_json_bool(), content="false")
inspect(
plain_obj.get("auto_flush").unwrap().as_bool().unwrap(),
plain_obj.get("auto_flush").unwrap().expect_json_bool(),
content="true",
)
inspect(
plain_obj.get("open_failures").unwrap().as_number().unwrap().to_int(),
plain_obj.get("open_failures").unwrap().expect_json_number().to_int(),
content="1",
)
inspect(
plain_obj.get("write_failures").unwrap().as_number().unwrap().to_int(),
plain_obj.get("write_failures").unwrap().expect_json_number().to_int(),
content="2",
)
inspect(
plain_obj.get("flush_failures").unwrap().as_number().unwrap().to_int(),
plain_obj.get("flush_failures").unwrap().expect_json_number().to_int(),
content="3",
)
inspect(
plain_obj.get("rotation_failures").unwrap().as_number().unwrap().to_int(),
plain_obj.get("rotation_failures").unwrap().expect_json_number().to_int(),
content="4",
)
inspect(
plain_rotation_obj.get("max_bytes").unwrap().as_number().unwrap().to_int(),
plain_rotation_obj.get("max_bytes").unwrap().expect_json_number().to_int(),
content="64",
)
inspect(
plain_rotation_obj.get("max_backups").unwrap().as_number().unwrap().to_int(),
plain_rotation_obj.get("max_backups").unwrap().expect_json_number().to_int(),
content="2",
)
@@ -101,18 +100,16 @@ test "file state json helpers stringify stable snapshots" {
rotation_failures=0,
),
)
let wide_obj = wide.as_object().unwrap()
let wide_obj = wide.expect_json_object()
let wide_state_rotation_obj = wide_obj
.get("rotation")
.unwrap()
.as_object()
.unwrap()
.expect_json_object()
inspect(
wide_state_rotation_obj
.get("max_bytes")
.unwrap()
.as_number()
.unwrap()
.expect_json_number()
.to_int(),
content="2147483647",
)
@@ -120,13 +117,12 @@ test "file state json helpers stringify stable snapshots" {
wide_state_rotation_obj
.get("max_backups")
.unwrap()
.as_number()
.unwrap()
.expect_json_number()
.to_int(),
content="3",
)
inspect(
wide_state_rotation_obj.get("max_bytes_i64").unwrap().as_string().unwrap(),
wide_state_rotation_obj.get("max_bytes_i64").unwrap().expect_json_string(),
content="4294967296",
)
inspect(
@@ -167,27 +163,27 @@ test "runtime file state json helpers stringify queue snapshots" {
dropped_count=5,
),
)
let runtime_obj = runtime_json.as_object().unwrap()
let runtime_file_obj = runtime_obj.get("file").unwrap().as_object().unwrap()
inspect(runtime_obj.get("queued").unwrap().as_bool().unwrap(), content="true")
let runtime_obj = runtime_json.expect_json_object()
let runtime_file_obj = runtime_obj.get("file").unwrap().expect_json_object()
inspect(runtime_obj.get("queued").unwrap().expect_json_bool(), content="true")
inspect(
runtime_obj.get("pending_count").unwrap().as_number().unwrap().to_int(),
runtime_obj.get("pending_count").unwrap().expect_json_number().to_int(),
content="7",
)
inspect(
runtime_obj.get("dropped_count").unwrap().as_number().unwrap().to_int(),
runtime_obj.get("dropped_count").unwrap().expect_json_number().to_int(),
content="5",
)
inspect(
runtime_file_obj.get("path").unwrap().as_string().unwrap(),
runtime_file_obj.get("path").unwrap().expect_json_string(),
content="logs/queue.log",
)
inspect(
runtime_file_obj.get("available").unwrap().as_bool().unwrap(),
runtime_file_obj.get("available").unwrap().expect_json_bool(),
content="true",
)
inspect(
runtime_file_obj.get("rotation").unwrap() is @json_parser.JsonValue::Null,
runtime_file_obj.get("rotation").unwrap() is Json::Null,
content="true",
)
@@ -232,23 +228,20 @@ test "runtime file state json helpers stringify queue snapshots" {
dropped_count=0,
),
)
let wide_runtime_obj = wide_runtime_json.as_object().unwrap()
let wide_runtime_obj = wide_runtime_json.expect_json_object()
let wide_runtime_file_obj = wide_runtime_obj
.get("file")
.unwrap()
.as_object()
.unwrap()
.expect_json_object()
let wide_runtime_rotation_obj = wide_runtime_file_obj
.get("rotation")
.unwrap()
.as_object()
.unwrap()
.expect_json_object()
inspect(
wide_runtime_rotation_obj
.get("max_bytes")
.unwrap()
.as_number()
.unwrap()
.expect_json_number()
.to_int(),
content="2147483647",
)
@@ -256,13 +249,12 @@ test "runtime file state json helpers stringify queue snapshots" {
wide_runtime_rotation_obj
.get("max_backups")
.unwrap()
.as_number()
.unwrap()
.expect_json_number()
.to_int(),
content="2",
)
inspect(
wide_runtime_rotation_obj.get("max_bytes_i64").unwrap().as_string().unwrap(),
wide_runtime_rotation_obj.get("max_bytes_i64").unwrap().expect_json_string(),
content="4294967296",
)
}
@@ -276,31 +268,29 @@ test "file sink policy json helpers stringify stable policies" {
rotation=Some(file_rotation(96, max_backups=3)),
),
)
let policy_obj = policy_json.as_object().unwrap()
let policy_obj = policy_json.expect_json_object()
let policy_rotation_obj = policy_obj
.get("rotation")
.unwrap()
.as_object()
.unwrap()
.expect_json_object()
inspect(
@json_parser.stringify(policy_json),
policy_json.stringify(),
content="{\"append\":false,\"auto_flush\":true,\"rotation\":{\"max_bytes\":96,\"max_backups\":3}}",
)
inspect(policy_obj.get("append").unwrap().as_bool().unwrap(), content="false")
inspect(policy_obj.get("append").unwrap().expect_json_bool(), content="false")
inspect(
policy_obj.get("auto_flush").unwrap().as_bool().unwrap(),
policy_obj.get("auto_flush").unwrap().expect_json_bool(),
content="true",
)
inspect(
policy_rotation_obj.get("max_bytes").unwrap().as_number().unwrap().to_int(),
policy_rotation_obj.get("max_bytes").unwrap().expect_json_number().to_int(),
content="96",
)
inspect(
policy_rotation_obj
.get("max_backups")
.unwrap()
.as_number()
.unwrap()
.expect_json_number()
.to_int(),
content="3",
)
@@ -312,18 +302,16 @@ test "file sink policy json helpers stringify stable policies" {
rotation=Some(file_rotation_i64(4294967296L, max_backups=4)),
),
)
let wide_policy_obj = wide_policy_json.as_object().unwrap()
let wide_policy_obj = wide_policy_json.expect_json_object()
let wide_policy_rotation_obj = wide_policy_obj
.get("rotation")
.unwrap()
.as_object()
.unwrap()
.expect_json_object()
inspect(
wide_policy_rotation_obj
.get("max_bytes")
.unwrap()
.as_number()
.unwrap()
.expect_json_number()
.to_int(),
content="2147483647",
)
@@ -331,13 +319,12 @@ test "file sink policy json helpers stringify stable policies" {
wide_policy_rotation_obj
.get("max_backups")
.unwrap()
.as_number()
.unwrap()
.expect_json_number()
.to_int(),
content="4",
)
inspect(
wide_policy_rotation_obj.get("max_bytes_i64").unwrap().as_string().unwrap(),
wide_policy_rotation_obj.get("max_bytes_i64").unwrap().expect_json_string(),
content="4294967296",
)
inspect(
+1 -3
View File
@@ -8,9 +8,7 @@ pub type RuntimeFileState = @file_model.RuntimeFileState
pub type RuntimeSinkProgress = @runtime.RuntimeSinkProgress
///|
pub fn runtime_file_state_to_json(
state : RuntimeFileState,
) -> @json_parser.JsonValue {
pub fn runtime_file_state_to_json(state : RuntimeFileState) -> Json {
@file_model.runtime_file_state_to_json(state)
}
+2 -4
View File
@@ -29,9 +29,7 @@ pub fn native_files_supported() -> Bool {
}
///|
pub fn file_sink_policy_to_json(
policy : FileSinkPolicy,
) -> @json_parser.JsonValue {
pub fn file_sink_policy_to_json(policy : FileSinkPolicy) -> Json {
@file_model.file_sink_policy_to_json(policy)
}
@@ -44,7 +42,7 @@ pub fn stringify_file_sink_policy(
}
///|
pub fn file_sink_state_to_json(state : FileSinkState) -> @json_parser.JsonValue {
pub fn file_sink_state_to_json(state : FileSinkState) -> Json {
@file_model.file_sink_state_to_json(state)
}