Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(log): use LOG_ERROR_F instead of LOG_ERROR (2/2) #1320

Merged
merged 6 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 43 additions & 47 deletions src/block_service/fds/fds_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,26 +161,26 @@ error_code fds_service::initialize(const std::vector<std::string> &args)
#define FDS_EXCEPTION_HANDLE(ERR_REFERENCE, OPERATION, INPUT_PARAMETER) \
catch (const Poco::TimeoutException &ex) \
{ \
LOG_ERROR("fds %s timeout: parameter(%s), code(%d), msg(%s)", \
OPERATION, \
INPUT_PARAMETER, \
ex.code(), \
ex.message().c_str()); \
LOG_ERROR_F("fds {} timeout: parameter({}), code({}), msg({})", \
OPERATION, \
INPUT_PARAMETER, \
ex.code(), \
ex.message()); \
ERR_REFERENCE = ERR_TIMEOUT; \
} \
catch (const Poco::Exception &ex) \
{ \
LOG_ERROR("fds %s get poco exception: parameter(%s), code(%d), msg(%s), what(%s)", \
OPERATION, \
INPUT_PARAMETER, \
ex.code(), \
ex.message().c_str(), \
ex.what()); \
LOG_ERROR_F("fds {} get poco exception: parameter({}), code({}), msg({}), what({})", \
OPERATION, \
INPUT_PARAMETER, \
ex.code(), \
ex.message(), \
ex.what()); \
ERR_REFERENCE = ERR_FS_INTERNAL; \
} \
catch (...) \
{ \
LOG_ERROR("fds %s get unknown exception: parameter(%s)", OPERATION, INPUT_PARAMETER); \
LOG_ERROR_F("fds {} get unknown exception: parameter({})", OPERATION, INPUT_PARAMETER); \
ERR_REFERENCE = ERR_FS_INTERNAL; \
}

Expand Down Expand Up @@ -233,10 +233,10 @@ dsn::task_ptr fds_service::list_dir(const ls_request &req,
}
}
} catch (const galaxy::fds::GalaxyFDSClientException &ex) {
LOG_ERROR("fds listObjects failed: parameter(%s), code(%d), msg(%s)",
req.dir_name.c_str(),
ex.code(),
ex.what());
LOG_ERROR_F("fds listObjects failed: parameter({}), code({}), msg({})",
req.dir_name,
ex.code(),
ex.what());
resp.err = ERR_FS_INTERNAL;
}
FDS_EXCEPTION_HANDLE(resp.err, "listObject", req.dir_name.c_str())
Expand All @@ -245,19 +245,17 @@ dsn::task_ptr fds_service::list_dir(const ls_request &req,
try {
if (_client->doesObjectExist(_bucket_name,
utils::path_to_fds(req.dir_name, false))) {
LOG_ERROR("fds list_dir failed: path not dir, parameter(%s)",
req.dir_name.c_str());
LOG_ERROR_F("fds list_dir failed: path not dir, parameter({})", req.dir_name);
resp.err = ERR_INVALID_PARAMETERS;
} else {
LOG_ERROR("fds list_dir failed: path not found, parameter(%s)",
req.dir_name.c_str());
LOG_ERROR_F("fds list_dir failed: path not found, parameter({})", req.dir_name);
resp.err = ERR_OBJECT_NOT_FOUND;
}
} catch (const galaxy::fds::GalaxyFDSClientException &ex) {
LOG_ERROR("fds doesObjectExist failed: parameter(%s), code(%d), msg(%s)",
req.dir_name.c_str(),
ex.code(),
ex.what());
LOG_ERROR_F("fds doesObjectExist failed: parameter({}), code({}), msg({})",
req.dir_name,
ex.code(),
ex.what());
resp.err = ERR_FS_INTERNAL;
}
FDS_EXCEPTION_HANDLE(resp.err, "doesObjectExist", req.dir_name.c_str())
Expand Down Expand Up @@ -333,24 +331,22 @@ dsn::task_ptr fds_service::remove_path(const remove_path_request &req,
if (req.recursive) {
should_remove_path = true;
} else {
LOG_ERROR("fds remove_path failed: dir not empty, parameter(%s)",
req.path.c_str());
LOG_ERROR_F("fds remove_path failed: dir not empty, parameter({})", req.path);
resp.err = ERR_DIR_NOT_EMPTY;
}
} else {
if (_client->doesObjectExist(_bucket_name, utils::path_to_fds(req.path, false))) {
should_remove_path = true;
} else {
LOG_ERROR("fds remove_path failed: path not found, parameter(%s)",
req.path.c_str());
LOG_ERROR_F("fds remove_path failed: path not found, parameter({})", req.path);
resp.err = ERR_OBJECT_NOT_FOUND;
}
}
} catch (const galaxy::fds::GalaxyFDSClientException &ex) {
LOG_ERROR("fds remove_path failed: parameter(%s), code(%d), msg(%s)",
req.path.c_str(),
ex.code(),
ex.what());
LOG_ERROR_F("fds remove_path failed: parameter({}), code({}), msg({})",
req.path,
ex.code(),
ex.what());
resp.err = ERR_FS_INTERNAL;
}
FDS_EXCEPTION_HANDLE(resp.err, "remove_path", req.path.c_str());
Expand All @@ -362,16 +358,16 @@ dsn::task_ptr fds_service::remove_path(const remove_path_request &req,
if (deleting->countFailedObjects() <= 0) {
resp.err = ERR_OK;
} else {
LOG_ERROR("fds remove_path failed: countFailedObjects = %d, parameter(%s)",
deleting->countFailedObjects(),
req.path.c_str());
LOG_ERROR_F("fds remove_path failed: countFailedObjects = {}, parameter({})",
deleting->countFailedObjects(),
req.path);
resp.err = ERR_FS_INTERNAL;
}
} catch (const galaxy::fds::GalaxyFDSClientException &ex) {
LOG_ERROR("fds remove_path failed: parameter(%s), code(%d), msg(%s)",
req.path.c_str(),
ex.code(),
ex.what());
LOG_ERROR_F("fds remove_path failed: parameter({}), code({}), msg({})",
req.path,
ex.code(),
ex.what());
resp.err = ERR_FS_INTERNAL;
}
FDS_EXCEPTION_HANDLE(resp.err, "remove_path", req.path.c_str());
Expand Down Expand Up @@ -505,10 +501,10 @@ error_code fds_file_object::get_content(uint64_t pos,
transfered_bytes += utils::copy_stream(is, os, PIECE_SIZE);
err = ERR_OK;
} catch (const galaxy::fds::GalaxyFDSClientException &ex) {
LOG_ERROR("fds getObject error: remote_file(%s), code(%d), msg(%s)",
file_name().c_str(),
ex.code(),
ex.what());
LOG_ERROR_F("fds getObject error: remote_file({}), code({}), msg({})",
file_name(),
ex.code(),
ex.what());
if (ex.code() == Poco::Net::HTTPResponse::HTTP_NOT_FOUND) {
_has_meta_synced = true;
_md5sum = "";
Expand Down Expand Up @@ -549,10 +545,10 @@ error_code fds_file_object::put_content(/*in-out*/ std::istream &is,
try {
c->putObject(_service->get_bucket_name(), _fds_path, is, galaxy::fds::FDSObjectMetadata());
} catch (const galaxy::fds::GalaxyFDSClientException &ex) {
LOG_ERROR("fds putObject error: remote_file(%s), code(%d), msg(%s)",
file_name().c_str(),
ex.code(),
ex.what());
LOG_ERROR_F("fds putObject error: remote_file({}), code({}), msg({})",
file_name(),
ex.code(),
ex.what());
err = ERR_FS_INTERNAL;
}
FDS_EXCEPTION_HANDLE(err, "putObject", file_name().c_str())
Expand Down
21 changes: 10 additions & 11 deletions src/block_service/local/local_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ dsn::task_ptr local_service::list_dir(const ls_request &req,
resp.err = ERR_OBJECT_NOT_FOUND;
} else {
if (!::dsn::utils::filesystem::get_subfiles(dir_path, children, false)) {
LOG_ERROR("get files under directory: %s fail", dir_path.c_str());
LOG_ERROR_F("get files under directory: {} fail", dir_path);
resp.err = ERR_FS_INTERNAL;
children.clear();
} else {
Expand All @@ -137,7 +137,7 @@ dsn::task_ptr local_service::list_dir(const ls_request &req,

children.clear();
if (!::dsn::utils::filesystem::get_subdirectories(dir_path, children, false)) {
LOG_ERROR("get subpaths under directory: %s fail", dir_path.c_str());
LOG_ERROR_F("get subpaths under directory: {} fail", dir_path);
resp.err = ERR_FS_INTERNAL;
children.clear();
} else {
Expand Down Expand Up @@ -492,9 +492,8 @@ dsn::task_ptr local_file_object::download(const download_request &req,
resp.err = ERR_OK;
std::string target_file = req.output_local_name;
if (target_file.empty()) {
LOG_ERROR("download %s failed, because target name(%s) is invalid",
file_name().c_str(),
target_file.c_str());
LOG_ERROR_F(
"download {} failed, because target name({}) is invalid", file_name(), target_file);
resp.err = ERR_INVALID_PARAMETERS;
}

Expand All @@ -508,19 +507,19 @@ dsn::task_ptr local_file_object::download(const download_request &req,
if (resp.err == ERR_OK) {
std::ifstream fin(file_name(), std::ifstream::in);
if (!fin.is_open()) {
LOG_ERROR("open block file(%s) failed, err(%s)",
file_name().c_str(),
utils::safe_strerror(errno).c_str());
LOG_ERROR_F("open block file({}) failed, err({})",
file_name(),
utils::safe_strerror(errno));
resp.err = ERR_FS_INTERNAL;
}

std::ofstream fout(target_file, std::ios_base::out | std::ios_base::trunc);
if (!fout.is_open()) {
if (fin.is_open())
fin.close();
LOG_ERROR("open target file(%s) failed, err(%s)",
target_file.c_str(),
utils::safe_strerror(errno).c_str());
LOG_ERROR_F("open target file({}) failed, err({})",
target_file,
utils::safe_strerror(errno));
resp.err = ERR_FILE_OPERATION_FAILED;
}

Expand Down
8 changes: 4 additions & 4 deletions src/client/partition_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ void partition_resolver::call_task(const rpc_response_task_ptr &t)
std::chrono::milliseconds(gap));
return;
} else {
LOG_ERROR("service access failed (%s), no more time for further "
"tries, set error = ERR_TIMEOUT, trace_id = %016" PRIx64,
err.to_string(),
req->header->trace_id);
LOG_ERROR_F("service access failed ({}), no more time for further tries, set error "
"= ERR_TIMEOUT, trace_id = {:#018x}",
err,
req->header->trace_id);
err = ERR_TIMEOUT;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/partition_resolver_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ partition_resolver_ptr partition_resolver_manager::find_or_create(
dsn::rpc_address meta_group = ptr->get_meta_server();
const std::vector<dsn::rpc_address> &existing_list = meta_group.group_address()->members();
if (!vector_equal(meta_list, existing_list)) {
LOG_ERROR("meta list not match for cluster(%s)", cluster_name);
LOG_ERROR_F("meta list not match for cluster({})", cluster_name);
return nullptr;
}
return ptr;
Expand Down
21 changes: 6 additions & 15 deletions src/client/partition_resolver_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,28 +310,19 @@ void partition_resolver_simple::query_config_reply(error_code err,
}
}
} else if (resp.err == ERR_OBJECT_NOT_FOUND) {
LOG_ERROR("%s.client: query config reply, gpid = %d.%d, err = %s",
_app_name.c_str(),
_app_id,
partition_index,
resp.err.to_string());
LOG_ERROR_PREFIX(
"query config reply, gpid = {}.{}, err = {}", _app_id, partition_index, resp.err);

client_err = ERR_APP_NOT_EXIST;
} else {
LOG_ERROR("%s.client: query config reply, gpid = %d.%d, err = %s",
_app_name.c_str(),
_app_id,
partition_index,
resp.err.to_string());
LOG_ERROR_PREFIX(
"query config reply, gpid = {}.{}, err = {}", _app_id, partition_index, resp.err);

client_err = resp.err;
}
} else {
LOG_ERROR("%s.client: query config reply, gpid = %d.%d, err = %s",
_app_name.c_str(),
_app_id,
partition_index,
err.to_string());
LOG_ERROR_PREFIX(
"query config reply, gpid = {}.{}, err = {}", _app_id, partition_index, err);
}

// get specific or all partition update
Expand Down
2 changes: 1 addition & 1 deletion src/client/replication_ddl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ dsn::error_code replication_ddl_client::list_apps(const dsn::app_status::type st
std::vector<partition_configuration> partitions;
r = list_app(info.app_name, app_id, partition_count, partitions);
if (r != dsn::ERR_OK) {
LOG_ERROR("list app(%s) failed, err = %s", info.app_name.c_str(), r.to_string());
LOG_ERROR_F("list app({}) failed, err = {}", info.app_name, r);
return r;
}
CHECK_EQ(info.app_id, app_id);
Expand Down
4 changes: 2 additions & 2 deletions src/client_lib/pegasus_client_factory_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ pegasus_client *pegasus_client_factory_impl::get_client(const char *cluster_name
const char *app_name)
{
if (cluster_name == nullptr || cluster_name[0] == '\0') {
LOG_ERROR("invalid parameter 'cluster_name'");
LOG_ERROR_F("invalid parameter 'cluster_name'");
return nullptr;
}
if (app_name == nullptr || app_name[0] == '\0') {
LOG_ERROR("invalid parameter 'app_name'");
LOG_ERROR_F("invalid parameter 'app_name'");
return nullptr;
}

Expand Down
Loading