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

95 lines
3.2 KiB
C++
Raw Normal View History

2017-03-26 02:16:21 +00:00
/**
* The MIT License (MIT)
*
2021-04-16 01:29:43 +00:00
* Copyright (c) 2013-2021 Winlin
2017-03-26 02:16:21 +00:00
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#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