2021-05-31 05:42:20 +00:00
|
|
|
//
|
|
|
|
// Copyright (c) 2013-2021 Winlin
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//
|
2017-03-26 02:16:21 +00:00
|
|
|
|
|
|
|
#ifndef SRS_SERVICE_LOG_HPP
|
|
|
|
#define SRS_SERVICE_LOG_HPP
|
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
|
|
|
#include <map>
|
2020-06-18 03:45:43 +00:00
|
|
|
#include <string>
|
2017-03-26 02:16:21 +00:00
|
|
|
|
|
|
|
#include <srs_service_st.hpp>
|
|
|
|
#include <srs_kernel_log.hpp>
|
|
|
|
|
2019-04-28 00:21:48 +00:00
|
|
|
// The st thread context, get_id will get the st-thread id,
|
|
|
|
// which identify the client.
|
2020-06-25 05:14:59 +00:00
|
|
|
class SrsThreadContext : public ISrsContext
|
2017-03-26 02:16:21 +00:00
|
|
|
{
|
|
|
|
private:
|
2020-07-05 15:26:55 +00:00
|
|
|
std::map<srs_thread_t, SrsContextId> cache;
|
2017-03-26 02:16:21 +00:00
|
|
|
public:
|
|
|
|
SrsThreadContext();
|
|
|
|
virtual ~SrsThreadContext();
|
|
|
|
public:
|
2020-07-05 15:26:55 +00:00
|
|
|
virtual SrsContextId generate_id();
|
2020-07-13 03:19:34 +00:00
|
|
|
virtual const SrsContextId& get_id();
|
|
|
|
virtual const SrsContextId& set_id(const SrsContextId& v);
|
2017-03-26 02:16:21 +00:00
|
|
|
public:
|
|
|
|
virtual void clear_cid();
|
|
|
|
};
|
|
|
|
|
2020-07-13 05:52:23 +00:00
|
|
|
// The context restore stores the context and restore it when done.
|
|
|
|
// Usage:
|
|
|
|
// SrsContextRestore(_srs_context->get_id());
|
2020-07-22 06:27:03 +00:00
|
|
|
#define SrsContextRestore(cid) impl_SrsContextRestore _context_restore_instance(cid)
|
2020-07-13 05:52:23 +00:00
|
|
|
class impl_SrsContextRestore
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
SrsContextId cid_;
|
|
|
|
public:
|
|
|
|
impl_SrsContextRestore(SrsContextId cid);
|
|
|
|
virtual ~impl_SrsContextRestore();
|
|
|
|
};
|
|
|
|
|
2019-04-28 00:21:48 +00:00
|
|
|
// The basic console log, which write log to console.
|
2017-03-26 02:16:21 +00:00
|
|
|
class SrsConsoleLog : public ISrsLog
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
SrsLogLevel level;
|
|
|
|
bool utc;
|
|
|
|
private:
|
|
|
|
char* buffer;
|
|
|
|
public:
|
|
|
|
SrsConsoleLog(SrsLogLevel l, bool u);
|
|
|
|
virtual ~SrsConsoleLog();
|
2019-04-30 00:30:13 +00:00
|
|
|
// Interface ISrsLog
|
2017-03-26 02:16:21 +00:00
|
|
|
public:
|
2017-06-11 06:03:19 +00:00
|
|
|
virtual srs_error_t initialize();
|
2017-03-26 02:16:21 +00:00
|
|
|
virtual void reopen();
|
2020-07-05 15:26:55 +00:00
|
|
|
virtual void verbose(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
|
|
|
virtual void info(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
|
|
|
virtual void trace(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
|
|
|
virtual void warn(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
|
|
|
virtual void error(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
2017-03-26 02:16:21 +00:00
|
|
|
};
|
|
|
|
|
2019-04-28 00:21:48 +00:00
|
|
|
// Generate the log header.
|
|
|
|
// @param dangerous Whether log is warning or error, log the errno if true.
|
|
|
|
// @param utc Whether use UTC time format in the log header.
|
|
|
|
// @param psize Output the actual header size.
|
|
|
|
// @remark It's a internal API.
|
2020-07-05 15:26:55 +00:00
|
|
|
bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char* tag, SrsContextId cid, const char* level, int* psize);
|
2017-03-26 02:16:21 +00:00
|
|
|
|
|
|
|
#endif
|