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
2014-04-12 21:35:26 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
eda1ddc03ddad63c46508038abecc6314001d28d
eda1ddc0
1 parent
f652c284
support reload log level/logfile/tank
显示空白字符变更
内嵌
并排对比
正在显示
8 个修改的文件
包含
143 行增加
和
37 行删除
trunk/src/app/srs_app_config.cpp
trunk/src/app/srs_app_log.cpp
trunk/src/app/srs_app_log.hpp
trunk/src/app/srs_app_reload.cpp
trunk/src/app/srs_app_reload.hpp
trunk/src/kernel/srs_kernel_log.cpp
trunk/src/kernel/srs_kernel_log.hpp
trunk/src/main/srs_main_server.cpp
trunk/src/app/srs_app_config.cpp
查看文件 @
eda1ddc
...
...
@@ -517,6 +517,42 @@ int SrsConfig::reload()
srs_trace
(
"reload pid success."
);
}
// merge config: srs_log_tank
if
(
!
srs_directive_equals
(
root
->
get
(
"srs_log_tank"
),
old_root
->
get
(
"srs_log_tank"
)))
{
for
(
it
=
subscribes
.
begin
();
it
!=
subscribes
.
end
();
++
it
)
{
ISrsReloadHandler
*
subscribe
=
*
it
;
if
((
ret
=
subscribe
->
on_reload_log_tank
())
!=
ERROR_SUCCESS
)
{
srs_error
(
"notify subscribes reload srs_log_tank failed. ret=%d"
,
ret
);
return
ret
;
}
}
srs_trace
(
"reload srs_log_tank success."
);
}
// merge config: srs_log_level
if
(
!
srs_directive_equals
(
root
->
get
(
"srs_log_level"
),
old_root
->
get
(
"srs_log_level"
)))
{
for
(
it
=
subscribes
.
begin
();
it
!=
subscribes
.
end
();
++
it
)
{
ISrsReloadHandler
*
subscribe
=
*
it
;
if
((
ret
=
subscribe
->
on_reload_log_level
())
!=
ERROR_SUCCESS
)
{
srs_error
(
"notify subscribes reload srs_log_level failed. ret=%d"
,
ret
);
return
ret
;
}
}
srs_trace
(
"reload srs_log_level success."
);
}
// merge config: srs_log_file
if
(
!
srs_directive_equals
(
root
->
get
(
"srs_log_file"
),
old_root
->
get
(
"srs_log_file"
)))
{
for
(
it
=
subscribes
.
begin
();
it
!=
subscribes
.
end
();
++
it
)
{
ISrsReloadHandler
*
subscribe
=
*
it
;
if
((
ret
=
subscribe
->
on_reload_log_file
())
!=
ERROR_SUCCESS
)
{
srs_error
(
"notify subscribes reload srs_log_file failed. ret=%d"
,
ret
);
return
ret
;
}
}
srs_trace
(
"reload srs_log_file success."
);
}
// directly supported for reload:
// chunk_size, ff_log_dir
...
...
trunk/src/app/srs_app_log.cpp
查看文件 @
eda1ddc
...
...
@@ -32,6 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_app_config.hpp>
#include <srs_kernel_error.hpp>
#include <srs_app_utility.hpp>
SrsThreadContext
::
SrsThreadContext
()
{
...
...
@@ -66,6 +67,7 @@ SrsFastLog::SrsFastLog()
log_data
=
new
char
[
LOG_MAX_SIZE
];
fd
=
-
1
;
log_to_file_tank
=
false
;
}
SrsFastLog
::~
SrsFastLog
()
...
...
@@ -76,22 +78,20 @@ SrsFastLog::~SrsFastLog()
::
close
(
fd
);
fd
=
-
1
;
}
_srs_config
->
unsubscribe
(
this
);
}
int
SrsFastLog
::
initialize
()
{
// TODO: support reload.
return
ERROR_SUCCESS
;
}
int
ret
=
ERROR_SUCCESS
;
int
SrsFastLog
::
level
()
{
return
_level
;
}
_srs_config
->
subscribe
(
this
);
void
SrsFastLog
::
set_level
(
int
level
)
{
_level
=
level
;
log_to_file_tank
=
_srs_config
->
get_srs_log_tank_file
();
_level
=
srs_get_log_level
(
_srs_config
->
get_srs_log_level
());
return
ret
;
}
void
SrsFastLog
::
verbose
(
const
char
*
tag
,
int
context_id
,
const
char
*
fmt
,
...)
...
...
@@ -197,6 +197,54 @@ void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...)
write_log
(
fd
,
log_data
,
size
,
SrsLogLevel
::
Error
);
}
int
SrsFastLog
::
on_reload_log_tank
()
{
int
ret
=
ERROR_SUCCESS
;
bool
tank
=
log_to_file_tank
;
log_to_file_tank
=
_srs_config
->
get_srs_log_tank_file
();
if
(
tank
)
{
return
ret
;
}
if
(
!
log_to_file_tank
)
{
return
ret
;
}
if
(
fd
>
0
)
{
::
close
(
fd
);
}
open_log_file
();
return
ret
;
}
int
SrsFastLog
::
on_reload_log_level
()
{
int
ret
=
ERROR_SUCCESS
;
_level
=
srs_get_log_level
(
_srs_config
->
get_srs_log_level
());
return
ret
;
}
int
SrsFastLog
::
on_reload_log_file
()
{
int
ret
=
ERROR_SUCCESS
;
if
(
!
log_to_file_tank
)
{
return
ret
;
}
if
(
fd
>
0
)
{
::
close
(
fd
);
}
open_log_file
();
return
ret
;
}
bool
SrsFastLog
::
generate_header
(
const
char
*
tag
,
int
context_id
,
const
char
*
level_name
,
int
*
header_size
)
{
// clock time
...
...
@@ -247,7 +295,8 @@ void SrsFastLog::write_log(int& fd, char *str_log, int size, int level)
str_log
[
size
++
]
=
LOG_TAIL
;
str_log
[
size
++
]
=
0
;
if
(
fd
<
0
||
!
_srs_config
->
get_srs_log_tank_file
())
{
// if not to file, to console and return.
if
(
!
log_to_file_tank
)
{
// if is error msg, then print color msg.
// \033[31m : red text code in shell
// \033[32m : green text code in shell
...
...
@@ -260,12 +309,29 @@ void SrsFastLog::write_log(int& fd, char *str_log, int size, int level)
}
else
{
printf
(
"
\033
[31m%s
\033
[0m"
,
str_log
);
}
return
;
}
// open log file. if specified
if
(
!
_srs_config
->
get_srs_log_file
().
empty
()
&&
fd
<
0
)
{
if
(
fd
<
0
)
{
open_log_file
();
}
// write log to file.
if
(
fd
>
0
)
{
::
write
(
fd
,
str_log
,
size
);
}
}
void
SrsFastLog
::
open_log_file
()
{
std
::
string
filename
=
_srs_config
->
get_srs_log_file
();
if
(
filename
.
empty
())
{
return
;
}
fd
=
::
open
(
filename
.
c_str
(),
O_RDWR
|
O_APPEND
);
if
(
fd
==
-
1
&&
errno
==
ENOENT
)
{
...
...
@@ -274,10 +340,4 @@ void SrsFastLog::write_log(int& fd, char *str_log, int size, int level)
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IWGRP
|
S_IROTH
);
}
}
// write log to file.
if
(
fd
>
0
&&
_srs_config
->
get_srs_log_tank_file
())
{
::
write
(
fd
,
str_log
,
size
);
}
}
...
...
trunk/src/app/srs_app_log.hpp
查看文件 @
eda1ddc
...
...
@@ -32,6 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_app_st.hpp>
#include <srs_kernel_log.hpp>
#include <srs_app_reload.hpp>
#include <string.h>
...
...
@@ -57,7 +58,7 @@ public:
/**
* we use memory/disk cache and donot flush when write log.
*/
class
SrsFastLog
:
public
ISrsLog
class
SrsFastLog
:
public
ISrsLog
,
public
ISrsReloadHandler
{
private
:
// defined in SrsLogLevel.
...
...
@@ -65,21 +66,27 @@ private:
char
*
log_data
;
// log to file if specified srs_log_file
int
fd
;
// whether log to file tank
bool
log_to_file_tank
;
public
:
SrsFastLog
();
virtual
~
SrsFastLog
();
public
:
virtual
int
initialize
();
virtual
int
level
();
virtual
void
set_level
(
int
level
);
virtual
void
verbose
(
const
char
*
tag
,
int
context_id
,
const
char
*
fmt
,
...);
virtual
void
info
(
const
char
*
tag
,
int
context_id
,
const
char
*
fmt
,
...);
virtual
void
trace
(
const
char
*
tag
,
int
context_id
,
const
char
*
fmt
,
...);
virtual
void
warn
(
const
char
*
tag
,
int
context_id
,
const
char
*
fmt
,
...);
virtual
void
error
(
const
char
*
tag
,
int
context_id
,
const
char
*
fmt
,
...);
// interface ISrsThreadHandler.
public:
virtual
int
on_reload_log_tank
();
virtual
int
on_reload_log_level
();
virtual
int
on_reload_log_file
();
private
:
virtual
bool
generate_header
(
const
char
*
tag
,
int
context_id
,
const
char
*
level_name
,
int
*
header_size
);
static
void
write_log
(
int
&
fd
,
char
*
str_log
,
int
size
,
int
level
);
virtual
void
write_log
(
int
&
fd
,
char
*
str_log
,
int
size
,
int
level
);
virtual
void
open_log_file
();
};
#endif
...
...
trunk/src/app/srs_app_reload.cpp
查看文件 @
eda1ddc
...
...
@@ -45,6 +45,21 @@ int ISrsReloadHandler::on_reload_pid()
return
ERROR_SUCCESS
;
}
int
ISrsReloadHandler
::
on_reload_log_tank
()
{
return
ERROR_SUCCESS
;
}
int
ISrsReloadHandler
::
on_reload_log_level
()
{
return
ERROR_SUCCESS
;
}
int
ISrsReloadHandler
::
on_reload_log_file
()
{
return
ERROR_SUCCESS
;
}
int
ISrsReloadHandler
::
on_reload_pithy_print
()
{
return
ERROR_SUCCESS
;
...
...
trunk/src/app/srs_app_reload.hpp
查看文件 @
eda1ddc
...
...
@@ -43,6 +43,9 @@ public:
public
:
virtual
int
on_reload_listen
();
virtual
int
on_reload_pid
();
virtual
int
on_reload_log_tank
();
virtual
int
on_reload_log_level
();
virtual
int
on_reload_log_file
();
virtual
int
on_reload_pithy_print
();
virtual
int
on_reload_vhost_added
(
std
::
string
vhost
);
virtual
int
on_reload_vhost_removed
(
std
::
string
vhost
);
...
...
trunk/src/kernel/srs_kernel_log.cpp
查看文件 @
eda1ddc
...
...
@@ -38,15 +38,6 @@ int ISrsLog::initialize()
return
ERROR_SUCCESS
;
}
int
ISrsLog
::
level
()
{
return
SrsLogLevel
::
Trace
;
}
void
ISrsLog
::
set_level
(
int
/*level*/
)
{
}
void
ISrsLog
::
verbose
(
const
char
*
/*tag*/
,
int
/*context_id*/
,
const
char
*
/*fmt*/
,
...)
{
}
...
...
trunk/src/kernel/srs_kernel_log.hpp
查看文件 @
eda1ddc
...
...
@@ -69,11 +69,6 @@ public:
virtual
int
initialize
();
public
:
/**
* defined in SrsLogLevel.
*/
virtual
int
level
();
virtual
void
set_level
(
int
level
);
/**
* log for verbose, very verbose information.
*/
virtual
void
verbose
(
const
char
*
tag
,
int
context_id
,
const
char
*
fmt
,
...);
...
...
trunk/src/main/srs_main_server.cpp
查看文件 @
eda1ddc
...
...
@@ -98,7 +98,6 @@ int main(int argc, char** argv)
if
((
ret
=
_srs_log
->
initialize
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
_srs_log
->
set_level
(
srs_get_log_level
(
_srs_config
->
get_srs_log_level
()));
srs_trace
(
"srs(simple-rtmp-server) "
RTMP_SIG_SRS_VERSION
);
srs_trace
(
"uname: "
SRS_UNAME
);
...
...
请
注册
或
登录
后发表评论