18
18
#include < srs_kernel_error.hpp>
19
19
#include < srs_app_utility.hpp>
20
20
#include < srs_kernel_utility.hpp>
21
+ #include < srs_core_lock.hpp>
21
22
22
23
// the max size of a line of log.
23
24
#define LOG_MAX_SIZE 8192
@@ -35,6 +36,8 @@ SrsFileLog::SrsFileLog()
35
36
fd = -1 ;
36
37
log_to_file_tank = false ;
37
38
utc = false ;
39
+
40
+ pthread_mutex_init (&mutex_, NULL );
38
41
}
39
42
40
43
SrsFileLog::~SrsFileLog ()
@@ -49,6 +52,8 @@ SrsFileLog::~SrsFileLog()
49
52
if (_srs_config) {
50
53
_srs_config->unsubscribe (this );
51
54
}
55
+
56
+ pthread_mutex_destroy (&mutex_);
52
57
}
53
58
54
59
srs_error_t SrsFileLog::initialize ()
@@ -79,6 +84,8 @@ void SrsFileLog::reopen()
79
84
80
85
void SrsFileLog::verbose (const char * tag, SrsContextId context_id, const char * fmt, ...)
81
86
{
87
+ SrsScopeLock sl (&mutex_);
88
+
82
89
if (level > SrsLogLevelVerbose) {
83
90
return ;
84
91
}
@@ -99,6 +106,8 @@ void SrsFileLog::verbose(const char* tag, SrsContextId context_id, const char* f
99
106
100
107
void SrsFileLog::info (const char * tag, SrsContextId context_id, const char * fmt, ...)
101
108
{
109
+ SrsScopeLock sl (&mutex_);
110
+
102
111
if (level > SrsLogLevelInfo) {
103
112
return ;
104
113
}
@@ -119,6 +128,8 @@ void SrsFileLog::info(const char* tag, SrsContextId context_id, const char* fmt,
119
128
120
129
void SrsFileLog::trace (const char * tag, SrsContextId context_id, const char * fmt, ...)
121
130
{
131
+ SrsScopeLock sl (&mutex_);
132
+
122
133
if (level > SrsLogLevelTrace) {
123
134
return ;
124
135
}
@@ -139,6 +150,8 @@ void SrsFileLog::trace(const char* tag, SrsContextId context_id, const char* fmt
139
150
140
151
void SrsFileLog::warn (const char * tag, SrsContextId context_id, const char * fmt, ...)
141
152
{
153
+ SrsScopeLock sl (&mutex_);
154
+
142
155
if (level > SrsLogLevelWarn) {
143
156
return ;
144
157
}
@@ -159,6 +172,8 @@ void SrsFileLog::warn(const char* tag, SrsContextId context_id, const char* fmt,
159
172
160
173
void SrsFileLog::error (const char * tag, SrsContextId context_id, const char * fmt, ...)
161
174
{
175
+ SrsScopeLock sl (&mutex_);
176
+
162
177
if (level > SrsLogLevelError) {
163
178
return ;
164
179
}
0 commit comments