mirror of
https://github.com/tstack/lnav.git
synced 2024-09-11 13:05:51 +03:00
parent
8c086c06ae
commit
1bb17a0b96
@ -29,6 +29,8 @@
|
||||
* @file logfile_sub_source.hh
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sqlite3.h>
|
||||
@ -39,6 +41,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "log_format.hh"
|
||||
|
||||
extern "C" {
|
||||
#include "strnatcmp.h"
|
||||
}
|
||||
@ -153,6 +157,15 @@ int sql_strnatcasecmp(void *ptr,
|
||||
return strnatcasecmp(a_len, (char *)a_in, b_len, (char *)b_in);
|
||||
}
|
||||
|
||||
static
|
||||
int sql_loglevelcmp(void *ptr,
|
||||
int a_len, const void *a_in,
|
||||
int b_len, const void *b_in)
|
||||
{
|
||||
return logline::levelcmp((const char *)a_in, a_len,
|
||||
(const char *)b_in, b_len);
|
||||
}
|
||||
|
||||
int register_collation_functions(sqlite3 *db)
|
||||
{
|
||||
sqlite3_create_collation(db, "ipaddress", SQLITE_UTF8, NULL, ipaddress);
|
||||
@ -160,6 +173,8 @@ int register_collation_functions(sqlite3 *db)
|
||||
sql_strnatcmp);
|
||||
sqlite3_create_collation(db, "naturalnocase", SQLITE_UTF8, NULL,
|
||||
sql_strnatcasecmp);
|
||||
sqlite3_create_collation(db, "loglevel", SQLITE_UTF8, NULL,
|
||||
sql_loglevelcmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -123,6 +123,41 @@ logline::level_t logline::string2level(const char *levelstr, size_t len, bool ex
|
||||
return retval;
|
||||
}
|
||||
|
||||
logline::level_t logline::abbrev2level(const char *levelstr, size_t len)
|
||||
{
|
||||
if (len == -1) {
|
||||
len = strlen(levelstr);
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
return LEVEL_UNKNOWN;
|
||||
}
|
||||
|
||||
switch (toupper(levelstr[0])) {
|
||||
case 'T':
|
||||
return LEVEL_TRACE;
|
||||
case 'D':
|
||||
return LEVEL_DEBUG;
|
||||
case 'I':
|
||||
return LEVEL_INFO;
|
||||
case 'W':
|
||||
return LEVEL_WARNING;
|
||||
case 'E':
|
||||
return LEVEL_ERROR;
|
||||
case 'C':
|
||||
return LEVEL_CRITICAL;
|
||||
case 'F':
|
||||
return LEVEL_FATAL;
|
||||
}
|
||||
|
||||
return LEVEL_UNKNOWN;
|
||||
}
|
||||
|
||||
int logline::levelcmp(const char *l1, size_t l1_len, const char *l2, size_t l2_len)
|
||||
{
|
||||
return abbrev2level(l1, l1_len) - abbrev2level(l2, l2_len);
|
||||
}
|
||||
|
||||
const char *logline_value::value_names[VALUE__MAX] = {
|
||||
"null",
|
||||
"text",
|
||||
|
@ -130,6 +130,11 @@ public:
|
||||
|
||||
static level_t string2level(const char *levelstr, size_t len = -1, bool exact = false);
|
||||
|
||||
static level_t abbrev2level(const char *levelstr, size_t len = -1);
|
||||
|
||||
static int levelcmp(const char *l1, size_t l1_len,
|
||||
const char *l2, size_t l2_len);
|
||||
|
||||
/**
|
||||
* Construct a logline object with the given values.
|
||||
*
|
||||
|
@ -69,7 +69,7 @@ static string declare_table_statement(log_vtab_impl *vi)
|
||||
<< " log_part text collate naturalnocase,\n"
|
||||
<< " log_time datetime,\n"
|
||||
<< " log_idle_msecs int,\n"
|
||||
<< " log_level text,\n";
|
||||
<< " log_level text collate loglevel,\n";
|
||||
vi->get_columns(cols);
|
||||
vi->vi_column_count = cols.size();
|
||||
for (iter = cols.begin(); iter != cols.end(); iter++) {
|
||||
|
@ -63,3 +63,25 @@ check_output "" <<EOF
|
||||
Row 0:
|
||||
Column 'file10.txt' < 'file2.txt' collate naturalcase: 0
|
||||
EOF
|
||||
|
||||
|
||||
run_test ./drive_sql "select 'w' < 'e' collate loglevel"
|
||||
|
||||
check_output "" <<EOF
|
||||
Row 0:
|
||||
Column 'w' < 'e' collate loglevel: 1
|
||||
EOF
|
||||
|
||||
run_test ./drive_sql "select 'e' < 'w' collate loglevel"
|
||||
|
||||
check_output "" <<EOF
|
||||
Row 0:
|
||||
Column 'e' < 'w' collate loglevel: 0
|
||||
EOF
|
||||
|
||||
run_test ./drive_sql "select 'info' collate loglevel between 'trace' and 'fatal'"
|
||||
|
||||
check_output "" <<EOF
|
||||
Row 0:
|
||||
Column 'info' collate loglevel between 'trace' and 'fatal': 1
|
||||
EOF
|
||||
|
Loading…
Reference in New Issue
Block a user