• 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

92.86
/src/pretty_printer.hh
1
/**
2
 * Copyright (c) 2015, 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
#ifndef pretty_printer_hh
31
#define pretty_printer_hh
32

33
#include <deque>
34
#include <optional>
35
#include <set>
36
#include <sstream>
37
#include <stack>
38
#include <string>
39
#include <vector>
40

41
#include "base/attr_line.hh"
42
#include "base/file_range.hh"
43
#include "data_scanner.hh"
44
#include "document.sections.hh"
45

46
class pretty_printer {
47
public:
48
    struct element {
49
        element(data_token_t token, data_scanner::capture_t& cap)
2,618✔
50
            : e_token(token), e_capture(cap)
2,618✔
51
        {
52
        }
2,618✔
53

54
        data_token_t e_token;
55
        data_scanner::capture_t e_capture;
56
    };
57

58
    pretty_printer(data_scanner* ds, string_attrs_t sa, int leading_indent = 0)
229✔
59
        : pp_leading_indent(leading_indent), pp_scanner(ds),
458✔
60
          pp_attrs(std::move(sa))
229✔
61
    {
62
        this->pp_body_lines.push(0);
229✔
63
        this->pp_scanner->reset();
229✔
64
        while (true) {
65
            auto tok_res = this->pp_scanner->tokenize2();
2,668✔
66
            if (!tok_res) {
2,668✔
67
                break;
226✔
68
            }
69
            if (tok_res->tr_token == DT_XML_CLOSE_TAG
2,442✔
70
                || tok_res->tr_token == DT_XML_DECL_TAG)
2,442✔
71
            {
72
                pp_is_xml = true;
3✔
73
                break;
3✔
74
            }
75
        }
2,439✔
76

77
        this->pp_interval_state.resize(1);
229✔
78
        this->pp_hier_nodes.push_back(
229✔
79
            std::make_unique<lnav::document::hier_node>());
458✔
80
    }
229✔
81

82
    void append_to(attr_line_t& al);
83

84
    std::vector<lnav::document::section_interval_t> take_intervals()
55✔
85
    {
86
        return std::move(this->pp_intervals);
55✔
87
    }
88

89
    std::unique_ptr<lnav::document::hier_node> take_hier_root()
55✔
90
    {
91
        if (this->pp_hier_stage == nullptr && !this->pp_hier_nodes.empty()) {
55✔
UNCOV
92
            this->pp_hier_stage = std::move(this->pp_hier_nodes.back());
×
UNCOV
93
            this->pp_hier_nodes.pop_back();
×
94
        }
95
        return std::move(this->pp_hier_stage);
55✔
96
    }
97

98
    std::set<size_t> take_indents() { return std::move(this->pp_indents); }
55✔
99

100
private:
101
    void descend(data_token_t dt);
102

103
    void ascend(data_token_t dt);
104

105
    void start_new_line();
106

107
    bool flush_values(bool start_on_depth = false);
108

109
    int append_indent();
110

111
    void write_element(const element& el);
112

113
    void append_child_node();
114

115
    struct interval_state {
116
        std::optional<file_off_t> is_start;
117
        std::string is_name;
118
    };
119

120
    int pp_leading_indent;
121
    int pp_depth{0};
122
    int pp_line_length{0};
123
    int pp_soft_indent{0};
124
    std::vector<data_token_t> pp_container_tokens{};
125
    std::stack<int> pp_body_lines{};
126
    data_scanner* pp_scanner;
127
    string_attrs_t pp_attrs;
128
    std::ostringstream pp_stream;
129
    std::deque<element> pp_values{};
130
    int pp_shift_accum{0};
131
    bool pp_is_xml{false};
132
    std::vector<interval_state> pp_interval_state;
133
    std::vector<lnav::document::section_interval_t> pp_intervals;
134
    std::vector<std::unique_ptr<lnav::document::hier_node>> pp_hier_nodes;
135
    std::unique_ptr<lnav::document::hier_node> pp_hier_stage;
136
    std::set<size_t> pp_indents;
137
};
138

139
#endif
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