Use log_error instead of cerr
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
#include <config/config.hpp>
|
#include <config/config.hpp>
|
||||||
|
#include <logger/logger.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <cstring>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <cstdlib>
|
||||||
|
|
||||||
std::string Config::filename{};
|
std::string Config::filename{};
|
||||||
std::map<std::string, std::string> Config::values{};
|
std::map<std::string, std::string> Config::values{};
|
||||||
@@ -22,7 +23,7 @@ int Config::get_int(const std::string& option, const int& def)
|
|||||||
{
|
{
|
||||||
std::string res = Config::get(option, "");
|
std::string res = Config::get(option, "");
|
||||||
if (!res.empty())
|
if (!res.empty())
|
||||||
return atoi(res.c_str());
|
return std::atoi(res.c_str());
|
||||||
else
|
else
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
@@ -65,7 +66,7 @@ bool Config::read_conf(const std::string& name)
|
|||||||
std::ifstream file(Config::filename.data());
|
std::ifstream file(Config::filename.data());
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
perror(("Error while opening file " + filename + " for reading.").c_str());
|
log_error("Error while opening file ", filename, " for reading: ", strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ void Config::save_to_file()
|
|||||||
std::ofstream file(Config::filename.data());
|
std::ofstream file(Config::filename.data());
|
||||||
if (file.fail())
|
if (file.fail())
|
||||||
{
|
{
|
||||||
std::cerr << "Could not save config file." << std::endl;
|
log_error("Could not save config file.");
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
for (const auto& it: Config::values)
|
for (const auto& it: Config::values)
|
||||||
|
|||||||
+4
-6
@@ -28,11 +28,9 @@ static bool exiting = false;
|
|||||||
int config_help(const std::string& missing_option)
|
int config_help(const std::string& missing_option)
|
||||||
{
|
{
|
||||||
if (!missing_option.empty())
|
if (!missing_option.empty())
|
||||||
std::cerr << "Error: empty value for option " << missing_option << "." << std::endl;
|
log_error("Error: empty value for option ", missing_option, ".");
|
||||||
std::cerr <<
|
log_error("Please provide a configuration file filled like this:\n\n"
|
||||||
"Please provide a configuration file filled like this:\n\n"
|
"hostname=irc.example.com\npassword=S3CR3T");
|
||||||
"hostname=irc.example.com\npassword=S3CR3T"
|
|
||||||
<< std::endl;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +50,7 @@ static void sigusr_handler(int, siginfo_t*, void*)
|
|||||||
int main(int ac, char** av)
|
int main(int ac, char** av)
|
||||||
{
|
{
|
||||||
const std::string conf_filename = ac > 1 ? av[1] : xdg_config_path("biboumi.cfg");
|
const std::string conf_filename = ac > 1 ? av[1] : xdg_config_path("biboumi.cfg");
|
||||||
std::cerr << "Using configuration file: " << conf_filename << std::endl;
|
log_info("Using configuration file: ", conf_filename);
|
||||||
|
|
||||||
if (!Config::read_conf(conf_filename))
|
if (!Config::read_conf(conf_filename))
|
||||||
return config_help("");
|
return config_help("");
|
||||||
|
|||||||
Reference in New Issue
Block a user