-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thanks to some precision guidance by regnat, we can remove libstore's dependency on libmain by just making the logging mechanisms pluggable. This: * moves loggers.{hh,cc} from libmain to libutil * removes the now-unnecessary (and incorrect) `toJSON` specialization * moves LogFormat from types.hh to loggers.hh * adds a completer (untested) To add another logger, the following steps should be all that's necessary: 1) Add enum variant in libutil/loggers.hh and name to the `std::set` in loggers.cc 2) Modify the specialized `set` and `to_string` methods to include the new variant 3) Use the `OnStartup` class to `registerLogger` the new logger method Co-authored-by: regnat <rg@regnat.ovh>
- Loading branch information
1 parent
85f6568
commit 6efa529
Showing
10 changed files
with
132 additions
and
77 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "loggers.hh" | ||
|
||
namespace nix { | ||
|
||
std::set<std::string> logFormats = { | ||
"raw", | ||
"raw-with-logs", | ||
"internal-json", | ||
"bar", | ||
"bar-with-logs" | ||
}; | ||
|
||
std::vector<std::shared_ptr<LoggerBuilder>> registeredLoggers; | ||
|
||
void registerLogger(std::string name, std::function<Logger*()> builder) | ||
{ | ||
LoggerBuilder lBuilder { .name = name, .builder = builder }; | ||
registeredLoggers.push_back(std::make_shared<LoggerBuilder>(lBuilder)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include "logging.hh" | ||
|
||
namespace nix { | ||
|
||
enum class LogFormat { | ||
raw, | ||
rawWithLogs, | ||
internalJson, | ||
bar, | ||
barWithLogs, | ||
}; | ||
|
||
struct LoggerBuilder { | ||
std::string name; | ||
std::function<Logger*()> builder; | ||
}; | ||
|
||
extern std::set<std::string> logFormats; | ||
|
||
extern std::vector<std::shared_ptr<LoggerBuilder>> registeredLoggers; | ||
|
||
void registerLogger(std::string name, std::function<Logger*()> builder); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters