Mercurial > irccd
changeset 110:5d71d270a2dd
Irccd: more cppformat usage, #483
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 27 Apr 2016 18:53:30 +0200 |
parents | 54301e7646b2 |
children | 1ed760f6e0c6 |
files | lib/irccd/irccd.cpp lib/irccd/irccdctl.cpp |
diffstat | 2 files changed, 24 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/irccd/irccd.cpp Wed Apr 27 13:10:05 2016 +0200 +++ b/lib/irccd/irccd.cpp Wed Apr 27 18:53:30 2016 +0200 @@ -19,6 +19,8 @@ #include <algorithm> #include <stdexcept> +#include <format.h> + #include "fs.hpp" #include "irccd.hpp" #include "logger.hpp" @@ -558,7 +560,7 @@ auto name = object.find("command"); if (name == object.end() || name->typeOf() != json::Type::String) { // TODO: send error - log::warning() << "invalid command object" << std::endl; + log::warning("invalid command object"); return; } @@ -567,7 +569,7 @@ if (it == m_commands.end()) { // TODO: send error again - log::warning() << "command does not exists" << std::endl; + log::warning("command does not exists"); return; } @@ -598,7 +600,7 @@ void Irccd::handleTransportDie(std::weak_ptr<TransportClient> ptr) { post([=] (Irccd &) { - log::info() << "transport: client disconnected" << std::endl; + log::info("transport: client disconnected"); auto tc = ptr.lock(); @@ -630,7 +632,7 @@ if (!FD_ISSET(pair.second->handle(), &input)) continue; - log::debug() << "transport: new client connected" << endl; + log::debug("transport: new client connected"); std::shared_ptr<TransportClient> client = pair.second->accept(); std::weak_ptr<TransportClient> ptr(client); @@ -735,7 +737,7 @@ auto server = ptr.lock(); if (server) { - log::info() << "server " << server->info().name << ": removed" << std::endl; + log::info(fmt::format("server {}: removed", server->info().name)); m_servers.erase(server->info().name); } }); @@ -832,7 +834,7 @@ plugin->onLoad(); m_plugins.insert({plugin->info().name, plugin}); } catch (const std::exception &ex) { - log::info() << "plugin " << plugin->info().name << ": " << ex.what() << std::endl; + log::warning(fmt::format("plugin {}: {}", plugin->info().name, ex.what())); } } @@ -851,16 +853,16 @@ paths.push_back(source); /* Iterate over all paths */ - log::info() << "plugin " << name << ": trying to load:" << std::endl; + log::info(fmt::format("plugin {}: trying to load:", name)); for (const auto &path : paths) { - log::info() << " from " << path << std::endl; + log::info(fmt::format(" from ", path)); try { plugin = std::make_shared<Plugin>(name, path, m_pluginConf[name]); break; } catch (const std::exception &ex) { - log::info() << " error: " << ex.what() << std::endl; + log::info(fmt::format(" error: {}", ex.what())); } } @@ -911,12 +913,12 @@ duk::StackAssert sa(ctx); + // TODO: improve this try { duk::getGlobal<void>(ctx, "\xff""\xff""timer-" + std::to_string(reinterpret_cast<std::intptr_t>(timer.get()))); duk::pcall(ctx, 0); duk::pop(ctx); } catch (const std::exception &) { - log::info() << "failure" << std::endl; } }); }
--- a/lib/irccd/irccdctl.cpp Wed Apr 27 13:10:05 2016 +0200 +++ b/lib/irccd/irccdctl.cpp Wed Apr 27 18:53:30 2016 +0200 @@ -23,6 +23,8 @@ #include <string> #include <unordered_map> +#include <format.h> + #include "elapsed-timer.hpp" #include "fs.hpp" #include "ini.hpp" @@ -38,6 +40,8 @@ namespace irccd { +using namespace fmt::literals; + using namespace net; using namespace net::address; using namespace net::option; @@ -224,11 +228,10 @@ } /* Show for debugging purpose */ - log::debug() << "alias " << option.key() << ":" << std::endl; + log::debug("alias {}:"_format(option.key())); for (const auto &cmd : alias) { - log::debug() << " " << cmd.command() << " "; - log::debug() << util::join(cmd.args().begin(), cmd.args().end(), ' ') << std::endl; + log::debug(" {} {}"_format(cmd.command(), util::join(cmd.args().begin(), cmd.args().end(), ' '))); } m_aliases.emplace(option.key(), std::move(alias)); @@ -344,7 +347,7 @@ if (result.count("-v") != 0 || result.count("--verbose") != 0) log::setVerbose(true); } catch (const std::exception &ex) { - log::warning() << sys::programName() << ": " << ex.what() << std::endl; + log::warning("{}: {}"_format(sys::programName(), ex.what())); usage(); } @@ -458,7 +461,7 @@ void Irccdctl::connect() { - log::info() << sys::programName() << ": connecting to irccd..." << std::endl; + log::info("{}: connecting to irccd..."_format(sys::programName())); /* Try to connect */ m_connection->connect(30000); @@ -477,8 +480,8 @@ m_ssl = object.valueOr("ssl", json::Type::Boolean, false).toBool(); log::info() << std::boolalpha; - log::info() << sys::programName() << ": connected to irccd " << m_major << "." << m_minor << "." << m_patch << std::endl; - log::info() << sys::programName() << ": javascript: " << m_javascript << ", ssl supported: " << m_ssl << std::endl; + log::info("{}: connected to irccd {}.{}.{}"_format(sys::programName(), m_major, m_minor, m_patch)); + log::info("{}: javascript: {}, ssl support: {}"_format(sys::programName(), m_javascript, m_ssl)); } void Irccdctl::run(int argc, char **argv) @@ -512,7 +515,7 @@ } } } catch (const std::exception &ex) { - log::warning() << sys::programName() << ": " << ex.what() << std::endl; + log::warning("{}: {}"_format(sys::programName(), ex.what())); std::exit(1); } @@ -524,7 +527,7 @@ /* help does not require connection */ if (std::strcmp(argv[0], "help") != 0) { if (!m_connection) { - log::warning() << sys::programName() << ": no connection specified" << std::endl; + log::warning("{}: no connection specified"_format(sys::programName())); std::exit(1); }