mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
For #820, extract service module.
This commit is contained in:
parent
0a57a46016
commit
ff822b55cd
16 changed files with 510 additions and 213 deletions
12
README.md
12
README.md
|
@ -858,17 +858,17 @@ SRS always use the most simple architecture to support complex transaction.
|
|||
|
||||
```
|
||||
+------------------------------------------------------+
|
||||
| Main(srs/ingest-hls/librtmp) |
|
||||
| SRS server | Programs in Main or Research |
|
||||
+------------------------------------------------------+
|
||||
| Modules(1)(User defined modularity) |
|
||||
| App(For SRS) | Modules(1) | research/librtmp |
|
||||
+------------------------------------------------------+
|
||||
| App(Server/Client application) |
|
||||
| Service(C/S apps over ST) | Libs(Export librtmp) |
|
||||
+------------------------------------------------------+
|
||||
| RTMP/HTTP/RTSP/RawStream(Protocol stack) |
|
||||
| Protocol Stack(RTMP/HTTP/RTSP/JSON/AMF/Format) |
|
||||
+------------------------------------------------------+
|
||||
| Kernel(depends on Core, provides error/log) |
|
||||
| Kernel(File, Codec, Stream, LB services) |
|
||||
+------------------------------------------------------+
|
||||
| Core(depends only on system apis) |
|
||||
| Core(Macros and very low-level APIs) |
|
||||
+------------------------------------------------------+
|
||||
```
|
||||
|
||||
|
|
32
trunk/configure
vendored
32
trunk/configure
vendored
|
@ -173,21 +173,32 @@ MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_rtmp_stack"
|
|||
PROTOCOL_INCS="src/protocol"; MODULE_DIR=${PROTOCOL_INCS} . auto/modules.sh
|
||||
PROTOCOL_OBJS="${MODULE_OBJS[@]}"
|
||||
#
|
||||
#App Module
|
||||
#Service Module, for both Server and Client Modules.
|
||||
if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
|
||||
MODULE_ID="SERVICE"
|
||||
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL")
|
||||
ModuleLibIncs=(${LibSTRoot} ${LibSSLRoot} ${SRS_OBJS_DIR})
|
||||
MODULE_FILES=("srs_service_log" "srs_service_st")
|
||||
DEFINES=""
|
||||
SERVICE_INCS="src/service"; MODULE_DIR=${SERVICE_INCS} . auto/modules.sh
|
||||
SERVICE_OBJS="${MODULE_OBJS[@]}"
|
||||
fi
|
||||
#
|
||||
#App Module, for SRS server only.
|
||||
if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
|
||||
MODULE_ID="APP"
|
||||
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL")
|
||||
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "SERVICE")
|
||||
ModuleLibIncs=(${LibSTRoot} ${LibSSLRoot} ${SRS_OBJS_DIR})
|
||||
MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_source"
|
||||
"srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder" "srs_app_http_stream"
|
||||
"srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config"
|
||||
"srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks"
|
||||
"srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge"
|
||||
"srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_edge"
|
||||
"srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_http_static"
|
||||
"srs_app_recv_thread" "srs_app_security" "srs_app_statistic" "srs_app_hds"
|
||||
"srs_app_mpegts_udp" "srs_app_rtsp" "srs_app_listener" "srs_app_async_call"
|
||||
"srs_app_caster_flv" "srs_app_process" "srs_app_ng_exec" "srs_app_kafka"
|
||||
"srs_app_hourglass" "srs_app_dash" "srs_app_fragment")
|
||||
"srs_app_hourglass" "srs_app_dash" "srs_app_fragment" "srs_app_dvr")
|
||||
DEFINES=""
|
||||
# add each modules for app
|
||||
for SRS_MODULE in ${SRS_MODULES[*]}; do
|
||||
|
@ -210,7 +221,7 @@ LIBS_OBJS="${MODULE_OBJS[@]}"
|
|||
#Main Module
|
||||
if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
|
||||
MODULE_ID="MAIN"
|
||||
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "APP")
|
||||
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "SERVICE" "APP")
|
||||
ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS_DIR} ${LibGperfRoot} ${LibSSLRoot})
|
||||
MODULE_FILES=("srs_main_server")
|
||||
DEFINES=""
|
||||
|
@ -231,7 +242,7 @@ fi
|
|||
# disable all app when export librtmp
|
||||
if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
|
||||
# all main entrances
|
||||
MAIN_ENTRANCES=("srs_main_server" "srs_main_ingest_hls")
|
||||
MAIN_ENTRANCES=("srs_main_server")
|
||||
# add each modules for main
|
||||
for SRS_MODULE in ${SRS_MODULES[*]}; do
|
||||
. $SRS_MODULE/config
|
||||
|
@ -241,14 +252,11 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
|
|||
# all depends libraries
|
||||
ModuleLibFiles=(${LibSTfile} ${LibSSLfile} ${LibGperfFile})
|
||||
# all depends objects
|
||||
MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${APP_OBJS[@]} ${MAIN_OBJS[@]}"
|
||||
MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${SERVICE_OBJS[@]} ${APP_OBJS[@]} ${MAIN_OBJS[@]}"
|
||||
LINK_OPTIONS="${SrsLinkOptions}${SrsGprofLink}${SrsGperfLink}"
|
||||
#
|
||||
# srs: srs(simple rtmp server) over st(state-threads)
|
||||
BUILD_KEY="srs" APP_MAIN="srs_main_server" APP_NAME="srs" . auto/apps.sh
|
||||
#
|
||||
# srs_ingest_hls: to ingest hls stream to srs.
|
||||
BUILD_KEY="srs_ingest_hls" APP_MAIN="srs_main_ingest_hls" APP_NAME="srs_ingest_hls" . auto/apps.sh
|
||||
# add each modules for application
|
||||
for SRS_MODULE in ${SRS_MODULES[*]}; do
|
||||
. $SRS_MODULE/config
|
||||
|
@ -270,8 +278,8 @@ if [ $SRS_UTEST = YES ]; then
|
|||
"srs_utest_reload")
|
||||
ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibSSLRoot})
|
||||
ModuleLibFiles=(${LibSTfile} ${LibSSLfile})
|
||||
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "APP")
|
||||
MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${APP_OBJS[@]}"
|
||||
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "SERVICE" "APP")
|
||||
MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${SERVICE_OBJS[@]} ${APP_OBJS[@]}"
|
||||
LINK_OPTIONS="-lpthread ${SrsLinkOptions}" MODULE_DIR="src/utest" APP_NAME="srs_utest" . auto/utest.sh
|
||||
fi
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
3C1232941AAE81D900CE8F6C /* srs_app_bandwidth.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C12324C1AAE81D900CE8F6C /* srs_app_bandwidth.cpp */; };
|
||||
3C1232951AAE81D900CE8F6C /* srs_app_config.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C12324E1AAE81D900CE8F6C /* srs_app_config.cpp */; };
|
||||
3C1232961AAE81D900CE8F6C /* srs_app_conn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1232501AAE81D900CE8F6C /* srs_app_conn.cpp */; };
|
||||
3C1232971AAE81D900CE8F6C /* srs_app_dvr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1232521AAE81D900CE8F6C /* srs_app_dvr.cpp */; };
|
||||
3C1232981AAE81D900CE8F6C /* srs_app_edge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1232541AAE81D900CE8F6C /* srs_app_edge.cpp */; };
|
||||
3C1232991AAE81D900CE8F6C /* srs_app_empty.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1232561AAE81D900CE8F6C /* srs_app_empty.cpp */; };
|
||||
3C12329A1AAE81D900CE8F6C /* srs_app_encoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1232581AAE81D900CE8F6C /* srs_app_encoder.cpp */; };
|
||||
|
@ -72,7 +71,6 @@
|
|||
3C1232D31AAEA56B00CE8F6C /* libst.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C1232D21AAEA56B00CE8F6C /* libst.a */; };
|
||||
3C1232E91AAEA5D000CE8F6C /* libcrypto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C1232E71AAEA5D000CE8F6C /* libcrypto.a */; };
|
||||
3C1232EA1AAEA5D000CE8F6C /* libssl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C1232E81AAEA5D000CE8F6C /* libssl.a */; };
|
||||
3C1232ED1AAEA70F00CE8F6C /* libhttp_parser.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C1232EC1AAEA70F00CE8F6C /* libhttp_parser.a */; };
|
||||
3C1EE6AE1AB1055800576EE9 /* srs_app_hds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1EE6AC1AB1055800576EE9 /* srs_app_hds.cpp */; };
|
||||
3C1EE6D71AB1367D00576EE9 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = 3C1EE6D61AB1367D00576EE9 /* README.md */; };
|
||||
3C24ECCD1C3B824800460622 /* memory.error.notcmalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C24ECCB1C3B824800460622 /* memory.error.notcmalloc.cpp */; };
|
||||
|
@ -126,6 +124,9 @@
|
|||
3CD247C31BB3F14100DC1922 /* srs_kernel_balance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CD247C11BB3F14000DC1922 /* srs_kernel_balance.cpp */; };
|
||||
3CD88B3F1ACA9C58000359E0 /* srs_app_async_call.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CD88B3D1ACA9C58000359E0 /* srs_app_async_call.cpp */; };
|
||||
3CE6CD311AE4AFB800706E07 /* srs_main_ingest_hls.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CE6CD301AE4AFB800706E07 /* srs_main_ingest_hls.cpp */; };
|
||||
3CE893B51E87508D000B742D /* srs_app_dvr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CE893B31E87508D000B742D /* srs_app_dvr.cpp */; };
|
||||
3CE893B91E8750A9000B742D /* srs_service_log.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CE893B71E8750A9000B742D /* srs_service_log.cpp */; };
|
||||
3CE893BC1E875108000B742D /* srs_service_st.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CE893BA1E875108000B742D /* srs_service_st.cpp */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
|
@ -208,8 +209,6 @@
|
|||
3C12324F1AAE81D900CE8F6C /* srs_app_config.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_app_config.hpp; path = ../../../src/app/srs_app_config.hpp; sourceTree = "<group>"; };
|
||||
3C1232501AAE81D900CE8F6C /* srs_app_conn.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_app_conn.cpp; path = ../../../src/app/srs_app_conn.cpp; sourceTree = "<group>"; };
|
||||
3C1232511AAE81D900CE8F6C /* srs_app_conn.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_app_conn.hpp; path = ../../../src/app/srs_app_conn.hpp; sourceTree = "<group>"; };
|
||||
3C1232521AAE81D900CE8F6C /* srs_app_dvr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_app_dvr.cpp; path = ../../../src/app/srs_app_dvr.cpp; sourceTree = "<group>"; };
|
||||
3C1232531AAE81D900CE8F6C /* srs_app_dvr.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_app_dvr.hpp; path = ../../../src/app/srs_app_dvr.hpp; sourceTree = "<group>"; };
|
||||
3C1232541AAE81D900CE8F6C /* srs_app_edge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_app_edge.cpp; path = ../../../src/app/srs_app_edge.cpp; sourceTree = "<group>"; };
|
||||
3C1232551AAE81D900CE8F6C /* srs_app_edge.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_app_edge.hpp; path = ../../../src/app/srs_app_edge.hpp; sourceTree = "<group>"; };
|
||||
3C1232561AAE81D900CE8F6C /* srs_app_empty.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_app_empty.cpp; path = ../../../src/app/srs_app_empty.cpp; sourceTree = "<group>"; };
|
||||
|
@ -426,6 +425,12 @@
|
|||
3CD88B3D1ACA9C58000359E0 /* srs_app_async_call.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_app_async_call.cpp; path = ../../../src/app/srs_app_async_call.cpp; sourceTree = "<group>"; };
|
||||
3CD88B3E1ACA9C58000359E0 /* srs_app_async_call.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_app_async_call.hpp; path = ../../../src/app/srs_app_async_call.hpp; sourceTree = "<group>"; };
|
||||
3CE6CD301AE4AFB800706E07 /* srs_main_ingest_hls.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_main_ingest_hls.cpp; path = ../../../src/main/srs_main_ingest_hls.cpp; sourceTree = "<group>"; };
|
||||
3CE893B31E87508D000B742D /* srs_app_dvr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_app_dvr.cpp; path = ../../../src/app/srs_app_dvr.cpp; sourceTree = "<group>"; };
|
||||
3CE893B41E87508D000B742D /* srs_app_dvr.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_app_dvr.hpp; path = ../../../src/app/srs_app_dvr.hpp; sourceTree = "<group>"; };
|
||||
3CE893B71E8750A9000B742D /* srs_service_log.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_service_log.cpp; path = ../../../src/service/srs_service_log.cpp; sourceTree = "<group>"; };
|
||||
3CE893B81E8750A9000B742D /* srs_service_log.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_service_log.hpp; path = ../../../src/service/srs_service_log.hpp; sourceTree = "<group>"; };
|
||||
3CE893BA1E875108000B742D /* srs_service_st.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_service_st.cpp; path = ../../../src/service/srs_service_st.cpp; sourceTree = "<group>"; };
|
||||
3CE893BB1E875108000B742D /* srs_service_st.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_service_st.hpp; path = ../../../src/service/srs_service_st.hpp; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
@ -433,7 +438,6 @@
|
|||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
3C1232ED1AAEA70F00CE8F6C /* libhttp_parser.a in Frameworks */,
|
||||
3C1232E91AAEA5D000CE8F6C /* libcrypto.a in Frameworks */,
|
||||
3C1232EA1AAEA5D000CE8F6C /* libssl.a in Frameworks */,
|
||||
3C1232D31AAEA56B00CE8F6C /* libst.a in Frameworks */,
|
||||
|
@ -473,6 +477,7 @@
|
|||
3C12322C1AAE819900CE8F6C /* protocol */,
|
||||
3C12324B1AAE81CE00CE8F6C /* app */,
|
||||
3C96ADC41B00A71000885304 /* modules */,
|
||||
3CE893B61E875095000B742D /* service */,
|
||||
3C1232041AAE80CB00CE8F6C /* main */,
|
||||
3C36DB541ABD1CA70066CCAF /* libs */,
|
||||
3C1231F91AAE670E00CE8F6C /* objs */,
|
||||
|
@ -604,8 +609,8 @@
|
|||
3C1232511AAE81D900CE8F6C /* srs_app_conn.hpp */,
|
||||
3C9F82201E4ECA8200F5B2D2 /* srs_app_dash.cpp */,
|
||||
3C9F82211E4ECA8200F5B2D2 /* srs_app_dash.hpp */,
|
||||
3C1232521AAE81D900CE8F6C /* srs_app_dvr.cpp */,
|
||||
3C1232531AAE81D900CE8F6C /* srs_app_dvr.hpp */,
|
||||
3CE893B31E87508D000B742D /* srs_app_dvr.cpp */,
|
||||
3CE893B41E87508D000B742D /* srs_app_dvr.hpp */,
|
||||
3C1232541AAE81D900CE8F6C /* srs_app_edge.cpp */,
|
||||
3C1232551AAE81D900CE8F6C /* srs_app_edge.hpp */,
|
||||
3C1232561AAE81D900CE8F6C /* srs_app_empty.cpp */,
|
||||
|
@ -911,6 +916,17 @@
|
|||
name = utest;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
3CE893B61E875095000B742D /* service */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
3CE893B71E8750A9000B742D /* srs_service_log.cpp */,
|
||||
3CE893B81E8750A9000B742D /* srs_service_log.hpp */,
|
||||
3CE893BA1E875108000B742D /* srs_service_st.cpp */,
|
||||
3CE893BB1E875108000B742D /* srs_service_st.hpp */,
|
||||
);
|
||||
name = service;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
|
@ -978,11 +994,11 @@
|
|||
3C26E3C61BB146FF00D0F9DB /* srs_app_kafka.cpp in Sources */,
|
||||
3C663F131AB0155100286D8B /* srs_flv_injecter.c in Sources */,
|
||||
3C24ECCD1C3B824800460622 /* memory.error.notcmalloc.cpp in Sources */,
|
||||
3C1232971AAE81D900CE8F6C /* srs_app_dvr.cpp in Sources */,
|
||||
3CD247C31BB3F14100DC1922 /* srs_kernel_balance.cpp in Sources */,
|
||||
3C1232271AAE814D00CE8F6C /* srs_kernel_log.cpp in Sources */,
|
||||
3C1232A81AAE81D900CE8F6C /* srs_app_log.cpp in Sources */,
|
||||
3C1232A41AAE81D900CE8F6C /* srs_app_ingest.cpp in Sources */,
|
||||
3CE893B51E87508D000B742D /* srs_app_dvr.cpp in Sources */,
|
||||
3C0D422E1B87165900C2508B /* srs_protocol_json.cpp in Sources */,
|
||||
3C1232B41AAE81D900CE8F6C /* srs_app_st.cpp in Sources */,
|
||||
3C9F82221E4ECA8200F5B2D2 /* srs_app_dash.cpp in Sources */,
|
||||
|
@ -1044,6 +1060,7 @@
|
|||
3C1232B21AAE81D900CE8F6C /* srs_app_source.cpp in Sources */,
|
||||
3C1231F71AAE652D00CE8F6C /* srs_core_performance.cpp in Sources */,
|
||||
3C4D184C1E73F133008806F7 /* srs_app_fragment.cpp in Sources */,
|
||||
3CE893BC1E875108000B742D /* srs_service_st.cpp in Sources */,
|
||||
3CC52DD81ACE4023006FEB01 /* srs_utest_amf0.cpp in Sources */,
|
||||
3C4F97121B8B466D00FF0E46 /* srs_app_process.cpp in Sources */,
|
||||
3C1232981AAE81D900CE8F6C /* srs_app_edge.cpp in Sources */,
|
||||
|
@ -1067,6 +1084,7 @@
|
|||
3C663F181AB0155100286D8B /* srs_play.c in Sources */,
|
||||
3C1232B61AAE81D900CE8F6C /* srs_app_thread.cpp in Sources */,
|
||||
3C1232A91AAE81D900CE8F6C /* srs_app_mpegts_udp.cpp in Sources */,
|
||||
3CE893B91E8750A9000B742D /* srs_service_log.cpp in Sources */,
|
||||
3C1232AE1AAE81D900CE8F6C /* srs_app_rtmp_conn.cpp in Sources */,
|
||||
3C1232B51AAE81D900CE8F6C /* srs_app_statistic.cpp in Sources */,
|
||||
3C663F161AB0155100286D8B /* srs_ingest_flv.c in Sources */,
|
||||
|
@ -1169,12 +1187,9 @@
|
|||
ALWAYS_SEARCH_USER_PATHS = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "c++98";
|
||||
CLANG_CXX_LIBRARY = "libstdc++";
|
||||
LIBRARY_SEARCH_PATHS = (
|
||||
"../../objs/**",
|
||||
"/Users/winlin/Desktop/git/ossrs/trunk/objs/http-parser-2.1",
|
||||
);
|
||||
LIBRARY_SEARCH_PATHS = "../../objs/**";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
"USER_HEADER_SEARCH_PATHS[arch=*]" = "../../src/** ../../objs ../../objs/st ../../objs/hp ../../objs/openssl";
|
||||
"USER_HEADER_SEARCH_PATHS[arch=*]" = "../../src/** ../../objs ../../objs/st ../../objs/openssl";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
|
@ -1184,10 +1199,7 @@
|
|||
ALWAYS_SEARCH_USER_PATHS = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "c++98";
|
||||
CLANG_CXX_LIBRARY = "libstdc++";
|
||||
LIBRARY_SEARCH_PATHS = (
|
||||
"../../objs/**",
|
||||
"/Users/winlin/Desktop/git/ossrs/trunk/objs/http-parser-2.1",
|
||||
);
|
||||
LIBRARY_SEARCH_PATHS = "../../objs/**";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
|
|
|
@ -35,51 +35,6 @@
|
|||
#include <srs_app_utility.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
|
||||
SrsThreadContext::SrsThreadContext()
|
||||
{
|
||||
}
|
||||
|
||||
SrsThreadContext::~SrsThreadContext()
|
||||
{
|
||||
}
|
||||
|
||||
int SrsThreadContext::generate_id()
|
||||
{
|
||||
static int id = 100;
|
||||
|
||||
int gid = id++;
|
||||
cache[st_thread_self()] = gid;
|
||||
return gid;
|
||||
}
|
||||
|
||||
int SrsThreadContext::get_id()
|
||||
{
|
||||
return cache[st_thread_self()];
|
||||
}
|
||||
|
||||
int SrsThreadContext::set_id(int v)
|
||||
{
|
||||
st_thread_t self = st_thread_self();
|
||||
|
||||
int ov = 0;
|
||||
if (cache.find(self) != cache.end()) {
|
||||
ov = cache[self];
|
||||
}
|
||||
|
||||
cache[self] = v;
|
||||
|
||||
return ov;
|
||||
}
|
||||
|
||||
void SrsThreadContext::clear_cid()
|
||||
{
|
||||
st_thread_t self = st_thread_self();
|
||||
std::map<st_thread_t, int>::iterator it = cache.find(self);
|
||||
if (it != cache.end()) {
|
||||
cache.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
// the max size of a line of log.
|
||||
#define LOG_MAX_SIZE 4096
|
||||
|
||||
|
@ -90,7 +45,7 @@ void SrsThreadContext::clear_cid()
|
|||
|
||||
SrsFastLog::SrsFastLog()
|
||||
{
|
||||
_level = SrsLogLevel::Trace;
|
||||
level = SrsLogLevelTrace;
|
||||
log_data = new char[LOG_MAX_SIZE];
|
||||
|
||||
fd = -1;
|
||||
|
@ -120,7 +75,7 @@ int SrsFastLog::initialize()
|
|||
_srs_config->subscribe(this);
|
||||
|
||||
log_to_file_tank = _srs_config->get_log_tank_file();
|
||||
_level = srs_get_log_level(_srs_config->get_log_level());
|
||||
level = srs_get_log_level(_srs_config->get_log_level());
|
||||
utc = _srs_config->get_utc_time();
|
||||
}
|
||||
|
||||
|
@ -142,12 +97,12 @@ void SrsFastLog::reopen()
|
|||
|
||||
void SrsFastLog::verbose(const char* tag, int context_id, const char* fmt, ...)
|
||||
{
|
||||
if (_level > SrsLogLevel::Verbose) {
|
||||
if (level > SrsLogLevelVerbose) {
|
||||
return;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
if (!generate_header(false, tag, context_id, "Verb", &size)) {
|
||||
if (!srs_log_header(log_data, LOG_MAX_SIZE, utc, false, tag, context_id, "Verb", &size)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -157,17 +112,17 @@ void SrsFastLog::verbose(const char* tag, int context_id, const char* fmt, ...)
|
|||
size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
write_log(fd, log_data, size, SrsLogLevel::Verbose);
|
||||
write_log(fd, log_data, size, SrsLogLevelVerbose);
|
||||
}
|
||||
|
||||
void SrsFastLog::info(const char* tag, int context_id, const char* fmt, ...)
|
||||
{
|
||||
if (_level > SrsLogLevel::Info) {
|
||||
if (level > SrsLogLevelInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
if (!generate_header(false, tag, context_id, "Debug", &size)) {
|
||||
if (!srs_log_header(log_data, LOG_MAX_SIZE, utc, false, tag, context_id, "Debug", &size)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -177,17 +132,17 @@ void SrsFastLog::info(const char* tag, int context_id, const char* fmt, ...)
|
|||
size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
write_log(fd, log_data, size, SrsLogLevel::Info);
|
||||
write_log(fd, log_data, size, SrsLogLevelInfo);
|
||||
}
|
||||
|
||||
void SrsFastLog::trace(const char* tag, int context_id, const char* fmt, ...)
|
||||
{
|
||||
if (_level > SrsLogLevel::Trace) {
|
||||
if (level > SrsLogLevelTrace) {
|
||||
return;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
if (!generate_header(false, tag, context_id, "Trace", &size)) {
|
||||
if (!srs_log_header(log_data, LOG_MAX_SIZE, utc, false, tag, context_id, "Trace", &size)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -197,17 +152,17 @@ void SrsFastLog::trace(const char* tag, int context_id, const char* fmt, ...)
|
|||
size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
write_log(fd, log_data, size, SrsLogLevel::Trace);
|
||||
write_log(fd, log_data, size, SrsLogLevelTrace);
|
||||
}
|
||||
|
||||
void SrsFastLog::warn(const char* tag, int context_id, const char* fmt, ...)
|
||||
{
|
||||
if (_level > SrsLogLevel::Warn) {
|
||||
if (level > SrsLogLevelWarn) {
|
||||
return;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
if (!generate_header(true, tag, context_id, "Warn", &size)) {
|
||||
if (!srs_log_header(log_data, LOG_MAX_SIZE, utc, true, tag, context_id, "Warn", &size)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -217,17 +172,17 @@ void SrsFastLog::warn(const char* tag, int context_id, const char* fmt, ...)
|
|||
size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
write_log(fd, log_data, size, SrsLogLevel::Warn);
|
||||
write_log(fd, log_data, size, SrsLogLevelWarn);
|
||||
}
|
||||
|
||||
void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...)
|
||||
{
|
||||
if (_level > SrsLogLevel::Error) {
|
||||
if (level > SrsLogLevelError) {
|
||||
return;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
if (!generate_header(true, tag, context_id, "Error", &size)) {
|
||||
if (!srs_log_header(log_data, LOG_MAX_SIZE, utc, true, tag, context_id, "Error", &size)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -242,7 +197,7 @@ void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...)
|
|||
size += snprintf(log_data + size, LOG_MAX_SIZE - size, "(%s)", strerror(errno));
|
||||
}
|
||||
|
||||
write_log(fd, log_data, size, SrsLogLevel::Error);
|
||||
write_log(fd, log_data, size, SrsLogLevelError);
|
||||
}
|
||||
|
||||
int SrsFastLog::on_reload_utc_time()
|
||||
|
@ -287,7 +242,7 @@ int SrsFastLog::on_reload_log_level()
|
|||
return ret;
|
||||
}
|
||||
|
||||
_level = srs_get_log_level(_srs_config->get_log_level());
|
||||
level = srs_get_log_level(_srs_config->get_log_level());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -312,65 +267,6 @@ int SrsFastLog::on_reload_log_file()
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool SrsFastLog::generate_header(bool error, const char* tag, int context_id, const char* level_name, int* header_size)
|
||||
{
|
||||
// clock time
|
||||
timeval tv;
|
||||
if (gettimeofday(&tv, NULL) == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// to calendar time
|
||||
struct tm* tm;
|
||||
if (utc) {
|
||||
if ((tm = gmtime(&tv.tv_sec)) == NULL) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ((tm = localtime(&tv.tv_sec)) == NULL) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// write log header
|
||||
int log_header_size = -1;
|
||||
|
||||
if (error) {
|
||||
if (tag) {
|
||||
log_header_size = snprintf(log_data, LOG_MAX_SIZE,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%d][%d] ",
|
||||
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),
|
||||
level_name, tag, getpid(), context_id, errno);
|
||||
} else {
|
||||
log_header_size = snprintf(log_data, LOG_MAX_SIZE,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%d][%d] ",
|
||||
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),
|
||||
level_name, getpid(), context_id, errno);
|
||||
}
|
||||
} else {
|
||||
if (tag) {
|
||||
log_header_size = snprintf(log_data, LOG_MAX_SIZE,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%d] ",
|
||||
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),
|
||||
level_name, tag, getpid(), context_id);
|
||||
} else {
|
||||
log_header_size = snprintf(log_data, LOG_MAX_SIZE,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%d] ",
|
||||
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),
|
||||
level_name, getpid(), context_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (log_header_size == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// write the header size.
|
||||
*header_size = srs_min(LOG_MAX_SIZE - 1, log_header_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SrsFastLog::write_log(int& fd, char *str_log, int size, int level)
|
||||
{
|
||||
// ensure the tail and EOF of string
|
||||
|
@ -388,9 +284,9 @@ void SrsFastLog::write_log(int& fd, char *str_log, int size, int level)
|
|||
// \033[32m : green text code in shell
|
||||
// \033[33m : yellow text code in shell
|
||||
// \033[0m : normal text code
|
||||
if (level <= SrsLogLevel::Trace) {
|
||||
if (level <= SrsLogLevelTrace) {
|
||||
printf("%.*s", size, str_log);
|
||||
} else if (level == SrsLogLevel::Warn) {
|
||||
} else if (level == SrsLogLevelWarn) {
|
||||
printf("\033[33m%.*s\033[0m", size, str_log);
|
||||
} else{
|
||||
printf("\033[31m%.*s\033[0m", size, str_log);
|
||||
|
|
|
@ -26,33 +26,11 @@
|
|||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#include <srs_app_st.hpp>
|
||||
#include <srs_kernel_log.hpp>
|
||||
#include <srs_app_reload.hpp>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
/**
|
||||
* st thread context, get_id will get the st-thread id,
|
||||
* which identify the client.
|
||||
*/
|
||||
class SrsThreadContext : public ISrsThreadContext
|
||||
{
|
||||
private:
|
||||
std::map<st_thread_t, int> cache;
|
||||
public:
|
||||
SrsThreadContext();
|
||||
virtual ~SrsThreadContext();
|
||||
public:
|
||||
virtual int generate_id();
|
||||
virtual int get_id();
|
||||
virtual int set_id(int v);
|
||||
public:
|
||||
virtual void clear_cid();
|
||||
};
|
||||
#include <srs_app_reload.hpp>
|
||||
#include <srs_service_log.hpp>
|
||||
|
||||
/**
|
||||
* we use memory/disk cache and donot flush when write log.
|
||||
|
@ -61,10 +39,10 @@ public:
|
|||
*/
|
||||
class SrsFastLog : public ISrsLog, public ISrsReloadHandler
|
||||
{
|
||||
// for utest to override
|
||||
// for utest to override
|
||||
protected:
|
||||
// defined in SrsLogLevel.
|
||||
int _level;
|
||||
SrsLogLevel level;
|
||||
private:
|
||||
char* log_data;
|
||||
// log to file if specified srs_log_file
|
||||
|
@ -76,6 +54,7 @@ private:
|
|||
public:
|
||||
SrsFastLog();
|
||||
virtual ~SrsFastLog();
|
||||
// interface ISrsLog
|
||||
public:
|
||||
virtual int initialize();
|
||||
virtual void reopen();
|
||||
|
@ -91,7 +70,6 @@ public:
|
|||
virtual int on_reload_log_level();
|
||||
virtual int on_reload_log_file();
|
||||
private:
|
||||
virtual bool generate_header(bool error, const char* tag, int context_id, const char* level_name, int* header_size);
|
||||
virtual void write_log(int& fd, char* str_log, int size, int level);
|
||||
virtual void open_log_file();
|
||||
};
|
||||
|
|
|
@ -28,9 +28,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include <st.h>
|
||||
|
||||
#include <srs_app_st.hpp>
|
||||
#include <srs_service_st.hpp>
|
||||
#include <srs_protocol_io.hpp>
|
||||
|
||||
// the internal classes, user should never use it.
|
||||
|
|
|
@ -110,20 +110,20 @@ failed:
|
|||
return ret;
|
||||
}
|
||||
|
||||
int srs_get_log_level(string level)
|
||||
SrsLogLevel srs_get_log_level(string level)
|
||||
{
|
||||
if ("verbose" == level) {
|
||||
return SrsLogLevel::Verbose;
|
||||
return SrsLogLevelVerbose;
|
||||
} else if ("info" == level) {
|
||||
return SrsLogLevel::Info;
|
||||
return SrsLogLevelInfo;
|
||||
} else if ("trace" == level) {
|
||||
return SrsLogLevel::Trace;
|
||||
return SrsLogLevelTrace;
|
||||
} else if ("warn" == level) {
|
||||
return SrsLogLevel::Warn;
|
||||
return SrsLogLevelWarn;
|
||||
} else if ("error" == level) {
|
||||
return SrsLogLevel::Error;
|
||||
return SrsLogLevelError;
|
||||
} else {
|
||||
return SrsLogLevel::Disabled;
|
||||
return SrsLogLevelDisabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <sys/resource.h>
|
||||
|
||||
#include <srs_app_st.hpp>
|
||||
#include <srs_kernel_log.hpp>
|
||||
|
||||
class SrsKbps;
|
||||
class SrsBuffer;
|
||||
|
@ -47,7 +48,7 @@ extern int srs_socket_connect(std::string server, int port, int64_t tm, st_netfd
|
|||
* convert level in string to log level in int.
|
||||
* @return the log level defined in SrsLogLevel.
|
||||
*/
|
||||
extern int srs_get_log_level(std::string level);
|
||||
extern SrsLogLevel srs_get_log_level(std::string level);
|
||||
|
||||
/**
|
||||
* build the path according to vhost/app/stream, where replace variables:
|
||||
|
|
|
@ -38,18 +38,17 @@
|
|||
* if specified Debug level, all level messages will be logged.
|
||||
* if specified Warn level, only Warn/Error/Fatal level messages will be logged.
|
||||
*/
|
||||
class SrsLogLevel
|
||||
enum SrsLogLevel
|
||||
{
|
||||
public:
|
||||
SrsLogLevelForbidden = 0x00,
|
||||
// only used for very verbose debug, generally,
|
||||
// we compile without this level for high performance.
|
||||
static const int Verbose = 0x01;
|
||||
static const int Info = 0x02;
|
||||
static const int Trace = 0x03;
|
||||
static const int Warn = 0x04;
|
||||
static const int Error = 0x05;
|
||||
// specified the disabled level, no log, for utest.
|
||||
static const int Disabled = 0x06;
|
||||
SrsLogLevelVerbose = 0x01,
|
||||
SrsLogLevelInfo = 0x02,
|
||||
SrsLogLevelTrace = 0x04,
|
||||
SrsLogLevelWarn = 0x08,
|
||||
SrsLogLevelError = 0x10,
|
||||
SrsLogLevelDisabled = 0x20,
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ using namespace std;
|
|||
#include <srs_kernel_error.hpp>
|
||||
#include <srs_app_server.hpp>
|
||||
#include <srs_app_config.hpp>
|
||||
#include <srs_app_log.hpp>
|
||||
#include <srs_service_log.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
#include <srs_rtmp_stack.hpp>
|
||||
#include <srs_kernel_stream.hpp>
|
||||
|
@ -54,8 +54,8 @@ using namespace std;
|
|||
int proxy_hls2rtmp(std::string hls, std::string rtmp);
|
||||
|
||||
// @global log and context.
|
||||
ISrsLog* _srs_log = new SrsFastLog();
|
||||
ISrsThreadContext* _srs_context = new ISrsThreadContext();
|
||||
ISrsLog* _srs_log = new SrsConsoleLog(SrsLogLevelTrace, false);
|
||||
ISrsThreadContext* _srs_context = new SrsThreadContext();
|
||||
// @global config object for app module.
|
||||
SrsConfig* _srs_config = NULL;
|
||||
|
||||
|
|
263
trunk/src/service/srs_service_log.cpp
Normal file
263
trunk/src/service/srs_service_log.cpp
Normal file
|
@ -0,0 +1,263 @@
|
|||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2017 OSSRS(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_service_log.hpp>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <sys/time.h>
|
||||
using namespace std;
|
||||
|
||||
#include <srs_kernel_error.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
|
||||
#define SRS_BASIC_LOG_SIZE 1024
|
||||
|
||||
SrsThreadContext::SrsThreadContext()
|
||||
{
|
||||
}
|
||||
|
||||
SrsThreadContext::~SrsThreadContext()
|
||||
{
|
||||
}
|
||||
|
||||
int SrsThreadContext::generate_id()
|
||||
{
|
||||
static int id = 100;
|
||||
|
||||
int gid = id++;
|
||||
cache[st_thread_self()] = gid;
|
||||
return gid;
|
||||
}
|
||||
|
||||
int SrsThreadContext::get_id()
|
||||
{
|
||||
return cache[st_thread_self()];
|
||||
}
|
||||
|
||||
int SrsThreadContext::set_id(int v)
|
||||
{
|
||||
st_thread_t self = st_thread_self();
|
||||
|
||||
int ov = 0;
|
||||
if (cache.find(self) != cache.end()) {
|
||||
ov = cache[self];
|
||||
}
|
||||
|
||||
cache[self] = v;
|
||||
|
||||
return ov;
|
||||
}
|
||||
|
||||
void SrsThreadContext::clear_cid()
|
||||
{
|
||||
st_thread_t self = st_thread_self();
|
||||
std::map<st_thread_t, int>::iterator it = cache.find(self);
|
||||
if (it != cache.end()) {
|
||||
cache.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
SrsConsoleLog::SrsConsoleLog(SrsLogLevel l, bool u)
|
||||
{
|
||||
level = l;
|
||||
utc = u;
|
||||
|
||||
buffer = new char[SRS_BASIC_LOG_SIZE];
|
||||
}
|
||||
|
||||
SrsConsoleLog::~SrsConsoleLog()
|
||||
{
|
||||
srs_freepa(buffer);
|
||||
}
|
||||
|
||||
int SrsConsoleLog::initialize()
|
||||
{
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
void SrsConsoleLog::reopen()
|
||||
{
|
||||
}
|
||||
|
||||
void SrsConsoleLog::verbose(const char* tag, int context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelVerbose) {
|
||||
return;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
if (!srs_log_header(buffer, SRS_BASIC_LOG_SIZE, utc, false, tag, context_id, "Verb", &size)) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
// we reserved 1 bytes for the new line.
|
||||
size += vsnprintf(buffer + size, SRS_BASIC_LOG_SIZE - size, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
fprintf(stdout, "%s", buffer);
|
||||
}
|
||||
|
||||
void SrsConsoleLog::info(const char* tag, int context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
if (!srs_log_header(buffer, SRS_BASIC_LOG_SIZE, utc, false, tag, context_id, "Debug", &size)) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
// we reserved 1 bytes for the new line.
|
||||
size += vsnprintf(buffer + size, SRS_BASIC_LOG_SIZE - size, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
fprintf(stdout, "%s", buffer);
|
||||
}
|
||||
|
||||
void SrsConsoleLog::trace(const char* tag, int context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelTrace) {
|
||||
return;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
if (!srs_log_header(buffer, SRS_BASIC_LOG_SIZE, utc, false, tag, context_id, "Trace", &size)) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
// we reserved 1 bytes for the new line.
|
||||
size += vsnprintf(buffer + size, SRS_BASIC_LOG_SIZE - size, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
fprintf(stdout, "%s", buffer);
|
||||
}
|
||||
|
||||
void SrsConsoleLog::warn(const char* tag, int context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelWarn) {
|
||||
return;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
if (!srs_log_header(buffer, SRS_BASIC_LOG_SIZE, utc, true, tag, context_id, "Warn", &size)) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
// we reserved 1 bytes for the new line.
|
||||
size += vsnprintf(buffer + size, SRS_BASIC_LOG_SIZE - size, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
fprintf(stderr, "%s", buffer);
|
||||
}
|
||||
|
||||
void SrsConsoleLog::error(const char* tag, int context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelError) {
|
||||
return;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
if (!srs_log_header(buffer, SRS_BASIC_LOG_SIZE, utc, true, tag, context_id, "Error", &size)) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
// we reserved 1 bytes for the new line.
|
||||
size += vsnprintf(buffer + size, SRS_BASIC_LOG_SIZE - size, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
// add strerror() to error msg.
|
||||
if (errno != 0) {
|
||||
size += snprintf(buffer + size, SRS_BASIC_LOG_SIZE - size, "(%s)", strerror(errno));
|
||||
}
|
||||
|
||||
fprintf(stderr, "%s", buffer);
|
||||
}
|
||||
|
||||
bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char* tag, int cid, const char* level, int* psize)
|
||||
{
|
||||
// clock time
|
||||
timeval tv;
|
||||
if (gettimeofday(&tv, NULL) == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// to calendar time
|
||||
struct tm* tm;
|
||||
if (utc) {
|
||||
if ((tm = gmtime(&tv.tv_sec)) == NULL) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ((tm = localtime(&tv.tv_sec)) == NULL) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int nb_header = -1;
|
||||
if (dangerous) {
|
||||
if (tag) {
|
||||
nb_header = snprintf(buffer, size,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%d][%d] ",
|
||||
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),
|
||||
level, tag, getpid(), cid, errno);
|
||||
} else {
|
||||
nb_header = snprintf(buffer, size,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%d][%d] ",
|
||||
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),
|
||||
level, getpid(), cid, errno);
|
||||
}
|
||||
} else {
|
||||
if (tag) {
|
||||
nb_header = snprintf(buffer, size,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%d] ",
|
||||
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),
|
||||
level, tag, getpid(), cid);
|
||||
} else {
|
||||
nb_header = snprintf(buffer, size,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%d] ",
|
||||
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),
|
||||
level, getpid(), cid);
|
||||
}
|
||||
}
|
||||
|
||||
if (nb_header == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// write the header size.
|
||||
*psize = srs_min(size - 1, nb_header);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
85
trunk/src/service/srs_service_log.hpp
Normal file
85
trunk/src/service/srs_service_log.hpp
Normal file
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2017 OSSRS(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_SERVICE_LOG_HPP
|
||||
#define SRS_SERVICE_LOG_HPP
|
||||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <srs_service_st.hpp>
|
||||
#include <srs_kernel_log.hpp>
|
||||
|
||||
/**
|
||||
* st thread context, get_id will get the st-thread id,
|
||||
* which identify the client.
|
||||
*/
|
||||
class SrsThreadContext : public ISrsThreadContext
|
||||
{
|
||||
private:
|
||||
std::map<st_thread_t, int> cache;
|
||||
public:
|
||||
SrsThreadContext();
|
||||
virtual ~SrsThreadContext();
|
||||
public:
|
||||
virtual int generate_id();
|
||||
virtual int get_id();
|
||||
virtual int set_id(int v);
|
||||
public:
|
||||
virtual void clear_cid();
|
||||
};
|
||||
|
||||
/**
|
||||
* The basic console log, which write log to console.
|
||||
*/
|
||||
class SrsConsoleLog : public ISrsLog
|
||||
{
|
||||
private:
|
||||
SrsLogLevel level;
|
||||
bool utc;
|
||||
private:
|
||||
char* buffer;
|
||||
public:
|
||||
SrsConsoleLog(SrsLogLevel l, bool u);
|
||||
virtual ~SrsConsoleLog();
|
||||
// interface ISrsLog
|
||||
public:
|
||||
virtual int initialize();
|
||||
virtual void reopen();
|
||||
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, ...);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char* tag, int cid, const char* level, int* psize);
|
||||
|
||||
#endif
|
25
trunk/src/service/srs_service_st.cpp
Normal file
25
trunk/src/service/srs_service_st.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2017 OSSRS(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_service_st.hpp>
|
||||
|
32
trunk/src/service/srs_service_st.hpp
Normal file
32
trunk/src/service/srs_service_st.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2017 OSSRS(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_SERVICE_ST_HPP
|
||||
#define SRS_SERVICE_ST_HPP
|
||||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#include <st.h>
|
||||
|
||||
#endif
|
||||
|
|
@ -30,15 +30,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <srs_app_log.hpp>
|
||||
|
||||
// kernel module.
|
||||
ISrsLog* _srs_log = new MockEmptyLog(SrsLogLevel::Disabled);
|
||||
ISrsLog* _srs_log = new MockEmptyLog(SrsLogLevelDisabled);
|
||||
ISrsThreadContext* _srs_context = new ISrsThreadContext();
|
||||
// app module.
|
||||
SrsConfig* _srs_config = NULL;
|
||||
SrsServer* _srs_server = NULL;
|
||||
|
||||
MockEmptyLog::MockEmptyLog(int level)
|
||||
MockEmptyLog::MockEmptyLog(SrsLogLevel l)
|
||||
{
|
||||
_level = level;
|
||||
level = l;
|
||||
}
|
||||
|
||||
MockEmptyLog::~MockEmptyLog()
|
||||
|
|
|
@ -84,7 +84,7 @@ void srs_bytes_print(char* pa, int size);
|
|||
class MockEmptyLog : public SrsFastLog
|
||||
{
|
||||
public:
|
||||
MockEmptyLog(int level);
|
||||
MockEmptyLog(SrsLogLevel l);
|
||||
virtual ~MockEmptyLog();
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue