mirror of
https://github.com/NixOS/nix
synced 2025-07-03 06:11:46 +02:00
Make 'logger' a std::unique_ptr
This prevents it from being leaked (see
bb411e4ae1
for an example of this).
This commit is contained in:
parent
1f688d62d7
commit
2018413e3e
8 changed files with 45 additions and 42 deletions
|
@ -6,7 +6,8 @@ namespace nix {
|
|||
|
||||
LogFormat defaultLogFormat = LogFormat::raw;
|
||||
|
||||
LogFormat parseLogFormat(const std::string & logFormatStr) {
|
||||
LogFormat parseLogFormat(const std::string & logFormatStr)
|
||||
{
|
||||
if (logFormatStr == "raw" || getEnv("NIX_GET_COMPLETIONS"))
|
||||
return LogFormat::raw;
|
||||
else if (logFormatStr == "raw-with-logs")
|
||||
|
@ -20,7 +21,8 @@ LogFormat parseLogFormat(const std::string & logFormatStr) {
|
|||
throw Error("option 'log-format' has an invalid value '%s'", logFormatStr);
|
||||
}
|
||||
|
||||
Logger * makeDefaultLogger() {
|
||||
std::unique_ptr<Logger> makeDefaultLogger()
|
||||
{
|
||||
switch (defaultLogFormat) {
|
||||
case LogFormat::raw:
|
||||
return makeSimpleLogger(false);
|
||||
|
@ -40,16 +42,19 @@ Logger * makeDefaultLogger() {
|
|||
}
|
||||
}
|
||||
|
||||
void setLogFormat(const std::string & logFormatStr) {
|
||||
void setLogFormat(const std::string & logFormatStr)
|
||||
{
|
||||
setLogFormat(parseLogFormat(logFormatStr));
|
||||
}
|
||||
|
||||
void setLogFormat(const LogFormat & logFormat) {
|
||||
void setLogFormat(const LogFormat & logFormat)
|
||||
{
|
||||
defaultLogFormat = logFormat;
|
||||
createDefaultLogger();
|
||||
}
|
||||
|
||||
void createDefaultLogger() {
|
||||
void createDefaultLogger()
|
||||
{
|
||||
logger = makeDefaultLogger();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue