mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Log: Change cid from int to string
This commit is contained in:
parent
bca4ec1da1
commit
8a0c2e01f8
42 changed files with 301 additions and 307 deletions
|
@ -490,7 +490,7 @@ public:
|
|||
// then the rest id is 100.
|
||||
// @param pattern the handler pattern which will serve the request.
|
||||
// @return the REST id; -1 if not matched.
|
||||
virtual int parse_rest_id(std::string pattern) = 0;
|
||||
virtual std::string parse_rest_id(std::string pattern) = 0;
|
||||
public:
|
||||
// The left all data is chunked body, the infinite chunked mode,
|
||||
// which is chunked encoding without chunked header.
|
||||
|
|
|
@ -2453,7 +2453,7 @@ srs_error_t SrsRtmpServer::response_connect_app(SrsRequest *req, const char* ser
|
|||
}
|
||||
// for edge to directly get the id of client.
|
||||
data->set("srs_pid", SrsAmf0Any::number(getpid()));
|
||||
data->set("srs_id", SrsAmf0Any::number(_srs_context->get_id()));
|
||||
data->set("srs_id", SrsAmf0Any::str(_srs_context->get_id().c_str()));
|
||||
|
||||
if ((err = protocol->send_and_free_packet(pkt, 0)) != srs_success) {
|
||||
return srs_error_wrap(err, "send connect app response");
|
||||
|
|
|
@ -535,19 +535,19 @@ string SrsHttpMessage::ext()
|
|||
return _ext;
|
||||
}
|
||||
|
||||
int SrsHttpMessage::parse_rest_id(string pattern)
|
||||
std::string SrsHttpMessage::parse_rest_id(string pattern)
|
||||
{
|
||||
string p = _uri->get_path();
|
||||
if (p.length() <= pattern.length()) {
|
||||
return -1;
|
||||
return "";
|
||||
}
|
||||
|
||||
string id = p.substr((int)pattern.length());
|
||||
if (!id.empty()) {
|
||||
return ::atoi(id.c_str());
|
||||
return id;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return "";
|
||||
}
|
||||
|
||||
srs_error_t SrsHttpMessage::enter_infinite_chunked()
|
||||
|
|
|
@ -172,7 +172,7 @@ public:
|
|||
virtual std::string query();
|
||||
virtual std::string ext();
|
||||
// Get the RESTful matched id.
|
||||
virtual int parse_rest_id(std::string pattern);
|
||||
virtual std::string parse_rest_id(std::string pattern);
|
||||
public:
|
||||
virtual srs_error_t enter_infinite_chunked();
|
||||
public:
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
#include <srs_kernel_error.hpp>
|
||||
|
@ -41,29 +42,31 @@ SrsThreadContext::~SrsThreadContext()
|
|||
{
|
||||
}
|
||||
|
||||
int SrsThreadContext::generate_id()
|
||||
string SrsThreadContext::generate_id()
|
||||
{
|
||||
static int id = 0;
|
||||
|
||||
if (id == 0) {
|
||||
id = (100 + ((uint32_t)(int64_t)this)%1000);
|
||||
}
|
||||
|
||||
int gid = id++;
|
||||
cache[srs_thread_self()] = gid;
|
||||
return gid;
|
||||
|
||||
stringstream ss;
|
||||
ss << gid;
|
||||
cache[srs_thread_self()] = ss.str();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
int SrsThreadContext::get_id()
|
||||
string SrsThreadContext::get_id()
|
||||
{
|
||||
return cache[srs_thread_self()];
|
||||
}
|
||||
|
||||
int SrsThreadContext::set_id(int v)
|
||||
string SrsThreadContext::set_id(string v)
|
||||
{
|
||||
srs_thread_t self = srs_thread_self();
|
||||
|
||||
int ov = 0;
|
||||
string ov;
|
||||
if (cache.find(self) != cache.end()) {
|
||||
ov = cache[self];
|
||||
}
|
||||
|
@ -76,7 +79,7 @@ int SrsThreadContext::set_id(int v)
|
|||
void SrsThreadContext::clear_cid()
|
||||
{
|
||||
srs_thread_t self = srs_thread_self();
|
||||
std::map<srs_thread_t, int>::iterator it = cache.find(self);
|
||||
std::map<srs_thread_t, string>::iterator it = cache.find(self);
|
||||
if (it != cache.end()) {
|
||||
cache.erase(it);
|
||||
}
|
||||
|
@ -105,7 +108,7 @@ void SrsConsoleLog::reopen()
|
|||
{
|
||||
}
|
||||
|
||||
void SrsConsoleLog::verbose(const char* tag, int context_id, const char* fmt, ...)
|
||||
void SrsConsoleLog::verbose(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelVerbose) {
|
||||
return;
|
||||
|
@ -125,7 +128,7 @@ void SrsConsoleLog::verbose(const char* tag, int context_id, const char* fmt, ..
|
|||
fprintf(stdout, "%s\n", buffer);
|
||||
}
|
||||
|
||||
void SrsConsoleLog::info(const char* tag, int context_id, const char* fmt, ...)
|
||||
void SrsConsoleLog::info(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelInfo) {
|
||||
return;
|
||||
|
@ -145,7 +148,7 @@ void SrsConsoleLog::info(const char* tag, int context_id, const char* fmt, ...)
|
|||
fprintf(stdout, "%s\n", buffer);
|
||||
}
|
||||
|
||||
void SrsConsoleLog::trace(const char* tag, int context_id, const char* fmt, ...)
|
||||
void SrsConsoleLog::trace(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelTrace) {
|
||||
return;
|
||||
|
@ -165,7 +168,7 @@ void SrsConsoleLog::trace(const char* tag, int context_id, const char* fmt, ...)
|
|||
fprintf(stdout, "%s\n", buffer);
|
||||
}
|
||||
|
||||
void SrsConsoleLog::warn(const char* tag, int context_id, const char* fmt, ...)
|
||||
void SrsConsoleLog::warn(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelWarn) {
|
||||
return;
|
||||
|
@ -185,7 +188,7 @@ void SrsConsoleLog::warn(const char* tag, int context_id, const char* fmt, ...)
|
|||
fprintf(stderr, "%s\n", buffer);
|
||||
}
|
||||
|
||||
void SrsConsoleLog::error(const char* tag, int context_id, const char* fmt, ...)
|
||||
void SrsConsoleLog::error(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelError) {
|
||||
return;
|
||||
|
@ -211,7 +214,7 @@ void SrsConsoleLog::error(const char* tag, int context_id, const char* fmt, ...)
|
|||
}
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char* tag, int cid, const char* level, int* psize)
|
||||
bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char* tag, const char* cid, const char* level, int* psize)
|
||||
{
|
||||
// clock time
|
||||
timeval tv;
|
||||
|
@ -235,24 +238,24 @@ bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char
|
|||
if (dangerous) {
|
||||
if (tag) {
|
||||
written = snprintf(buffer, size,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%d][%d] ",
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%s][%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 {
|
||||
written = snprintf(buffer, size,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%d][%d] ",
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%s][%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) {
|
||||
written = snprintf(buffer, size,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%d] ",
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%s] ",
|
||||
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 {
|
||||
written = snprintf(buffer, size,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%d] ",
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%s] ",
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <srs_core.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <srs_service_st.hpp>
|
||||
#include <srs_kernel_log.hpp>
|
||||
|
@ -36,14 +37,14 @@
|
|||
class SrsThreadContext : public ISrsThreadContext
|
||||
{
|
||||
private:
|
||||
std::map<srs_thread_t, int> cache;
|
||||
std::map<srs_thread_t, std::string> cache;
|
||||
public:
|
||||
SrsThreadContext();
|
||||
virtual ~SrsThreadContext();
|
||||
public:
|
||||
virtual int generate_id();
|
||||
virtual int get_id();
|
||||
virtual int set_id(int v);
|
||||
virtual std::string generate_id();
|
||||
virtual std::string get_id();
|
||||
virtual std::string set_id(std::string v);
|
||||
public:
|
||||
virtual void clear_cid();
|
||||
};
|
||||
|
@ -63,11 +64,11 @@ public:
|
|||
public:
|
||||
virtual srs_error_t 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, ...);
|
||||
virtual void verbose(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void info(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void trace(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void warn(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void error(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
};
|
||||
|
||||
// Generate the log header.
|
||||
|
@ -75,6 +76,6 @@ public:
|
|||
// @param utc Whether use UTC time format in the log header.
|
||||
// @param psize Output the actual header size.
|
||||
// @remark It's a internal API.
|
||||
bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char* tag, int cid, const char* level, int* psize);
|
||||
bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char* tag, const char* cid, const char* level, int* psize);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -122,7 +122,7 @@ srs_error_t SrsBasicRtmpClient::do_connect_app(string local_ip, bool debug)
|
|||
data->set("srs_version", SrsAmf0Any::str(RTMP_SIG_SRS_VERSION));
|
||||
// for edge to directly get the id of client.
|
||||
data->set("srs_pid", SrsAmf0Any::number(getpid()));
|
||||
data->set("srs_id", SrsAmf0Any::number(_srs_context->get_id()));
|
||||
data->set("srs_id", SrsAmf0Any::str(_srs_context->get_id().c_str()));
|
||||
|
||||
// local ip of edge
|
||||
data->set("srs_server_ip", SrsAmf0Any::str(local_ip.c_str()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue