Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2013-10-17 22:09:10 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
67d96fcab422f05bf89241af93be368239ba6267
67d96fca
1 parent
7268dd15
add log
隐藏空白字符变更
内嵌
并排对比
正在显示
6 个修改的文件
包含
153 行增加
和
1 行删除
trunk/configure
trunk/src/core/srs_core.hpp
trunk/src/core/srs_core_log.cpp
trunk/src/core/srs_core_log.hpp
trunk/src/main/srs_main_server.cpp
trunk/src/upp/upp.upp
trunk/configure
查看文件 @
67d96fc
...
...
@@ -81,7 +81,7 @@ LibSTfile="${LibSTRoot}/libst.a"
#Core Module
MODULE_ID
=
"CORE"
MODULE_DEPENDS
=()
ModuleLibIncs
=()
ModuleLibIncs
=(
${
LibSTRoot
}
)
MODULE_FILES
=(
"srs_core_log"
)
MODULE_DIR
=
"src/core"
. auto/modules.sh
CORE_OBJS
=
"
${
MODULE_OBJS
[@]
}
"
...
...
trunk/src/core/srs_core.hpp
0 → 100755
查看文件 @
67d96fc
#ifndef SRS_CORE_HPP
#define SRS_CORE_HPP
/*
#include <srs_core.hpp>
*/
// for int64_t print using PRId64 format.
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#endif
\ No newline at end of file
...
...
trunk/src/core/srs_core_log.cpp
查看文件 @
67d96fc
#include <srs_core_log.hpp>
#include <string.h>
#include <sys/time.h>
#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
*
FormatTime
();
};
private
:
DateTime
time
;
std
::
map
<
st_thread_t
,
int
>
cache
;
public
:
LogContext
();
virtual
~
LogContext
();
public
:
virtual
void
SetId
();
virtual
int
GetId
();
public
:
virtual
const
char
*
FormatTime
();
};
ILogContext
*
log_context
=
new
LogContext
();
LogContext
::
DateTime
::
DateTime
(){
memset
(
time_data
,
0
,
DATE_LEN
);
}
LogContext
::
DateTime
::~
DateTime
(){
}
const
char
*
LogContext
::
DateTime
::
FormatTime
(){
// clock time
timeval
tv
;
if
(
gettimeofday
(
&
tv
,
NULL
)
==
-
1
){
return
""
;
}
// to calendar time
struct
tm
*
tm
;
if
((
tm
=
localtime
(
&
tv
.
tv_sec
))
==
NULL
){
return
""
;
}
// log header, the time/pid/level of log
// reserved 1bytes for the new line.
snprintf
(
time_data
,
DATE_LEN
,
"%d-%02d-%02d %02d:%02d:%02d.%03d"
,
1900
+
tm
->
tm_year
,
1
+
tm
->
tm_mon
,
tm
->
tm_mday
,
tm
->
tm_hour
,
tm
->
tm_min
,
tm
->
tm_sec
,
(
int
)(
tv
.
tv_usec
/
1000
));
return
time_data
;
}
LogContext
::
LogContext
(){
}
LogContext
::~
LogContext
(){
}
void
LogContext
::
SetId
(){
static
int
id
=
0
;
cache
[
st_thread_self
()]
=
id
++
;
}
int
LogContext
::
GetId
(){
return
cache
[
st_thread_self
()];
}
const
char
*
LogContext
::
FormatTime
(){
return
time
.
FormatTime
();
}
...
...
trunk/src/core/srs_core_log.hpp
查看文件 @
67d96fc
#ifndef SRS_CORE_LOG_HPP
#define SRS_CORE_LOG_HPP
/*
#include <srs_core_log.hpp>
*/
#include <srs_core.hpp>
#include <stdio.h>
#include <errno.h>
#include <string.h>
class
ILogContext
{
public
:
ILogContext
();
virtual
~
ILogContext
();
public
:
virtual
void
SetId
()
=
0
;
virtual
int
GetId
()
=
0
;
public
:
virtual
const
char
*
FormatTime
()
=
0
;
};
// user must implements the LogContext and define a global instance.
extern
ILogContext
*
log_context
;
#if 0
#define SrsVerbose(msg, ...) printf("[%s][%d][verbs] ", log_context->FormatTime(), log_context->GetId());printf(msg, ##__VA_ARGS__);printf("\n")
#define SrsInfo(msg, ...) printf("[%s][%d][infos] ", log_context->FormatTime(), log_context->GetId());printf(msg, ##__VA_ARGS__);printf("\n")
#define SrsTrace(msg, ...) printf("[%s][%d][trace] ", log_context->FormatTime(), log_context->GetId());printf(msg, ##__VA_ARGS__);printf("\n")
#define SrsWarn(msg, ...) printf("[%s][%d][warns] ", log_context->FormatTime(), log_context->GetId());printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
#define SrsError(msg, ...) printf("[%s][%d][error] ", log_context->FormatTime(), log_context->GetId());printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
#else
#define SrsVerbose(msg, ...) printf("[%s][%d][verbs][%s] ", log_context->FormatTime(), log_context->GetId(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
#define SrsInfo(msg, ...) printf("[%s][%d][infos][%s] ", log_context->FormatTime(), log_context->GetId(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
#define SrsTrace(msg, ...) printf("[%s][%d][trace][%s] ", log_context->FormatTime(), log_context->GetId(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
#define SrsWarn(msg, ...) printf("[%s][%d][warns][%s] ", log_context->FormatTime(), log_context->GetId(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
#define SrsError(msg, ...) printf("[%s][%d][error][%s] ", log_context->FormatTime(), log_context->GetId(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
#endif
#endif
...
...
trunk/src/main/srs_main_server.cpp
查看文件 @
67d96fc
#include <unistd.h>
#include <srs_core_log.hpp>
int
main
(
int
/*argc*/
,
char
**
/*argv*/
){
log_context
->
SetId
();
SrsWarn
(
"server start"
);
return
0
;
}
...
...
trunk/src/upp/upp.upp
查看文件 @
67d96fc
...
...
@@ -2,6 +2,7 @@ file
main readonly separator,
..\main\srs_main_server.cpp,
core readonly separator,
..\core\srs_core.hpp,
..\core\srs_core_log.hpp,
..\core\srs_core_log.cpp;
mainconfig
...
...
请
注册
或
登录
后发表评论