• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tstack / lnav / 17589970077-2502

09 Sep 2025 05:00PM UTC coverage: 65.196% (-5.0%) from 70.225%
17589970077-2502

push

github

tstack
[format] add fields for source file/line

Knowing the source file/line context in a log
message can help find log messages when using
log2src.

56 of 70 new or added lines in 2 files covered. (80.0%)

13954 existing lines in 210 files now uncovered.

45516 of 69814 relevant lines covered (65.2%)

404154.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.66
/src/log_level.cc
1
/**
2
 * Copyright (c) 2018, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29

30
#include "log_level.hh"
31

32
#include <ctype.h>
33

34
#include "config.h"
35

36
constexpr std::array<string_fragment, LEVEL__MAX> level_names = {
37
    "unknown"_frag,
38
    "trace"_frag,
39
    "debug5"_frag,
40
    "debug4"_frag,
41
    "debug3"_frag,
42
    "debug2"_frag,
43
    "debug"_frag,
44
    "info"_frag,
45
    "stats"_frag,
46
    "notice"_frag,
47
    "warning"_frag,
48
    "error"_frag,
49
    "critical"_frag,
50
    "fatal"_frag,
51
    "invalid"_frag,
52
};
53

54
log_level_t
55
abbrev2level(const char* levelstr, ssize_t len)
2,364✔
56
{
57
    if (len == 0 || levelstr[0] == '\0') {
2,364✔
UNCOV
58
        return LEVEL_UNKNOWN;
×
59
    }
60

61
    switch (toupper(levelstr[0])) {
2,364✔
62
        case 'T':
1✔
63
            return LEVEL_TRACE;
1✔
64
        case 'D':
699✔
65
        case 'V':
66
            if (len > 1) {
699✔
67
                switch (levelstr[len - 1]) {
6✔
UNCOV
68
                    case '2':
×
UNCOV
69
                        return LEVEL_DEBUG2;
×
70
                    case '3':
×
71
                        return LEVEL_DEBUG3;
×
72
                    case '4':
×
73
                        return LEVEL_DEBUG4;
×
74
                    case '5':
×
75
                        return LEVEL_DEBUG5;
×
76
                }
77
            }
78
            return LEVEL_DEBUG;
699✔
79
        case 'I':
308✔
80
            if (len == 7 && toupper(levelstr[1]) == 'N'
308✔
UNCOV
81
                && toupper(levelstr[2]) == 'V' && toupper(levelstr[3]) == 'A'
×
UNCOV
82
                && toupper(levelstr[4]) == 'L' && toupper(levelstr[5]) == 'I'
×
83
                && toupper(levelstr[6]) == 'D')
×
84
            {
85
                return LEVEL_INVALID;
×
86
            }
87
            return LEVEL_INFO;
308✔
UNCOV
88
        case 'S':
×
UNCOV
89
            return LEVEL_STATS;
×
90
        case 'N':
×
91
            return LEVEL_NOTICE;
×
92
        case 'W':
13✔
93
            return LEVEL_WARNING;
13✔
94
        case 'E':
729✔
95
            return LEVEL_ERROR;
729✔
UNCOV
96
        case 'C':
×
UNCOV
97
            return LEVEL_CRITICAL;
×
98
        case 'F':
1✔
99
            return LEVEL_FATAL;
1✔
100
        default:
613✔
101
            return LEVEL_UNKNOWN;
613✔
102
    }
103
}
104

105
int
106
levelcmp(const char* l1, ssize_t l1_len, const char* l2, ssize_t l2_len)
33✔
107
{
108
    return abbrev2level(l1, l1_len) - abbrev2level(l2, l2_len);
33✔
109
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc