Use correct log levels

This commit is contained in:
blank X 2022-01-17 16:49:54 +07:00
parent 03c6669c59
commit 466115bc39
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
3 changed files with 17 additions and 17 deletions

View File

@ -19,13 +19,13 @@ void kore_parent_configure(int argc, char* argv[]) {
} }
config_fstream.close(); config_fstream.close();
if (config_fstream.fail() && !config_fstream.eof()) { if (config_fstream.fail() && !config_fstream.eof()) {
kore_log(LOG_NOTICE, "fail bit set when reading config"); kore_log(LOG_ERR, "fail bit set when reading config");
exit(1); exit(1);
} }
kore_json json; kore_json json;
kore_json_init(&json, config_str.c_str(), config_str.length()); kore_json_init(&json, config_str.c_str(), config_str.length());
if (kore_json_parse(&json) != KORE_RESULT_OK) { if (kore_json_parse(&json) != KORE_RESULT_OK) {
kore_log(LOG_NOTICE, "failed to parse json: %s", kore_json_strerror(&json)); kore_log(LOG_ERR, "failed to parse json: %s", kore_json_strerror(&json));
exit(1); exit(1);
} }
kore_json_item* redis_host_json = kore_json_find_string(json.root, "redis_host"); kore_json_item* redis_host_json = kore_json_find_string(json.root, "redis_host");
@ -42,16 +42,16 @@ void kore_parent_configure(int argc, char* argv[]) {
void kore_worker_configure() { void kore_worker_configure() {
if (config.redis_host && config.redis_port) { if (config.redis_host && config.redis_port) {
kore_log(LOG_NOTICE, "connecting to redis instance at %s:%d", (*config.redis_host).c_str(), (*config.redis_port)); kore_log(LOG_INFO, "connecting to redis instance at %s:%d", (*config.redis_host).c_str(), (*config.redis_port));
struct timeval timeout = {1, 0}; struct timeval timeout = {1, 0};
redis = redisConnectWithTimeout((*config.redis_host).c_str(), (*config.redis_port), timeout); redis = redisConnectWithTimeout((*config.redis_host).c_str(), (*config.redis_port), timeout);
if (!redis || redis->err) { if (!redis || redis->err) {
if (redis) { if (redis) {
kore_log(LOG_NOTICE, "failed to connect to redis: %s", redis->errstr); kore_log(LOG_ERR, "failed to connect to redis: %s", redis->errstr);
redisFree(redis); redisFree(redis);
redis = nullptr; redis = nullptr;
} else { } else {
kore_log(LOG_NOTICE, "failed to connect to redis"); kore_log(LOG_ERR, "failed to connect to redis");
} }
kore_shutdown(); kore_shutdown();
exit(1); exit(1);
@ -60,9 +60,9 @@ void kore_worker_configure() {
redisReply* reply = (redisReply*)redisCommand(redis, "AUTH %s", (*config.redis_password).c_str()); redisReply* reply = (redisReply*)redisCommand(redis, "AUTH %s", (*config.redis_password).c_str());
if (!reply || reply->type == REDIS_REPLY_ERROR) { if (!reply || reply->type == REDIS_REPLY_ERROR) {
if (!reply) { if (!reply) {
kore_log(LOG_NOTICE, "received nullptr while authenticating to redis"); kore_log(LOG_ERR, "received nullptr while authenticating to redis");
} else { } else {
kore_log(LOG_NOTICE, "received error while authenticating to redis: %s", reply->str); kore_log(LOG_ERR, "received error while authenticating to redis: %s", reply->str);
freeReplyObject(reply); freeReplyObject(reply);
} }
redisFree(redis); redisFree(redis);

View File

@ -28,11 +28,11 @@ static bool send_hget_and_http_resp(struct http_request* req, const char* id, bo
redisReply* reply = (redisReply*)redisCommand(redis, "HGET %s %s", keys.key.c_str(), keys.field.c_str()); redisReply* reply = (redisReply*)redisCommand(redis, "HGET %s %s", keys.key.c_str(), keys.field.c_str());
if (!reply) { if (!reply) {
redis_mutex.unlock(); redis_mutex.unlock();
kore_log(LOG_NOTICE, "received nullptr while sending HGET to redis"); kore_log(LOG_WARNING, "received nullptr while sending HGET to redis");
return false; return false;
} }
if (reply->type == REDIS_REPLY_ERROR) { if (reply->type == REDIS_REPLY_ERROR) {
kore_log(LOG_NOTICE, "received error while sending HGET to redis: %s", reply->str); kore_log(LOG_WARNING, "received error while sending HGET to redis: %s", reply->str);
freeReplyObject(reply); freeReplyObject(reply);
redis_mutex.unlock(); redis_mutex.unlock();
return false; return false;
@ -58,7 +58,7 @@ static bool send_hget_and_http_resp(struct http_request* req, const char* id, bo
freeReplyObject(reply); freeReplyObject(reply);
redis_mutex.unlock(); redis_mutex.unlock();
if (error) { if (error) {
kore_log(LOG_NOTICE, "received error while parsing packed album: %s", (*error).c_str()); kore_log(LOG_WARNING, "received error while parsing packed album: %s", (*error).c_str());
return false; return false;
} }
send_album_page(req, std::move(album)); send_album_page(req, std::move(album));
@ -89,7 +89,7 @@ static int album_or_image_start(struct http_request* req) {
struct kore_curl* client = (kore_curl*)http_state_create(req, sizeof(*client), NULL); struct kore_curl* client = (kore_curl*)http_state_create(req, sizeof(*client), NULL);
if (!kore_curl_init(client, api_url.c_str(), KORE_CURL_ASYNC)) { if (!kore_curl_init(client, api_url.c_str(), KORE_CURL_ASYNC)) {
http_state_cleanup(req); http_state_cleanup(req);
kore_log(LOG_NOTICE, "failed to initialize curl client"); kore_log(LOG_ERR, "failed to initialize curl client");
std::string error_page = build_error_page("Failed to initialize curl client"); std::string error_page = build_error_page("Failed to initialize curl client");
http_response(req, 500, error_page.c_str(), error_page.length()); http_response(req, 500, error_page.c_str(), error_page.length());
return HTTP_STATE_COMPLETE; return HTTP_STATE_COMPLETE;
@ -109,11 +109,11 @@ static void send_hset(const char* id, bool is_album, const char* packed) {
redisReply* reply = (redisReply*)redisCommand(redis, "HSET %s %s %s", keys.key.c_str(), keys.field.c_str(), packed); redisReply* reply = (redisReply*)redisCommand(redis, "HSET %s %s %s", keys.key.c_str(), keys.field.c_str(), packed);
if (!reply) { if (!reply) {
redis_mutex.unlock(); redis_mutex.unlock();
kore_log(LOG_NOTICE, "received nullptr while sending HSET to redis"); kore_log(LOG_WARNING, "received nullptr while sending HSET to redis");
return; return;
} }
if (reply->type == REDIS_REPLY_ERROR) { if (reply->type == REDIS_REPLY_ERROR) {
kore_log(LOG_NOTICE, "received error while sending HSET to redis: %s", reply->str); kore_log(LOG_WARNING, "received error while sending HSET to redis: %s", reply->str);
freeReplyObject(reply); freeReplyObject(reply);
redis_mutex.unlock(); redis_mutex.unlock();
return; return;
@ -146,7 +146,7 @@ static int album_or_image_end(struct http_request* req) {
kore_json json; kore_json json;
kore_json_init(&json, body, strlen(body)); kore_json_init(&json, body, strlen(body));
if (kore_json_parse(&json) != KORE_RESULT_OK) { if (kore_json_parse(&json) != KORE_RESULT_OK) {
kore_log(LOG_NOTICE, "failed to parse json: %s", kore_json_strerror(&json)); kore_log(LOG_ERR, "failed to parse json: %s", kore_json_strerror(&json));
std::string error = "Failed to parse response: "; std::string error = "Failed to parse response: ";
error.append(kore_json_strerror(&json)); error.append(kore_json_strerror(&json));
kore_json_cleanup(&json); kore_json_cleanup(&json);
@ -191,7 +191,7 @@ static int album_or_image_end(struct http_request* req) {
if (error_detail_json) { if (error_detail_json) {
error_detail = error_detail_json->data.string; error_detail = error_detail_json->data.string;
} }
kore_log(LOG_NOTICE, "received error from api: %s: %s", error_code, error_detail); kore_log(LOG_ERR, "received error from api: %s: %s", error_code, error_detail);
std::string to_append; std::string to_append;
if (needs_newline) { if (needs_newline) {
to_append.append("\n"); to_append.append("\n");
@ -217,7 +217,7 @@ static int album_or_image_end(struct http_request* req) {
kore_curl_cleanup(client); kore_curl_cleanup(client);
http_state_cleanup(req); http_state_cleanup(req);
if (error) { if (error) {
kore_log(LOG_NOTICE, "%s", (*error).c_str()); kore_log(LOG_ERR, "%s", (*error).c_str());
std::string error_page = build_error_page((*error).c_str()); std::string error_page = build_error_page((*error).c_str());
http_response(req, 500, error_page.c_str(), error_page.length()); http_response(req, 500, error_page.c_str(), error_page.length());
return HTTP_STATE_COMPLETE; return HTTP_STATE_COMPLETE;

View File

@ -28,7 +28,7 @@ static int proxy_start(struct http_request* req) {
struct kore_curl* client = (kore_curl*)http_state_create(req, sizeof(*client), NULL); struct kore_curl* client = (kore_curl*)http_state_create(req, sizeof(*client), NULL);
if (!kore_curl_init(client, url.c_str(), KORE_CURL_ASYNC)) { if (!kore_curl_init(client, url.c_str(), KORE_CURL_ASYNC)) {
http_state_cleanup(req); http_state_cleanup(req);
kore_log(LOG_NOTICE, "failed to initialize curl client"); kore_log(LOG_ERR, "failed to initialize curl client");
std::string error_page = build_error_page("Failed to initialize curl client"); std::string error_page = build_error_page("Failed to initialize curl client");
http_response(req, 500, error_page.c_str(), error_page.length()); http_response(req, 500, error_page.c_str(), error_page.length());
return HTTP_STATE_COMPLETE; return HTTP_STATE_COMPLETE;