aboutsummaryrefslogtreecommitdiff
path: root/bbot/diagnostics.cxx
blob: 5954ad14b1d396707720d3b41df7428e57828617 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// file      : bbot/diagnostics.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license   : TBC; see accompanying LICENSE file

#include <bbot/diagnostics.hxx>

#include <bbot/utility.hxx>

using namespace std;
using namespace butl;

namespace bbot
{
  // Diagnostics verbosity level.
  //
  uint16_t verb;

  // Diagnostic facility, project specifics.
  //

  void simple_prologue_base::
  operator() (const diag_record& r) const
  {
    if (type_ != nullptr)
      r << type_;

    if (name_ != nullptr)
      r << name_;

    if (data_ != nullptr)
      r << '(' << data_ << ')';

    if (name_ != nullptr || data_ != nullptr)
      r << ": ";
  }

  const char* trace_type = "trace: ";
  const char* trace_indent = "\n  ";

  trace_mark_base::
  trace_mark_base (const char* name, const char* data)
      : basic_mark_base (trace_type, trace_indent, name, data)
  {
  }

  basic_mark error ("error: ");
  basic_mark warn  ("warning: ");
  basic_mark info  ("info: ");
  basic_mark text  (nullptr);
  fail_mark  fail  ("error: ");

  const fail_end endf;

  // We used the right arrow Unicode character to signal line continuation.
  // It only looked cute when displayed properly.
  //
  const char systemd_indent[] = " \\\n";

  void
  systemd_diagnostics (bool with_critical)
  {
    trace_indent    =
      fail.indent_  =
      error.indent_ =
      warn.indent_  =
      info.indent_  =
      text.indent_  = systemd_indent;

    // We don't always see colorized output so keep 'error: ', etc.
    //
    fail.type_  = with_critical ? "<2>error: " : "<3>error: ";
    error.type_ = "<3>error: ";
    warn.type_  = "<4>warning: ";
    info.type_  = "<6>";
    trace_type  = "<7>";
  }
}