mirror of https://github.com/tstack/lnav.git
[nits] minor fixes
This commit is contained in:
parent
1627698168
commit
094b45f7ca
|
@ -62,11 +62,14 @@ static void extract_metadata(string_fragment, struct script_metadata& meta_out);
|
||||||
using log_formats_map_t
|
using log_formats_map_t
|
||||||
= std::map<intern_string_t, std::shared_ptr<external_log_format>>;
|
= std::map<intern_string_t, std::shared_ptr<external_log_format>>;
|
||||||
|
|
||||||
|
using namespace lnav::roles::literals;
|
||||||
|
|
||||||
static auto intern_lifetime = intern_string::get_table_lifetime();
|
static auto intern_lifetime = intern_string::get_table_lifetime();
|
||||||
static log_formats_map_t LOG_FORMATS;
|
static log_formats_map_t LOG_FORMATS;
|
||||||
|
|
||||||
struct loader_userdata {
|
struct loader_userdata {
|
||||||
yajlpp_parse_context* ud_parse_context{nullptr};
|
yajlpp_parse_context* ud_parse_context{nullptr};
|
||||||
|
std::string ud_file_schema;
|
||||||
ghc::filesystem::path ud_format_path;
|
ghc::filesystem::path ud_format_path;
|
||||||
std::vector<intern_string_t>* ud_format_names{nullptr};
|
std::vector<intern_string_t>* ud_format_names{nullptr};
|
||||||
std::vector<lnav::console::user_message>* ud_errors{nullptr};
|
std::vector<lnav::console::user_message>* ud_errors{nullptr};
|
||||||
|
@ -932,11 +935,11 @@ struct json_path_container format_handlers = {
|
||||||
static int
|
static int
|
||||||
read_id(yajlpp_parse_context* ypc, const unsigned char* str, size_t len)
|
read_id(yajlpp_parse_context* ypc, const unsigned char* str, size_t len)
|
||||||
{
|
{
|
||||||
|
auto* ud = static_cast<loader_userdata*>(ypc->ypc_userdata);
|
||||||
auto file_id = std::string((const char*) str, len);
|
auto file_id = std::string((const char*) str, len);
|
||||||
|
|
||||||
if (find(SUPPORTED_FORMAT_SCHEMAS.begin(),
|
ud->ud_file_schema = file_id;
|
||||||
SUPPORTED_FORMAT_SCHEMAS.end(),
|
if (SUPPORTED_FORMAT_SCHEMAS.find(file_id)
|
||||||
file_id)
|
|
||||||
== SUPPORTED_FORMAT_SCHEMAS.end())
|
== SUPPORTED_FORMAT_SCHEMAS.end())
|
||||||
{
|
{
|
||||||
const auto* handler = ypc->ypc_current_handler;
|
const auto* handler = ypc->ypc_current_handler;
|
||||||
|
@ -959,20 +962,17 @@ read_id(yajlpp_parse_context* ypc, const unsigned char* str, size_t len)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct json_path_container root_format_handler
|
struct json_path_container root_format_handler = json_path_container{
|
||||||
= json_path_container{
|
json_path_handler("$schema", read_id)
|
||||||
json_path_handler("$schema", read_id)
|
.with_synopsis("The URI of the schema for this file")
|
||||||
.with_synopsis("The URI of the schema for this file")
|
.with_description("Specifies the type of this file"),
|
||||||
.with_description("Specifies the type of this file"),
|
|
||||||
|
|
||||||
yajlpp::pattern_property_handler(
|
yajlpp::pattern_property_handler("(?<format_name>\\w+)")
|
||||||
"(?<format_name>\\w+)")
|
.with_description("The definition of a log file format.")
|
||||||
.with_description(
|
.with_obj_provider(ensure_format)
|
||||||
"The definition of a log file format.")
|
.with_children(format_handlers),
|
||||||
.with_obj_provider(ensure_format)
|
}
|
||||||
.with_children(format_handlers),
|
.with_schema_id(DEFAULT_FORMAT_SCHEMA);
|
||||||
}
|
|
||||||
.with_schema_id(DEFAULT_FORMAT_SCHEMA);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
write_sample_file()
|
write_sample_file()
|
||||||
|
@ -1112,6 +1112,30 @@ load_format_file(const ghc::filesystem::path& filename,
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
ypc.complete_parse();
|
ypc.complete_parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ud.ud_file_schema.empty()) {
|
||||||
|
static const auto SCHEMA_LINE
|
||||||
|
= attr_line_t()
|
||||||
|
.append(
|
||||||
|
fmt::format(FMT_STRING(" \"$schema\": \"{}\","),
|
||||||
|
*SUPPORTED_FORMAT_SCHEMAS.begin()))
|
||||||
|
.with_attr_for_all(
|
||||||
|
VC_ROLE.value(role_t::VCR_QUOTED_CODE));
|
||||||
|
|
||||||
|
errors.emplace_back(
|
||||||
|
lnav::console::user_message::warning(
|
||||||
|
attr_line_t("format file is missing ")
|
||||||
|
.append_quoted("$schema"_symbol)
|
||||||
|
.append(" property"))
|
||||||
|
.with_snippet(lnav::console::snippet::from(
|
||||||
|
intern_string::lookup(filename.string()), ""))
|
||||||
|
.with_note("the schema specifies the supported format "
|
||||||
|
"version and can be used with editors to "
|
||||||
|
"automatically validate the file")
|
||||||
|
.with_help(attr_line_t("add the following property to the "
|
||||||
|
"top-level JSON object:\n")
|
||||||
|
.append(SCHEMA_LINE)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
|
|
@ -606,7 +606,7 @@ logfile::rebuild_index(nonstd::optional<ui_clock::time_point> deadline)
|
||||||
auto sbr = read_result.unwrap();
|
auto sbr = read_result.unwrap();
|
||||||
sbr.rtrim(is_line_ending);
|
sbr.rtrim(is_line_ending);
|
||||||
|
|
||||||
if (li.li_has_ansi) {
|
if (li.li_valid_utf && li.li_has_ansi) {
|
||||||
auto tmp_line = sbr.to_string_fragment().to_string();
|
auto tmp_line = sbr.to_string_fragment().to_string();
|
||||||
|
|
||||||
scrub_ansi_string(tmp_line, nullptr);
|
scrub_ansi_string(tmp_line, nullptr);
|
||||||
|
|
|
@ -55,6 +55,11 @@
|
||||||
[1m/bad_regex_log/highlights/foobar/pattern[0m [4m<regex>[0m
|
[1m/bad_regex_log/highlights/foobar/pattern[0m [4m<regex>[0m
|
||||||
[1mDescription[0m
|
[1mDescription[0m
|
||||||
A regular expression to highlight in logs of this format.
|
A regular expression to highlight in logs of this format.
|
||||||
|
[33m⚠ warning[0m: format file is missing “[1m$schema[0m” property
|
||||||
|
[36m --> [0m[1m{test_dir}/bad-config/formats/invalid-regex/format.json[0m
|
||||||
|
[36m =[0m [36mnote[0m: the schema specifies the supported format version and can be used with editors to automatically validate the file
|
||||||
|
[36m =[0m [36mhelp[0m: add the following property to the top-level JSON object:
|
||||||
|
[37m[40m "$schema": "https://lnav.org/schemas/format-v1.schema.json",[0m
|
||||||
[1m[31m✘ error[0m: “foo” is not a valid value for option “[1m/bad_sample_log/value/pid/kind[0m”
|
[1m[31m✘ error[0m: “foo” is not a valid value for option “[1m/bad_sample_log/value/pid/kind[0m”
|
||||||
[36m --> [0m[1m{test_dir}/bad-config/formats/invalid-sample/format.json[0m:24
|
[36m --> [0m[1m{test_dir}/bad-config/formats/invalid-sample/format.json[0m:24
|
||||||
[36m | [0m[37m[40m "kind": "foo" [0m
|
[36m | [0m[37m[40m "kind": "foo" [0m
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
[36m | [0m ar_log": { "abc" } }
|
[36m | [0m ar_log": { "abc" } }
|
||||||
[36m | [0m (right here) ------^
|
[36m | [0m (right here) ------^
|
||||||
[36m | [0m
|
[36m | [0m
|
||||||
|
[33m⚠ warning[0m: format file is missing “[1m$schema[0m” property
|
||||||
|
[36m --> [0m[1m{test_dir}/bad-config-json/formats/invalid-json/format.json[0m
|
||||||
|
[36m =[0m [36mnote[0m: the schema specifies the supported format version and can be used with editors to automatically validate the file
|
||||||
|
[36m =[0m [36mhelp[0m: add the following property to the top-level JSON object:
|
||||||
|
[37m[40m "$schema": "https://lnav.org/schemas/format-v1.schema.json",[0m
|
||||||
[1m[31m✘ error[0m: “abc(” is not a valid regular expression
|
[1m[31m✘ error[0m: “abc(” is not a valid regular expression
|
||||||
[1m[31mreason[0m: missing closing parenthesis
|
[1m[31mreason[0m: missing closing parenthesis
|
||||||
[36m --> [0m[1m/invalid_key_log/level-pointer[0m
|
[36m --> [0m[1m/invalid_key_log/level-pointer[0m
|
||||||
|
|
Loading…
Reference in New Issue