1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00
srs/trunk/src/protocol/srs_service_log.hpp

78 lines
2.2 KiB
C++
Raw Normal View History

//
// 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:
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);
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:
virtual srs_error_t initialize();
2017-03-26 02:16:21 +00:00
virtual void reopen();
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.
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