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

84 lines
3 KiB
C++
Raw Normal View History

2017-03-25 09:21:39 +00:00
/**
* The MIT License (MIT)
*
2021-04-16 01:25:55 +00:00
* Copyright (c) 2013-2021 Winlin
2017-03-25 09:21:39 +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.
*/
2014-03-01 10:06:20 +00:00
#ifndef SRS_APP_LOG_HPP
#define SRS_APP_LOG_HPP
2014-03-01 10:06:20 +00:00
#include <srs_core.hpp>
#include <string.h>
#include <string>
2017-03-26 02:16:21 +00:00
#include <srs_app_reload.hpp>
#include <srs_service_log.hpp>
2014-03-01 10:06:20 +00:00
2020-09-17 08:25:24 +00:00
// For log TAGs.
#define TAG_MAIN "MAIN"
#define TAG_MAYBE "MAYBE"
#define TAG_DTLS_ALERT "DTLS_ALERT"
#define TAG_DTLS_HANG "DTLS_HANG"
#define TAG_RESOURCE_UNSUB "RESOURCE_UNSUB"
2020-12-23 07:13:21 +00:00
#define TAG_LARGE_TIMER "LARGE_TIMER"
2020-09-17 08:25:24 +00:00
2019-04-30 00:24:52 +00:00
// Use memory/disk cache and donot flush when write log.
// it's ok to use it without config, which will log to console, and default trace level.
// when you want to use different level, override this classs, set the protected _level.
2020-06-25 05:14:59 +00:00
class SrsFileLog : public ISrsLog, public ISrsReloadHandler
2014-03-01 10:06:20 +00:00
{
2019-04-30 00:24:52 +00:00
private:
// Defined in SrsLogLevel.
2017-03-26 02:16:21 +00:00
SrsLogLevel level;
private:
2014-03-01 10:06:20 +00:00
char* log_data;
2019-04-30 00:24:52 +00:00
// Log to file if specified srs_log_file
int fd;
2019-04-30 00:24:52 +00:00
// Whether log to file tank
2014-04-12 13:35:26 +00:00
bool log_to_file_tank;
2019-04-30 00:24:52 +00:00
// Whether use utc time.
2015-09-09 15:37:07 +00:00
bool utc;
2014-03-01 10:06:20 +00:00
public:
2020-06-25 05:14:59 +00:00
SrsFileLog();
virtual ~SrsFileLog();
2019-04-30 00:30:13 +00:00
// Interface ISrsLog
2014-03-01 10:06:20 +00:00
public:
virtual srs_error_t initialize();
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, ...);
2019-04-30 00:30:13 +00:00
// Interface ISrsReloadHandler.
2014-04-12 13:35:26 +00:00
public:
virtual srs_error_t on_reload_utc_time();
2017-09-22 08:14:30 +00:00
virtual srs_error_t on_reload_log_tank();
virtual srs_error_t on_reload_log_level();
virtual srs_error_t on_reload_log_file();
2014-03-01 10:06:20 +00:00
private:
2014-04-12 13:35:26 +00:00
virtual void write_log(int& fd, char* str_log, int size, int level);
virtual void open_log_file();
2014-03-01 10:06:20 +00:00
};
#endif
2014-08-02 14:18:39 +00:00