[cleanup] some modernization

This commit is contained in:
Timothy Stack 2019-05-21 22:14:36 -07:00
parent 6cf5cc8213
commit 0918063640
18 changed files with 239 additions and 152 deletions

View File

@ -111,6 +111,7 @@ set(diag_STAT_SRCS
curl_looper.hh
doc_status_source.hh
elem_to_json.hh
base/enum_util.hh
field_overlay_source.hh
file_vtab.hh
filter_observer.hh

View File

@ -1,8 +1,14 @@
AM_CPPFLAGS = \
-Wall \
-I$(top_srcdir)/src/
noinst_LIBRARIES = libbase.a
noinst_HEADERS = \
enum_util.hh \
lnav_log.hh \
opt_util.hh \
pthreadpp.hh
libbase_a_SOURCES = \

41
src/base/enum_util.hh Normal file
View File

@ -0,0 +1,41 @@
/**
* Copyright (c) 2019, Timothy Stack
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Timothy Stack nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lnav_enum_util_hh
#define lnav_enum_util_hh
#include <type_traits>
template <typename E>
constexpr auto to_underlying(E e) noexcept
{
return static_cast<std::underlying_type_t<E>>(e);
}
#endif

View File

@ -78,6 +78,7 @@
#include "lnav_log.hh"
#include "pthreadpp.hh"
#include "enum_util.hh"
static const size_t BUFFER_SIZE = 256 * 1024;
static const size_t MAX_LOG_LINE_SIZE = 2048;
@ -92,10 +93,10 @@ static const char *CRASH_MSG =
" %s\n"
"=========================\n";
FILE *lnav_log_file;
lnav_log_level_t lnav_log_level = LOG_LEVEL_DEBUG;
nonstd::optional<FILE *> lnav_log_file;
lnav_log_level_t lnav_log_level = lnav_log_level_t::DEBUG;
const char *lnav_log_crash_dir;
const struct termios *lnav_log_orig_termios;
nonstd::optional<const struct termios *> lnav_log_orig_termios;
static pthread_mutex_t lnav_log_mutex = PTHREAD_MUTEX_INITIALIZER;
log_state_dumper::log_state_list log_state_dumper::DUMPER_LIST;
@ -140,7 +141,7 @@ static char *log_alloc()
new_start = (const char *)memchr(
new_start, '\n', log_ring.lr_frag_end - log_ring.lr_frag_start);
assert(new_start != NULL);
assert(new_start != nullptr);
log_ring.lr_frag_start = new_start - log_ring.lr_data;
assert(log_ring.lr_frag_start >= 0);
assert(log_ring.lr_frag_start <= (off_t)BUFFER_SIZE);
@ -153,7 +154,7 @@ void log_argv(int argc, char *argv[])
{
const char *log_path = getenv("LNAV_LOG_PATH");
if (log_path != NULL) {
if (log_path != nullptr) {
lnav_log_file = fopen(log_path, "a");
}
@ -190,7 +191,7 @@ void log_host_info()
log_info(" gid=%d", getgid());
log_info(" euid=%d", geteuid());
log_info(" egid=%d", getegid());
if (getcwd(cwd, sizeof(cwd)) == NULL) {
if (getcwd(cwd, sizeof(cwd)) == nullptr) {
log_info(" ERROR: getcwd failed");
}
else {
@ -200,7 +201,7 @@ void log_host_info()
log_info(" version=%s", VCS_PACKAGE_STRING);
getrusage(RUSAGE_SELF, &ru);
log_rusage(LOG_LEVEL_INFO, ru);
log_rusage(lnav_log_level_t::INFO, ru);
}
void log_rusage_raw(enum lnav_log_level_t level, const char *src_file, int line_number, const struct rusage &ru)
@ -233,7 +234,6 @@ void log_msg(lnav_log_level_t level, const char *src_file, int line_number,
struct tm localtm;
ssize_t prefix_size;
va_list args;
char *line;
ssize_t rc;
if (level < lnav_log_level) {
@ -243,9 +243,9 @@ void log_msg(lnav_log_level_t level, const char *src_file, int line_number,
mutex_guard mg(lnav_log_mutex);
va_start(args, fmt);
gettimeofday(&curr_time, NULL);
gettimeofday(&curr_time, nullptr);
localtime_r(&curr_time.tv_sec, &localtm);
line = log_alloc();
auto line = log_alloc();
prefix_size = snprintf(
line, MAX_LOG_LINE_SIZE,
"%4d-%02d-%02dT%02d:%02d:%02d.%03d %s %s:%d ",
@ -256,7 +256,7 @@ void log_msg(lnav_log_level_t level, const char *src_file, int line_number,
localtm.tm_min,
localtm.tm_sec,
(int)(curr_time.tv_usec / 1000),
LEVEL_NAMES[level],
LEVEL_NAMES[to_underlying(level)],
basename((char *)src_file),
line_number);
rc = vsnprintf(&line[prefix_size], MAX_LOG_LINE_SIZE - prefix_size,
@ -266,45 +266,39 @@ void log_msg(lnav_log_level_t level, const char *src_file, int line_number,
}
line[prefix_size + rc] = '\n';
log_ring.lr_length += prefix_size + rc + 1;
if (lnav_log_file != nullptr) {
fwrite(line, 1, prefix_size + rc + 1, lnav_log_file);
fflush(lnav_log_file);
}
lnav_log_file | [&](auto file) {
fwrite(line, 1, prefix_size + rc + 1, file);
fflush(file);
};
va_end(args);
}
void log_msg_extra(const char *fmt, ...)
{
va_list args;
ssize_t rc;
char *line;
mutex_guard mg(lnav_log_mutex);
va_list args;
va_start(args, fmt);
line = log_alloc();
rc = vsnprintf(line, MAX_LOG_LINE_SIZE - 1, fmt, args);
auto line = log_alloc();
auto rc = vsnprintf(line, MAX_LOG_LINE_SIZE - 1, fmt, args);
log_ring.lr_length += rc;
if (lnav_log_file != nullptr) {
fwrite(line, 1, rc, lnav_log_file);
fflush(lnav_log_file);
}
lnav_log_file | [&](auto file) {
fwrite(line, 1, rc, file);
fflush(file);
};
va_end(args);
}
void log_msg_extra_complete()
{
char *line;
mutex_guard mg(lnav_log_mutex);
line = log_alloc();
auto line = log_alloc();
line[0] = '\n';
log_ring.lr_length += 1;
if (lnav_log_file != nullptr) {
fwrite(line, 1, 1, lnav_log_file);
fflush(lnav_log_file);
}
lnav_log_file | [&](auto file) {
fwrite(line, 1, 1, file);
fflush(file);
};
}
#pragma GCC diagnostic push
@ -360,7 +354,7 @@ static void sigabrt(int sig)
log_state_dumper *lsd;
for (lsd = LIST_FIRST(&log_state_dumper::DUMPER_LIST.lsl_list);
lsd != NULL;
lsd != nullptr;
lsd = LIST_NEXT(lsd, lsd_link)) {
lsd->log_state();
}
@ -377,20 +371,20 @@ static void sigabrt(int sig)
symlink(crash_path, latest_crash_path);
}
if (lnav_log_orig_termios != NULL) {
lnav_log_orig_termios | [](auto termios) {
{
log_crash_recoverer *lcr;
for (lcr = LIST_FIRST(&log_crash_recoverer::CRASH_LIST.lcl_list);
lcr != NULL;
lcr != nullptr;
lcr = LIST_NEXT(lcr, lcr_link)) {
lcr->log_crash_recover();
}
}
tcsetattr(STDOUT_FILENO, TCSAFLUSH, lnav_log_orig_termios);
tcsetattr(STDOUT_FILENO, TCSAFLUSH, termios);
dup2(STDOUT_FILENO, STDERR_FILENO);
}
};
fprintf(stderr, CRASH_MSG, crash_path);
#ifndef ATTACH_ON_SIGNAL
@ -409,11 +403,11 @@ static void sigabrt(int sig)
char pid_str[32];
snprintf(pid_str, sizeof(pid_str), "--pid=%d", lnav_pid);
execlp("gdb", "gdb", pid_str, NULL);
execlp("gdb", "gdb", pid_str, nullptr);
snprintf(pid_str, sizeof(pid_str),
"--attach-pid=%d", lnav_pid);
execlp("lldb", "lldb", pid_str, NULL);
execlp("lldb", "lldb", pid_str, nullptr);
fprintf(stderr, "Could not attach gdb or lldb, exiting.\n");
_exit(1);

View File

@ -29,8 +29,8 @@
* @file lnav_log.hh
*/
#ifndef __lnav_log_hh
#define __lnav_log_hh
#ifndef lnav_log_hh
#define lnav_log_hh
#include <errno.h>
#include <stdio.h>
@ -44,12 +44,14 @@
#define __dead2 __attribute__((noreturn))
#endif
enum lnav_log_level_t {
LOG_LEVEL_TRACE,
LOG_LEVEL_DEBUG,
LOG_LEVEL_INFO,
LOG_LEVEL_WARNING,
LOG_LEVEL_ERROR,
#include "opt_util.hh"
enum class lnav_log_level_t : uint32_t {
TRACE,
DEBUG,
INFO,
WARNING,
ERROR,
};
void log_argv(int argc, char *argv[]);
@ -115,9 +117,9 @@ public:
LIST_ENTRY(log_crash_recoverer) lcr_link;
};
extern FILE *lnav_log_file;
extern nonstd::optional<FILE *> lnav_log_file;
extern const char *lnav_log_crash_dir;
extern const struct termios *lnav_log_orig_termios;
extern nonstd::optional<const struct termios *> lnav_log_orig_termios;
extern enum lnav_log_level_t lnav_log_level;
#define log_msg_wrapper(level, fmt...) \
@ -132,33 +134,33 @@ extern enum lnav_log_level_t lnav_log_level;
log_rusage_raw(level, __FILE__, __LINE__, ru);
#define log_error(fmt...) \
log_msg_wrapper(LOG_LEVEL_ERROR, fmt);
log_msg_wrapper(lnav_log_level_t::ERROR, fmt);
#define log_warning(fmt...) \
log_msg_wrapper(LOG_LEVEL_WARNING, fmt);
log_msg_wrapper(lnav_log_level_t::WARNING, fmt);
#define log_info(fmt...) \
log_msg_wrapper(LOG_LEVEL_INFO, fmt);
log_msg_wrapper(lnav_log_level_t::INFO, fmt);
#define log_debug(fmt...) \
log_msg_wrapper(LOG_LEVEL_DEBUG, fmt);
log_msg_wrapper(lnav_log_level_t::DEBUG, fmt);
#define log_trace(fmt...) \
log_msg_wrapper(LOG_LEVEL_TRACE, fmt);
log_msg_wrapper(lnav_log_level_t::TRACE, fmt);
#define require(e) \
((void) ((e) ? 0 : __require (#e, __FILE__, __LINE__)))
#define __require(e, file, line) \
(log_msg(LOG_LEVEL_ERROR, file, line, "failed precondition `%s'", e), log_abort(), 1)
(log_msg(lnav_log_level_t::ERROR, file, line, "failed precondition `%s'", e), log_abort(), 1)
#define ensure(e) \
((void) ((e) ? 0 : __ensure (#e, __FILE__, __LINE__)))
#define __ensure(e, file, line) \
(log_msg(LOG_LEVEL_ERROR, file, line, "failed postcondition `%s'", e), log_abort(), 1)
(log_msg(lnav_log_level_t::ERROR, file, line, "failed postcondition `%s'", e), log_abort(), 1)
#define log_perror(e) \
((void) ((e != -1) ? 0 : __log_perror (#e, __FILE__, __LINE__)))
#define __log_perror(e, file, line) \
(log_msg(LOG_LEVEL_ERROR, file, line, "syscall failed `%s' -- %s", e, strerror(errno)), 1)
(log_msg(lnav_log_level_t::ERROR, file, line, "syscall failed `%s' -- %s", e, strerror(errno)), 1)
#endif

65
src/base/opt_util.hh Normal file
View File

@ -0,0 +1,65 @@
/**
* Copyright (c) 2019, Timothy Stack
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Timothy Stack nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lnav_opt_util_hh
#define lnav_opt_util_hh
#include "optional.hpp"
namespace detail {
template <class T>
typename std::enable_if<std::is_void<T>::value, T>::type
void_or_nullopt()
{
return;
}
template <class T>
typename std::enable_if<not std::is_void<T>::value, T>::type
void_or_nullopt()
{
return nonstd::nullopt;
}
template <class T>
struct is_optional : std::false_type {};
template <class T>
struct is_optional<nonstd::optional<T>> : std::true_type {};
}
template <class T, class F, std::enable_if_t<detail::is_optional<std::decay_t<T>>::value, int> = 0>
auto operator|(T&& t, F f) -> decltype(detail::void_or_nullopt<decltype(f(std::forward<T>(t).operator*()))>()) {
using return_type = decltype(f(std::forward<T>(t).operator*()));
if (t) return f(std::forward<T>(t).operator*());
else return detail::void_or_nullopt<return_type>();
}
#endif

View File

@ -69,7 +69,7 @@ int curl_request::debug_cb(CURL *handle,
break;
case CURLINFO_HEADER_IN:
case CURLINFO_HEADER_OUT:
if (lnav_log_level == LOG_LEVEL_TRACE) {
if (lnav_log_level == lnav_log_level_t::TRACE) {
write_to_log = true;
}
else {

View File

@ -46,6 +46,7 @@
#include "field_overlay_source.hh"
#include "hotkeys.hh"
#include "log_format_loader.hh"
#include "base/opt_util.hh"
using namespace std;
@ -881,25 +882,32 @@ void handle_paging_key(int ch)
case 'I':
{
hist_source2 &hs = lnav_data.ld_hist_source2;
auto &hs = lnav_data.ld_hist_source2;
auto &hist_tc = lnav_data.ld_views[LNV_HISTOGRAM];
if (toggle_view(&lnav_data.ld_views[LNV_HISTOGRAM])) {
struct timeval log_top = lss->time_for_row(lnav_data.ld_views[LNV_LOG].get_top());
if (toggle_view(&hist_tc)) {
auto *src_view = dynamic_cast<text_time_translator *>(tc->get_sub_source());
tc = *lnav_data.ld_view_stack.top();
tc->set_top(vis_line_t(hs.row_for_time(log_top)));
if (src_view != nullptr) {
struct timeval log_top = src_view->time_for_row(tc->get_top());
hist_tc.set_top(vis_line_t(hs.row_for_time(log_top)));
}
}
else {
textview_curses &hist_tc = lnav_data.ld_views[LNV_HISTOGRAM];
textview_curses &log_tc = lnav_data.ld_views[LNV_LOG];
lss = &lnav_data.ld_log_source;
struct timeval hist_top_time = hs.time_for_row(hist_tc.get_top());
struct timeval curr_top_time = lss->time_for_row(log_tc.get_top());
if (hs.row_for_time(hist_top_time) != hs.row_for_time(curr_top_time)) {
vis_line_t new_top = lss->find_from_time(hist_top_time);
log_tc.set_top(new_top);
log_tc.set_needs_update();
}
lnav_data.ld_view_stack.top() | [](auto top_tc) {
auto *dst_view = dynamic_cast<text_time_translator *>(top_tc->get_sub_source());
if (dst_view != nullptr) {
struct timeval hist_top_time = hs.time_for_row(hist_tc.get_top());
struct timeval curr_top_time = dst_view->time_for_row(top_tc->get_top());
if (hs.row_for_time(hist_top_time) != hs.row_for_time(curr_top_time)) {
vis_line_t new_top = vis_line_t(dst_view->row_for_time(hist_top_time));
top_tc->set_top(new_top);
top_tc->set_needs_update();
}
}
};
}
}
break;

View File

@ -50,6 +50,7 @@
#include "base/lnav_log.hh"
#include "input_dispatcher.hh"
#include "lnav_util.hh"
void input_dispatcher::new_input(const struct timeval &current_time, int ch)
{
@ -95,14 +96,21 @@ void input_dispatcher::new_input(const struct timeval &current_time, int ch)
void input_dispatcher::poll(const struct timeval &current_time)
{
if (this->id_escape_index == 1) {
static const struct timeval escape_threshold = { 0, 10000 };
struct timeval diff;
gettimeofday((struct timeval *) &current_time, nullptr);
timersub(&current_time, &this->id_escape_start_time, &diff);
if (diff.tv_sec > 0 || diff.tv_usec > (10000)) {
if (escape_threshold < diff) {
this->id_key_handler(KEY_CTRL_RBRACKET);
this->id_escape_index = 0;
}
}
}
void input_dispatcher::append_to_escape_buffer(int ch)
{
if (this->id_escape_index < (sizeof(this->id_escape_buffer) - 1)) {
this->id_escape_buffer[this->id_escape_index++] = static_cast<char>(ch);
this->id_escape_buffer[this->id_escape_index] = '\0';
}
}

View File

@ -60,10 +60,7 @@ public:
std::function<void(const char *)> id_escape_handler;
std::function<void()> id_mouse_handler;
private:
void append_to_escape_buffer(int ch) {
this->id_escape_buffer[this->id_escape_index++] = static_cast<char>(ch);
this->id_escape_buffer[this->id_escape_index] = '\0';
}
void append_to_escape_buffer(int ch);
char id_escape_buffer[32];
size_t id_escape_index{0};

View File

@ -1134,11 +1134,6 @@ private:
static void handle_key(int ch) {
lnav_data.ld_input_state.push_back(ch);
if (lnav_data.ld_mode == LNM_PAGING) {
auto top_tc = lnav_data.ld_view_stack.top();
}
switch (ch) {
case CTRL('d'):
case KEY_RESIZE:
@ -1177,7 +1172,7 @@ static input_dispatcher::escape_match_t match_escape_seq(const char *escape_buff
return input_dispatcher::escape_match_t::NONE;
}
char keyseq[32] = "";
char keyseq[32 * 3 + 1] = "";
for (size_t lpc = 0; escape_buffer[lpc]; lpc++) {
snprintf(keyseq + strlen(keyseq), sizeof(keyseq) - strlen(keyseq),
@ -1185,7 +1180,7 @@ static input_dispatcher::escape_match_t match_escape_seq(const char *escape_buff
escape_buffer[lpc]);
}
key_map &km = lnav_config.lc_ui_keymaps[lnav_config.lc_ui_keymap];
auto &km = lnav_config.lc_ui_keymaps[lnav_config.lc_ui_keymap];
auto iter = km.km_seq_to_cmd.find(keyseq);
if (iter != km.km_seq_to_cmd.end()) {
return input_dispatcher::escape_match_t::FULL;
@ -1211,7 +1206,7 @@ static input_dispatcher::escape_match_t match_escape_seq(const char *escape_buff
static void handle_escape_seq(const char *escape_buffer)
{
char keyseq[32] = "";
char keyseq[32 * 3 + 1] = "";
for (size_t lpc = 0; escape_buffer[lpc]; lpc++) {
snprintf(keyseq + strlen(keyseq), sizeof(keyseq) - strlen(keyseq),
@ -1928,7 +1923,7 @@ int main(int argc, char *argv[])
case 'd':
lnav_data.ld_debug_log_name = optarg;
lnav_log_level = LOG_LEVEL_TRACE;
lnav_log_level = lnav_log_level_t::TRACE;
break;
case 'a':

View File

@ -291,7 +291,7 @@ static void config_error_reporter(const yajlpp_parse_context &ypc,
lnav_log_level_t level,
const char *msg)
{
if (level >= LOG_LEVEL_ERROR) {
if (level >= lnav_log_level_t::ERROR) {
struct userdata *ud = (userdata *) ypc.ypc_userdata;
ud->ud_errors.emplace_back(msg);

View File

@ -493,34 +493,4 @@ inline void rusageadd(const struct rusage &left, const struct rusage &right, str
size_t abbreviate_str(char *str, size_t len, size_t max_len);
namespace detail {
template <class T>
typename std::enable_if<std::is_void<T>::value, T>::type
void_or_nullopt()
{
return;
}
template <class T>
typename std::enable_if<not std::is_void<T>::value, T>::type
void_or_nullopt()
{
return nonstd::nullopt;
}
template <class T>
struct is_optional : std::false_type {};
template <class T>
struct is_optional<nonstd::optional<T>> : std::true_type {};
}
template <class T, class F, std::enable_if_t<detail::is_optional<std::decay_t<T>>::value, int> = 0>
auto operator|(T&& t, F f) -> decltype(detail::void_or_nullopt<decltype(f(std::forward<T>(t).operator*()))>()) {
using return_type = decltype(f(std::forward<T>(t).operator*()));
if (t) return f(std::forward<T>(t).operator*());
else return detail::void_or_nullopt<return_type>();
}
#endif

View File

@ -709,7 +709,7 @@ static void format_error_reporter(const yajlpp_parse_context &ypc,
lnav_log_level_t level,
const char *msg)
{
if (level >= LOG_LEVEL_ERROR) {
if (level >= lnav_log_level_t::ERROR) {
struct userdata *ud = (userdata *) ypc.ypc_userdata;
ud->ud_errors->push_back(msg);

View File

@ -398,7 +398,7 @@ logfile::rebuild_result_t logfile::rebuild_index()
this->lf_filename.c_str(),
begin_size,
this->lf_index.size());
log_rusage(LOG_LEVEL_INFO, this->lf_activity.la_initial_index_rusage);
log_rusage(lnav_log_level_t::INFO, this->lf_activity.la_initial_index_rusage);
}
/*

View File

@ -521,20 +521,20 @@ static void sqlite_logger(void *dummy, int code, const char *msg)
switch (code) {
case SQLITE_OK:
level = LOG_LEVEL_DEBUG;
level = lnav_log_level_t::DEBUG;
break;
#ifdef SQLITE_NOTICE
case SQLITE_NOTICE:
level = LOG_LEVEL_INFO;
level = lnav_log_level_t::INFO;
break;
#endif
#ifdef SQLITE_WARNING
case SQLITE_WARNING:
level = LOG_LEVEL_WARNING;
level = lnav_log_level_t::WARNING;
break;
#endif
default:
level = LOG_LEVEL_ERROR;
level = lnav_log_level_t::ERROR;
break;
}

View File

@ -417,28 +417,28 @@ int yajlpp_parse_context::handle_unused(void *ctx)
strlen(handler->jph_description) > 0) {
ypc->report_error(
LOG_LEVEL_WARNING,
lnav_log_level_t::WARNING,
"%s:line %d",
ypc->ypc_source.c_str(),
line_number);
ypc->report_error(LOG_LEVEL_WARNING, " unexpected data for path");
ypc->report_error(lnav_log_level_t::WARNING, " unexpected data for path");
ypc->report_error(LOG_LEVEL_WARNING,
ypc->report_error(lnav_log_level_t::WARNING,
" %s %s -- %s",
&ypc->ypc_path[0],
handler->jph_synopsis,
handler->jph_description);
}
else if (ypc->ypc_path[0]) {
ypc->report_error(LOG_LEVEL_WARNING,
ypc->report_error(lnav_log_level_t::WARNING,
"%s:line %d",
ypc->ypc_source.c_str(),
line_number);
ypc->report_error(LOG_LEVEL_WARNING, " unexpected path --");
ypc->report_error(lnav_log_level_t::WARNING, " unexpected path --");
ypc->report_error(LOG_LEVEL_WARNING, " %s", &ypc->ypc_path[0]);
ypc->report_error(lnav_log_level_t::WARNING, " %s", &ypc->ypc_path[0]);
} else {
ypc->report_error(LOG_LEVEL_WARNING,
ypc->report_error(lnav_log_level_t::WARNING,
"%s:line %d\n unexpected JSON value",
ypc->ypc_source.c_str(),
line_number);
@ -448,20 +448,20 @@ int yajlpp_parse_context::handle_unused(void *ctx)
ypc->ypc_callbacks.yajl_integer != (int (*)(void *, long long))yajlpp_parse_context::handle_unused ||
ypc->ypc_callbacks.yajl_double != (int (*)(void *, double))yajlpp_parse_context::handle_unused ||
ypc->ypc_callbacks.yajl_string != (int (*)(void *, const unsigned char *, size_t))yajlpp_parse_context::handle_unused) {
ypc->report_error(LOG_LEVEL_WARNING, " expecting one of the following data types --");
ypc->report_error(lnav_log_level_t::WARNING, " expecting one of the following data types --");
}
if (ypc->ypc_callbacks.yajl_boolean != (int (*)(void *, int))yajlpp_parse_context::handle_unused) {
ypc->report_error(LOG_LEVEL_WARNING, " boolean");
ypc->report_error(lnav_log_level_t::WARNING, " boolean");
}
if (ypc->ypc_callbacks.yajl_integer != (int (*)(void *, long long))yajlpp_parse_context::handle_unused) {
ypc->report_error(LOG_LEVEL_WARNING, " integer");
ypc->report_error(lnav_log_level_t::WARNING, " integer");
}
if (ypc->ypc_callbacks.yajl_double != (int (*)(void *, double))yajlpp_parse_context::handle_unused) {
ypc->report_error(LOG_LEVEL_WARNING, " float");
ypc->report_error(lnav_log_level_t::WARNING, " float");
}
if (ypc->ypc_callbacks.yajl_string != (int (*)(void *, const unsigned char *, size_t))yajlpp_parse_context::handle_unused) {
ypc->report_error(LOG_LEVEL_WARNING, " string");
ypc->report_error(lnav_log_level_t::WARNING, " string");
}
if (handler == nullptr) {
@ -473,9 +473,9 @@ int yajlpp_parse_context::handle_unused(void *ctx)
accepted_handlers = ypc->ypc_handlers;
}
ypc->report_error(LOG_LEVEL_WARNING, " accepted paths --");
ypc->report_error(lnav_log_level_t::WARNING, " accepted paths --");
for (int lpc = 0; accepted_handlers[lpc].jph_path[0]; lpc++) {
ypc->report_error(LOG_LEVEL_WARNING, " %s %s -- %s",
ypc->report_error(lnav_log_level_t::WARNING, " %s %s -- %s",
accepted_handlers[lpc].jph_path,
accepted_handlers[lpc].jph_synopsis,
accepted_handlers[lpc].jph_description);
@ -515,7 +515,7 @@ yajlpp_parse_context::parse(const unsigned char *jsonText, size_t jsonTextLen)
if (retval != yajl_status_ok && this->ypc_error_reporter) {
this->ypc_error_reporter(
*this, LOG_LEVEL_ERROR,
*this, lnav_log_level_t::ERROR,
fmt::format("error:{}:{}:invalid json -- {}",
this->ypc_source,
this->get_line_number(),
@ -532,7 +532,7 @@ yajl_status yajlpp_parse_context::complete_parse()
if (retval != yajl_status_ok && this->ypc_error_reporter) {
this->ypc_error_reporter(
*this, LOG_LEVEL_ERROR,
*this, lnav_log_level_t::ERROR,
fmt::format("error:{}:invalid json -- {}",
this->ypc_source,
yajl_get_error(this->ypc_handle, 0,

View File

@ -209,7 +209,7 @@ struct json_path_handler : public json_path_handler_base {
if (res) {
obj->*ENUM = (ENUM_T) res.value();
} else {
ypc->report_error(LOG_LEVEL_ERROR,
ypc->report_error(lnav_log_level_t::ERROR,
"error:%s:line %d\n "
"Invalid value, '%.*s', for option:",
ypc->ypc_source.c_str(),
@ -217,17 +217,17 @@ struct json_path_handler : public json_path_handler_base {
len,
str);
ypc->report_error(LOG_LEVEL_ERROR,
ypc->report_error(lnav_log_level_t::ERROR,
" %s %s -- %s\n",
&ypc->ypc_path[0],
handler->jph_synopsis,
handler->jph_description);
ypc->report_error(LOG_LEVEL_ERROR,
ypc->report_error(lnav_log_level_t::ERROR,
" Allowed values: ");
for (int lpc = 0; handler->jph_enum_values[lpc].first; lpc++) {
const json_path_handler::enum_value_t &ev = handler->jph_enum_values[lpc];
ypc->report_error(LOG_LEVEL_ERROR, " %s\n", ev.first);
ypc->report_error(lnav_log_level_t::ERROR, " %s\n", ev.first);
}
}
@ -273,7 +273,7 @@ struct json_path_handler : public json_path_handler_base {
pcre_context_static<30> pc;
if (!jph.jph_pattern->match(pc, pi)) {
ypc.report_error(LOG_LEVEL_ERROR,
ypc.report_error(lnav_log_level_t::ERROR,
"Value does not match pattern: %s",
jph.jph_pattern_re);
}
@ -282,15 +282,15 @@ struct json_path_handler : public json_path_handler_base {
try {
jph.jph_string_validator(to_string_fragment(field_ptr));
} catch (const std::exception &e) {
ypc.report_error(LOG_LEVEL_ERROR,
ypc.report_error(lnav_log_level_t::ERROR,
"%s",
e.what());
}
}
if (field_ptr.empty() && jph.jph_min_length > 0) {
ypc.report_error(LOG_LEVEL_ERROR, "value must not be empty");
ypc.report_error(lnav_log_level_t::ERROR, "value must not be empty");
} else if (field_ptr.size() < jph.jph_min_length) {
ypc.report_error(LOG_LEVEL_ERROR, "value must be at least %lu characters long",
ypc.report_error(lnav_log_level_t::ERROR, "value must be at least %lu characters long",
jph.jph_min_length);
}
};
@ -300,7 +300,7 @@ struct json_path_handler : public json_path_handler_base {
auto &field_ptr = ypc.get_rvalue(ypc.get_obj_member<T, NUM_T, NUM>());
if (field_ptr < jph.jph_min_value) {
ypc.report_error(LOG_LEVEL_ERROR,
ypc.report_error(lnav_log_level_t::ERROR,
"value must be greater than %lld",
jph.jph_min_value);
}