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: Move tox_log_level out into its own file. #2794

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,15 @@ set(toxcore_SOURCES
toxcore/timed_auth.h
toxcore/tox_api.c
toxcore/tox.c
toxcore/tox.h
toxcore/tox_dispatch.c
toxcore/tox_dispatch.h
toxcore/tox_event.c
toxcore/tox_event.h
toxcore/tox_events.c
toxcore/tox_events.h
toxcore/tox.h
toxcore/tox_log_level.c
toxcore/tox_log_level.h
toxcore/tox_private.c
toxcore/tox_private.h
toxcore/tox_pack.c
Expand All @@ -363,8 +365,9 @@ endif()
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium)
set(toxcore_API_HEADERS
${toxcore_SOURCE_DIR}/toxcore/tox.h^tox
${toxcore_SOURCE_DIR}/toxcore/tox_dispatch.h^tox
${toxcore_SOURCE_DIR}/toxcore/tox_events.h^tox
${toxcore_SOURCE_DIR}/toxcore/tox_dispatch.h^tox)
${toxcore_SOURCE_DIR}/toxcore/tox_log_level.h^tox)
if(EXPERIMENTAL_API)
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
${toxcore_SOURCE_DIR}/toxcore/tox_private.h^tox)
Expand Down
9 changes: 9 additions & 0 deletions toxcore/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test")
exports_files(
srcs = [
"tox.h",
"tox_log_level.h",
"tox_private.h",
],
visibility = ["//c-toxcore:__subpackages__"],
Expand Down Expand Up @@ -980,6 +981,13 @@ cc_library(
],
)

cc_library(
name = "tox_log_level",
srcs = ["tox_log_level.c"],
hdrs = ["tox_log_level.h"],
visibility = ["//c-toxcore:__subpackages__"],
)

cc_library(
name = "tox",
srcs = [
Expand Down Expand Up @@ -1010,6 +1018,7 @@ cc_library(
":network",
":onion_client",
":state",
":tox_log_level",
":util",
"//c-toxcore/toxencryptsave:defines",
"@pthread",
Expand Down
2 changes: 2 additions & 0 deletions toxcore/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ libtoxcore_la_SOURCES = ../third_party/cmp/cmp.c \
../toxcore/tox_event.c \
../toxcore/tox_events.h \
../toxcore/tox_events.c \
../toxcore/tox_log_level.c \
../toxcore/tox_log_level.h \
../toxcore/tox_pack.h \
../toxcore/tox_pack.c \
../toxcore/tox_unpack.h \
Expand Down
36 changes: 2 additions & 34 deletions toxcore/tox.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
#include <stddef.h>
#include <stdint.h>

#include "tox_log_level.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -438,40 +440,6 @@ typedef enum Tox_Savedata_Type {

const char *tox_savedata_type_to_string(Tox_Savedata_Type value);

/**
* @brief Severity level of log messages.
*/
typedef enum Tox_Log_Level {

/**
* Very detailed traces including all network activity.
*/
TOX_LOG_LEVEL_TRACE,

/**
* Debug messages such as which port we bind to.
*/
TOX_LOG_LEVEL_DEBUG,

/**
* Informational log messages such as video call status changes.
*/
TOX_LOG_LEVEL_INFO,

/**
* Warnings about internal inconsistency or logic errors.
*/
TOX_LOG_LEVEL_WARNING,

/**
* Severe unexpected errors caused by external or internal inconsistency.
*/
TOX_LOG_LEVEL_ERROR,

} Tox_Log_Level;

const char *tox_log_level_to_string(Tox_Log_Level value);

/**
* @brief This event is triggered when Tox logs an internal message.
*
Expand Down
21 changes: 0 additions & 21 deletions toxcore/tox_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,27 +378,6 @@ const char *tox_savedata_type_to_string(Tox_Savedata_Type value)

return "<invalid Tox_Savedata_Type>";
}
const char *tox_log_level_to_string(Tox_Log_Level value)
{
switch (value) {
case TOX_LOG_LEVEL_TRACE:
return "TOX_LOG_LEVEL_TRACE";

case TOX_LOG_LEVEL_DEBUG:
return "TOX_LOG_LEVEL_DEBUG";

case TOX_LOG_LEVEL_INFO:
return "TOX_LOG_LEVEL_INFO";

case TOX_LOG_LEVEL_WARNING:
return "TOX_LOG_LEVEL_WARNING";

case TOX_LOG_LEVEL_ERROR:
return "TOX_LOG_LEVEL_ERROR";
}

return "<invalid Tox_Log_Level>";
}
const char *tox_err_options_new_to_string(Tox_Err_Options_New value)
{
switch (value) {
Expand Down
27 changes: 27 additions & 0 deletions toxcore/tox_log_level.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2016-2024 The TokTok team.
* Copyright © 2013 Tox project.
*/
#include "tox_log_level.h"

const char *tox_log_level_to_string(Tox_Log_Level value)
{
switch (value) {
case TOX_LOG_LEVEL_TRACE:
return "TOX_LOG_LEVEL_TRACE";

case TOX_LOG_LEVEL_DEBUG:
return "TOX_LOG_LEVEL_DEBUG";

case TOX_LOG_LEVEL_INFO:
return "TOX_LOG_LEVEL_INFO";

case TOX_LOG_LEVEL_WARNING:
return "TOX_LOG_LEVEL_WARNING";

case TOX_LOG_LEVEL_ERROR:
return "TOX_LOG_LEVEL_ERROR";
}

return "<invalid Tox_Log_Level>";
}
48 changes: 48 additions & 0 deletions toxcore/tox_log_level.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2022-2024 The TokTok team.
*/

#ifndef C_TOXCORE_TOXCORE_TOX_LOG_LEVEL_H
#define C_TOXCORE_TOXCORE_TOX_LOG_LEVEL_H

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Severity level of log messages.
*/
typedef enum Tox_Log_Level {
/**
* Very detailed traces including all network activity.
*/
TOX_LOG_LEVEL_TRACE,

/**
* Debug messages such as which port we bind to.
*/
TOX_LOG_LEVEL_DEBUG,

/**
* Informational log messages such as video call status changes.
*/
TOX_LOG_LEVEL_INFO,

/**
* Warnings about internal inconsistency or logic errors.
*/
TOX_LOG_LEVEL_WARNING,

/**
* Severe unexpected errors caused by external or internal inconsistency.
*/
TOX_LOG_LEVEL_ERROR,
} Tox_Log_Level;

const char *tox_log_level_to_string(Tox_Log_Level value);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* C_TOXCORE_TOXCORE_TOX_LOG_LEVEL_H */
Loading