}
+
+static void loggerBackend(std::unique_ptr<Logging::Entry> entry) {
+ static thread_local std::stringstream buf;
+
+ buf.str("");
+ buf << "msg=" << std::quoted(entry->message);
+ if (entry->error) {
+ buf << " oserror=" << std::quoted(entry->error.get());
+ }
+
+ if (entry->name) {
+ buf << " subsystem=" << std::quoted(entry->name.get());
+ }
+
+ for (auto const& v: entry->values) {
+ buf << " ";
+ buf << v.first << "=" << std::quoted(v.second);
+ }
+ g_log << Logger::Urgency(entry->level) << buf.str() << endl;
+}
+
+
int main(int argc, char **argv)
{
g_argc = argc;
exit(0);
}
- g_slog = Logging::Logger::create([](std::unique_ptr<Logging::Entry> entry) {
- if (entry->error) {
- std::cout << "ERR ";
- } else {
- std::cout << "INFO";
- }
- if (entry->name) {
- std::cout << entry->name.get() << ": ";
- }
- std::cout << entry->message;
- for (auto const& v: entry->values) {
- std::cout << " ";
- std::cout << v.first << "=" << v.second;
- }
- std::cout << std::endl;
- });
+ g_slog = Logging::Logger::create(loggerBackend);
auto startupLog = g_slog->withName("startup");
if(!::arg().file(configname.c_str())) {
std::shared_ptr<Logr::Logger> Logger::withValues(const std::string& key, const Logr::Loggable& value)
{
- auto res = std::make_shared<Logger>(getptr(), _name.get(), _level, _callback);
+ auto res = std::make_shared<Logger>(getptr(), _name, _level, _callback);
res->_values.insert({key, value.to_string()});
res->setVerbosity(getVerbosity());
return res;
Logger::Logger(EntryLogger callback) : _callback(callback)
{
}
- Logger::Logger(EntryLogger callback, boost::optional<const std::string> name) : _callback(callback), _name(name)
+ Logger::Logger(EntryLogger callback, boost::optional<std::string> name) : _callback(callback), _name(name)
{
}
- Logger::Logger(std::shared_ptr<Logger> parent, boost::optional<const std::string> name, size_t lvl, EntryLogger callback) : _parent(parent), _callback(callback), _name(name), _level(lvl)
+ Logger::Logger(std::shared_ptr<Logger> parent, boost::optional<std::string> name, size_t lvl, EntryLogger callback) : _parent(parent), _callback(callback), _name(name), _level(lvl)
{
}
static std::shared_ptr<Logger> create(EntryLogger callback, const std::string& name);
Logger(EntryLogger callback);
- Logger(EntryLogger callback, boost::optional<const std::string> name);
- Logger(std::shared_ptr<Logger> parent, boost::optional<const std::string> name, size_t lvl, EntryLogger callback);
+ Logger(EntryLogger callback, boost::optional<std::string> name);
+ Logger(std::shared_ptr<Logger> parent, boost::optional<std::string> name, size_t lvl, EntryLogger callback);
virtual ~Logger();
size_t getVerbosity() const;