mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
use fast log
This commit is contained in:
parent
382fd127e4
commit
7d570fb4f3
23 changed files with 517 additions and 273 deletions
|
@ -35,43 +35,78 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
// the context for multiple clients.
|
||||
class ILogContext
|
||||
/**
|
||||
* the log interface provides method to write log.
|
||||
* but we provides some macro, which enable us to disable the log when compile.
|
||||
* @see also SmtDebug/SmtTrace/SmtWarn/SmtError which is corresponding to Debug/Trace/Warn/Fatal.
|
||||
*/
|
||||
class ISrsLog
|
||||
{
|
||||
public:
|
||||
ILogContext();
|
||||
virtual ~ILogContext();
|
||||
ISrsLog();
|
||||
virtual ~ISrsLog();
|
||||
public:
|
||||
virtual void generate_id() = 0;
|
||||
virtual int get_id() = 0;
|
||||
public:
|
||||
virtual const char* format_time() = 0;
|
||||
/**
|
||||
* log for verbose, very verbose information.
|
||||
*/
|
||||
virtual void verbose(const char* tag, int context_id, const char* fmt, ...);
|
||||
/**
|
||||
* log for debug, detail information.
|
||||
*/
|
||||
virtual void info(const char* tag, int context_id, const char* fmt, ...);
|
||||
/**
|
||||
* log for trace, important information.
|
||||
*/
|
||||
virtual void trace(const char* tag, int context_id, const char* fmt, ...);
|
||||
/**
|
||||
* log for warn, warn is something should take attention, but not a error.
|
||||
*/
|
||||
virtual void warn(const char* tag, int context_id, const char* fmt, ...);
|
||||
/**
|
||||
* log for error, something error occur, do something about the error, ie. close the connection,
|
||||
* but we will donot abort the program.
|
||||
*/
|
||||
virtual void error(const char* tag, int context_id, const char* fmt, ...);
|
||||
};
|
||||
|
||||
// the context for multiple clients.
|
||||
class ISrsThreadContext
|
||||
{
|
||||
public:
|
||||
ISrsThreadContext();
|
||||
virtual ~ISrsThreadContext();
|
||||
public:
|
||||
virtual void generate_id();
|
||||
virtual int get_id();
|
||||
};
|
||||
|
||||
// user must provides a log object
|
||||
extern ISrsLog* _srs_log;
|
||||
|
||||
// user must implements the LogContext and define a global instance.
|
||||
extern ILogContext* log_context;
|
||||
extern ISrsThreadContext* _srs_context;
|
||||
|
||||
// donot print method
|
||||
#if 0
|
||||
#define srs_verbose(msg, ...) printf("[%s][%d][verbs] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n")
|
||||
#define srs_info(msg, ...) printf("[%s][%d][infos] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n")
|
||||
#define srs_trace(msg, ...) printf("[%s][%d][trace] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n")
|
||||
#define srs_warn(msg, ...) printf("[%s][%d][warns] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
||||
#define srs_error(msg, ...) printf("[%s][%d][error] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
||||
#if 1
|
||||
#define srs_verbose(msg, ...) _srs_log->verbose(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_info(msg, ...) _srs_log->info(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_trace(msg, ...) _srs_log->trace(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_warn(msg, ...) _srs_log->warn(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_error(msg, ...) _srs_log->error(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
// use __FUNCTION__ to print c method
|
||||
#elif 1
|
||||
#define srs_verbose(msg, ...) printf("[%s][%d][verbs][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
||||
#define srs_info(msg, ...) printf("[%s][%d][infos][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
||||
#define srs_trace(msg, ...) printf("[%s][%d][trace][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
||||
#define srs_warn(msg, ...) printf("[%s][%d][warns][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
||||
#define srs_error(msg, ...) printf("[%s][%d][error][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
||||
#elif 0
|
||||
#define srs_verbose(msg, ...) _srs_log->verbose(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_info(msg, ...) _srs_log->info(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_trace(msg, ...) _srs_log->trace(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_warn(msg, ...) _srs_log->warn(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_error(msg, ...) _srs_log->error(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
// use __PRETTY_FUNCTION__ to print c++ class:method
|
||||
#else
|
||||
#define srs_verbose(msg, ...) printf("[%s][%d][verbs][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
||||
#define srs_info(msg, ...) printf("[%s][%d][infos][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
||||
#define srs_trace(msg, ...) printf("[%s][%d][trace][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
||||
#define srs_warn(msg, ...) printf("[%s][%d][warns][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
||||
#define srs_error(msg, ...) printf("[%s][%d][error][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
||||
#define srs_verbose(msg, ...) _srs_log->verbose(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_info(msg, ...) _srs_log->info(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_trace(msg, ...) _srs_log->trace(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_warn(msg, ...) _srs_log->warn(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_error(msg, ...) _srs_log->error(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue