Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
capture-logging.hh
1
#pragma once
2
3
#include "
nix/util/logging.hh
"
4
5
#include <sstream>
6
7
namespace
nix::testing {
8
9
class
CaptureLogger :
public
Logger
10
{
11
std::ostringstream oss;
12
13
public
:
14
CaptureLogger() {}
15
16
std::string get()
const
17
{
18
return
oss.str();
19
}
20
21
void
log(Verbosity lvl, std::string_view s)
noexcept
override
22
{
23
oss << s << std::endl;
24
}
25
26
void
logEI(
const
ErrorInfo
& ei)
noexcept
override
27
{
28
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
29
}
30
};
31
32
class
CaptureLogging
33
{
34
std::unique_ptr<CaptureLogger> logger;
35
Logger
* oldLogger;
36
37
public
:
38
CaptureLogging()
39
{
40
oldLogger =
nix::logger
;
41
logger = std::make_unique<CaptureLogger>();
42
nix::logger
= logger.get();
43
}
44
45
std::string get()
const
46
{
47
return
logger->get();
48
}
49
50
CaptureLogging(CaptureLogging &&) =
delete
;
51
CaptureLogging(
const
CaptureLogging &) =
delete
;
52
CaptureLogging & operator=(CaptureLogging &&) =
delete
;
53
CaptureLogging & operator=(
const
CaptureLogging &) =
delete
;
54
55
~CaptureLogging()
56
{
57
nix::logger
= oldLogger;
58
}
59
};
60
61
}
// namespace nix::testing
nix::Logger
Definition
logging.hh:96
logging.hh
nix::logger
Logger * logger
Definition
logging.cc:45
nix::ErrorInfo
Definition
error.hh:109
libutil-test-support
include
nix
util
tests
capture-logging.hh
Generated by
1.18.0