1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 03:41:55 +00:00

extract log context, move log to kernel module.

This commit is contained in:
winlin 2014-03-01 10:42:55 +08:00
parent dea66a322d
commit 39d3425691
26 changed files with 141 additions and 81 deletions

6
trunk/configure vendored
View file

@ -133,7 +133,7 @@ CORE_OBJS="${MODULE_OBJS[@]}"
MODULE_ID="KERNEL"
MODULE_DEPENDS=("CORE")
ModuleLibIncs=(${SRS_OBJS})
MODULE_FILES=("srs_kernel_error")
MODULE_FILES=("srs_kernel_error" "srs_kernel_log")
MODULE_DIR="src/kernel" . auto/modules.sh
KERNEL_OBJS="${MODULE_OBJS[@]}"
#
@ -141,7 +141,7 @@ KERNEL_OBJS="${MODULE_OBJS[@]}"
MODULE_ID="APP"
MODULE_DEPENDS=("CORE" "KERNEL")
ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${LibSSLRoot} ${SRS_OBJS})
MODULE_FILES=("srs_core_log" "srs_core_server"
MODULE_FILES=("srs_core_server"
"srs_core_conn" "srs_core_client"
"srs_core_rtmp" "srs_core_socket" "srs_core_buffer"
"srs_core_protocol" "srs_core_amf0"
@ -150,7 +150,7 @@ MODULE_FILES=("srs_core_log" "srs_core_server"
"srs_core_config" "srs_core_refer" "srs_core_reload"
"srs_core_hls" "srs_core_forward" "srs_core_encoder"
"srs_core_http" "srs_core_thread" "srs_core_bandwidth"
"srs_core_st")
"srs_core_st" "srs_core_log_context")
MODULE_DIR="src/app" . auto/modules.sh
APP_OBJS="${MODULE_OBJS[@]}"
#

View file

@ -25,7 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <utility>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_core_stream.hpp>

View file

@ -25,7 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_error.hpp>
#include <srs_core_socket.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#define SOCKET_READ_SIZE 4096

View file

@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using namespace std;
#include <srs_kernel_error.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_core_rtmp.hpp>
#include <srs_core_protocol.hpp>
#include <srs_core_autofree.hpp>

View file

@ -28,7 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_error.hpp>
#include <srs_core_stream.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_core_autofree.hpp>
SrsCodecBuffer::SrsCodecBuffer()

View file

@ -38,7 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using namespace std;
#include <srs_kernel_error.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_core_autofree.hpp>
#define FILE_OFFSET(fd) lseek(fd, 0, SEEK_CUR)

View file

@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_conn.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_core_server.hpp>

View file

@ -33,7 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <algorithm>
#include <srs_kernel_error.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_core_config.hpp>
#include <srs_core_rtmp.hpp>
#include <srs_core_pithy_print.hpp>

View file

@ -30,7 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_error.hpp>
#include <srs_core_rtmp.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_core_protocol.hpp>
#include <srs_core_pithy_print.hpp>
#include <srs_core_rtmp.hpp>

View file

@ -27,7 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <stdlib.h>
#include <srs_kernel_error.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_core_autofree.hpp>
#include <srs_core_socket.hpp>

View file

@ -34,7 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_error.hpp>
#include <srs_core_rtmp.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_core_socket.hpp>
#define SRS_DEFAULT_HTTP_PORT 80

View file

@ -21,64 +21,20 @@ 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.
*/
#include <srs_core_log.hpp>
#include <srs_core_log_context.hpp>
#include <string.h>
#include <sys/time.h>
ILogContext* log_context = new SrsLogContext();
#include <string>
#include <map>
#include <st.h>
ILogContext::ILogContext()
{
}
ILogContext::~ILogContext()
{
}
class LogContext : public ILogContext
{
private:
class DateTime
{
private:
// %d-%02d-%02d %02d:%02d:%02d.%03d
#define DATE_LEN 24
char time_data[DATE_LEN];
public:
DateTime();
virtual ~DateTime();
public:
virtual const char* format_time();
};
private:
DateTime time;
std::map<st_thread_t, int> cache;
public:
LogContext();
virtual ~LogContext();
public:
virtual void generate_id();
virtual int get_id();
public:
virtual const char* format_time();
};
ILogContext* log_context = new LogContext();
LogContext::DateTime::DateTime()
SrsLogContext::DateTime::DateTime()
{
memset(time_data, 0, DATE_LEN);
}
LogContext::DateTime::~DateTime()
SrsLogContext::DateTime::~DateTime()
{
}
const char* LogContext::DateTime::format_time()
const char* SrsLogContext::DateTime::format_time()
{
// clock time
timeval tv;
@ -100,27 +56,26 @@ const char* LogContext::DateTime::format_time()
return time_data;
}
LogContext::LogContext()
SrsLogContext::SrsLogContext()
{
}
LogContext::~LogContext()
SrsLogContext::~SrsLogContext()
{
}
void LogContext::generate_id()
void SrsLogContext::generate_id()
{
static int id = 1;
cache[st_thread_self()] = id++;
}
int LogContext::get_id()
int SrsLogContext::get_id()
{
return cache[st_thread_self()];
}
const char* LogContext::format_time()
const char* SrsLogContext::format_time()
{
return time.format_time();
}

View file

@ -0,0 +1,70 @@
/*
The MIT License (MIT)
Copyright (c) 2013-2014 winlin
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_CORE_LOG_CONTEXT_HPP
#define SRS_CORE_LOG_CONTEXT_HPP
/*
#include <srs_core_log_context.hpp>
*/
#include <srs_core.hpp>
#include <srs_core_st.hpp>
#include <srs_kernel_log.hpp>
#include <string.h>
#include <sys/time.h>
#include <string>
#include <map>
class SrsLogContext : public ILogContext
{
private:
class DateTime
{
private:
// %d-%02d-%02d %02d:%02d:%02d.%03d
#define DATE_LEN 24
char time_data[DATE_LEN];
public:
DateTime();
virtual ~DateTime();
public:
virtual const char* format_time();
};
private:
DateTime time;
std::map<st_thread_t, int> cache;
public:
SrsLogContext();
virtual ~SrsLogContext();
public:
virtual void generate_id();
virtual int get_id();
public:
virtual const char* format_time();
};
#endif

View file

@ -26,7 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <stdlib.h>
#include <map>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_core_config.hpp>
#include <srs_core_reload.hpp>
#include <srs_kernel_error.hpp>

View file

@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_protocol.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_core_amf0.hpp>
#include <srs_kernel_error.hpp>
#include <srs_core_socket.hpp>

View file

@ -34,7 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <string>
#include <srs_core_st.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
// the following is the timeout for rtmp protocol,

View file

@ -24,7 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_refer.hpp>
#include <srs_kernel_error.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_core_config.hpp>
int SrsRefer::check(std::string page_url, SrsConfDirective* refer)

View file

@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_rtmp.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_core_socket.hpp>
#include <srs_core_protocol.hpp>

View file

@ -30,7 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <algorithm>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_core_client.hpp>
#include <srs_core_config.hpp>

View file

@ -26,7 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <algorithm>
using namespace std;
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_core_protocol.hpp>
#include <srs_core_autofree.hpp>
#include <srs_core_amf0.hpp>

View file

@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_stream.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
SrsStream::SrsStream()

View file

@ -24,7 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_thread.hpp>
#include <srs_kernel_error.hpp>
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
ISrsThreadHandler::ISrsThreadHandler()
{

View file

@ -0,0 +1,33 @@
/*
The MIT License (MIT)
Copyright (c) 2013-2014 winlin
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.
*/
#include <srs_kernel_log.hpp>
ILogContext::ILogContext()
{
}
ILogContext::~ILogContext()
{
}

View file

@ -25,7 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define SRS_CORE_LOG_HPP
/*
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
*/
#include <srs_core.hpp>

View file

@ -21,7 +21,7 @@ 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.
*/
#include <srs_core_log.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_core_server.hpp>
#include <srs_core_config.hpp>

View file

@ -12,6 +12,8 @@ file
kernel readonly separator,
..\kernel\srs_kernel_error.hpp,
..\kernel\srs_kernel_error.cpp,
..\kernel\srs_kernel_log.hpp,
..\kernel\srs_kernel_log.cpp,
app readonly separator,
..\app\srs_core_amf0.hpp,
..\app\srs_core_amf0.cpp,
@ -37,8 +39,8 @@ file
..\app\srs_core_hls.cpp,
..\app\srs_core_http.hpp,
..\app\srs_core_http.cpp,
..\app\srs_core_log.hpp,
..\app\srs_core_log.cpp,
..\app\srs_core_log_context.hpp,
..\app\srs_core_log_context.cpp,
..\app\srs_core_pithy_print.hpp,
..\app\srs_core_pithy_print.cpp,
..\app\srs_core_protocol.hpp,