diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-08-19 13:07:45 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-08-27 01:16:14 +0100 |
commit | 13ae9e9a93a1c02fad9475002c0391b86b7ad7bb (patch) | |
tree | a9575d3582c4f40e051c93ae18dded03fdddc432 /toxcore/tox.h | |
parent | 1f25fc0ae417bfc47dea4966cb5e43689aa88d5c (diff) |
Move logging to a callback.
This removes the global logger (which by the way was deleted when the first tox
was killed, so other toxes would then stop logging). Various bits of the code
now carry a logger or pass it around. It's a bit less transparent now, but now
there is no need to have a global logger, and clients can decide what to log and
where.
Diffstat (limited to 'toxcore/tox.h')
-rw-r--r-- | toxcore/tox.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/toxcore/tox.h b/toxcore/tox.h index 16e83207..7838f1cb 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -654,6 +654,66 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error); | |||
654 | void tox_kill(Tox *tox); | 654 | void tox_kill(Tox *tox); |
655 | 655 | ||
656 | /** | 656 | /** |
657 | * Severity level of log messages. | ||
658 | */ | ||
659 | typedef enum TOX_LOG_LEVEL { | ||
660 | |||
661 | /** | ||
662 | * Very detailed traces including all network activity. | ||
663 | */ | ||
664 | TOX_LOG_LEVEL_LOG_TRACE, | ||
665 | |||
666 | /** | ||
667 | * Debug messages such as which port we bind to. | ||
668 | */ | ||
669 | TOX_LOG_LEVEL_LOG_DEBUG, | ||
670 | |||
671 | /** | ||
672 | * Informational log messages such as video call status changes. | ||
673 | */ | ||
674 | TOX_LOG_LEVEL_LOG_INFO, | ||
675 | |||
676 | /** | ||
677 | * Warnings about internal inconsistency or logic errors. | ||
678 | */ | ||
679 | TOX_LOG_LEVEL_LOG_WARNING, | ||
680 | |||
681 | /** | ||
682 | * Severe unexpected errors caused by external or internal inconsistency. | ||
683 | */ | ||
684 | TOX_LOG_LEVEL_LOG_ERROR, | ||
685 | |||
686 | } TOX_LOG_LEVEL; | ||
687 | |||
688 | |||
689 | /** | ||
690 | * @param level The severity of the log message. | ||
691 | * @param file The source file from which the message originated. | ||
692 | * @param line The source line from which the message originated. | ||
693 | * @param func The function from which the message originated. | ||
694 | * @param message The log message. | ||
695 | */ | ||
696 | typedef void tox_log_cb(Tox *tox, TOX_LOG_LEVEL level, const char *file, uint32_t line, const char *func, | ||
697 | const char *message, void *user_data); | ||
698 | |||
699 | |||
700 | /** | ||
701 | * Set the callback for the `log` event. Pass NULL to unset. | ||
702 | * | ||
703 | * This event is triggered when the toxcore library logs an internal message. | ||
704 | * This is mostly useful for debugging. This callback can be called from any | ||
705 | * function, not just tox_iterate. This means the user data lifetime must at | ||
706 | * least extend between registering and unregistering it or tox_kill. | ||
707 | * | ||
708 | * Other toxcore modules such as toxav may concurrently call this callback at | ||
709 | * any time. Thus, user code must make sure it is equipped to handle concurrent | ||
710 | * execution, e.g. by employing appropriate mutex locking. The callback | ||
711 | * registration function must not be called during execution of any other Tox | ||
712 | * library function (toxcore or toxav). | ||
713 | */ | ||
714 | void tox_callback_log(Tox *tox, tox_log_cb *callback, void *user_data); | ||
715 | |||
716 | /** | ||
657 | * Calculates the number of bytes required to store the tox instance with | 717 | * Calculates the number of bytes required to store the tox instance with |
658 | * tox_get_savedata. This function cannot fail. The result is always greater than 0. | 718 | * tox_get_savedata. This function cannot fail. The result is always greater than 0. |
659 | * | 719 | * |