1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-24 23:14:19 +00:00
srs/trunk/src/protocol/srs_protocol_log.hpp

77 lines
2.1 KiB
C++
Raw Normal View History

//
2022-06-20 11:22:25 +00:00
// Copyright (c) 2013-2022 The SRS Authors
//
// SPDX-License-Identifier: MIT or MulanPSL-2.0
//
2017-03-26 02:16:21 +00:00
2022-06-09 11:59:51 +00:00
#ifndef SRS_PROTOCOL_LOG_HPP
#define SRS_PROTOCOL_LOG_HPP
2017-03-26 02:16:21 +00:00
#include <srs_core.hpp>
#include <map>
2020-06-18 03:45:43 +00:00
#include <string>
2017-03-26 02:16:21 +00:00
2022-06-09 11:59:51 +00:00
#include <srs_protocol_st.hpp>
2017-03-26 02:16:21 +00:00
#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:
std::map<srs_thread_t, SrsContextId> cache;
2017-03-26 02:16:21 +00:00
public:
SrsThreadContext();
virtual ~SrsThreadContext();
public:
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);
private:
2017-03-26 02:16:21 +00:00
virtual void clear_cid();
};
// Set the context id of specified thread, not self.
extern const SrsContextId& srs_context_set_cid_of(srs_thread_t trd, const SrsContextId& v);
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:
2022-10-25 01:18:33 +00:00
SrsLogLevel level_;
2017-03-26 02:16:21 +00:00
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:
virtual srs_error_t initialize();
2017-03-26 02:16:21 +00:00
virtual void reopen();
2022-10-25 01:18:33 +00:00
virtual void log(SrsLogLevel level, const char* tag, const SrsContextId& context_id, const char* fmt, va_list args);
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.
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