Merge pull request #28 from wenjiegit/master
merge from wenjie.zhao for colorful log.
正在显示
3 个修改的文件
包含
19 行增加
和
9 行删除
| @@ -308,7 +308,7 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<string>& arg | @@ -308,7 +308,7 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<string>& arg | ||
| 308 | srs_error("line %d: unexpected end of file, expecting ; or \"}\"", buffer->line); | 308 | srs_error("line %d: unexpected end of file, expecting ; or \"}\"", buffer->line); |
| 309 | return ERROR_SYSTEM_CONFIG_INVALID; | 309 | return ERROR_SYSTEM_CONFIG_INVALID; |
| 310 | } | 310 | } |
| 311 | - srs_error("end of file. ret=%d", ret); | 311 | + srs_trace("end of file. ret=%d", ret); |
| 312 | 312 | ||
| 313 | return ret; | 313 | return ret; |
| 314 | } | 314 | } |
| @@ -81,7 +81,7 @@ void SrsFastLog::verbose(const char* tag, int context_id, const char* fmt, ...) | @@ -81,7 +81,7 @@ void SrsFastLog::verbose(const char* tag, int context_id, const char* fmt, ...) | ||
| 81 | size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); | 81 | size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); |
| 82 | va_end(ap); | 82 | va_end(ap); |
| 83 | 83 | ||
| 84 | - write_log(log_data, size); | 84 | + write_log(log_data, size, SrsLogLevel::Verbose); |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | void SrsFastLog::info(const char* tag, int context_id, const char* fmt, ...) | 87 | void SrsFastLog::info(const char* tag, int context_id, const char* fmt, ...) |
| @@ -101,7 +101,7 @@ void SrsFastLog::info(const char* tag, int context_id, const char* fmt, ...) | @@ -101,7 +101,7 @@ void SrsFastLog::info(const char* tag, int context_id, const char* fmt, ...) | ||
| 101 | size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); | 101 | size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); |
| 102 | va_end(ap); | 102 | va_end(ap); |
| 103 | 103 | ||
| 104 | - write_log(log_data, size); | 104 | + write_log(log_data, size, SrsLogLevel::Info); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | void SrsFastLog::trace(const char* tag, int context_id, const char* fmt, ...) | 107 | void SrsFastLog::trace(const char* tag, int context_id, const char* fmt, ...) |
| @@ -121,7 +121,7 @@ void SrsFastLog::trace(const char* tag, int context_id, const char* fmt, ...) | @@ -121,7 +121,7 @@ void SrsFastLog::trace(const char* tag, int context_id, const char* fmt, ...) | ||
| 121 | size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); | 121 | size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); |
| 122 | va_end(ap); | 122 | va_end(ap); |
| 123 | 123 | ||
| 124 | - write_log(log_data, size); | 124 | + write_log(log_data, size, SrsLogLevel::Trace); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | void SrsFastLog::warn(const char* tag, int context_id, const char* fmt, ...) | 127 | void SrsFastLog::warn(const char* tag, int context_id, const char* fmt, ...) |
| @@ -141,7 +141,7 @@ void SrsFastLog::warn(const char* tag, int context_id, const char* fmt, ...) | @@ -141,7 +141,7 @@ void SrsFastLog::warn(const char* tag, int context_id, const char* fmt, ...) | ||
| 141 | size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); | 141 | size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); |
| 142 | va_end(ap); | 142 | va_end(ap); |
| 143 | 143 | ||
| 144 | - write_log(log_data, size); | 144 | + write_log(log_data, size, SrsLogLevel::Warn); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...) | 147 | void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...) |
| @@ -161,7 +161,10 @@ void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...) | @@ -161,7 +161,10 @@ void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...) | ||
| 161 | size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); | 161 | size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); |
| 162 | va_end(ap); | 162 | va_end(ap); |
| 163 | 163 | ||
| 164 | - write_log(log_data, size); | 164 | + // add strerror() to error msg. |
| 165 | + size += snprintf(log_data + size, LOG_MAX_SIZE - size, "(%s)", strerror(errno)); | ||
| 166 | + | ||
| 167 | + write_log(log_data, size, SrsLogLevel::Error); | ||
| 165 | } | 168 | } |
| 166 | 169 | ||
| 167 | bool SrsFastLog::generate_header(const char* tag, int context_id, const char* level_name, int* header_size) | 170 | bool SrsFastLog::generate_header(const char* tag, int context_id, const char* level_name, int* header_size) |
| @@ -203,7 +206,7 @@ bool SrsFastLog::generate_header(const char* tag, int context_id, const char* le | @@ -203,7 +206,7 @@ bool SrsFastLog::generate_header(const char* tag, int context_id, const char* le | ||
| 203 | return true; | 206 | return true; |
| 204 | } | 207 | } |
| 205 | 208 | ||
| 206 | -void SrsFastLog::write_log(char* str_log, int size) | 209 | +void SrsFastLog::write_log(char *str_log, int size, int _level) |
| 207 | { | 210 | { |
| 208 | // ensure the tail and EOF of string | 211 | // ensure the tail and EOF of string |
| 209 | // LOG_TAIL_SIZE for the TAIL char. | 212 | // LOG_TAIL_SIZE for the TAIL char. |
| @@ -214,5 +217,12 @@ void SrsFastLog::write_log(char* str_log, int size) | @@ -214,5 +217,12 @@ void SrsFastLog::write_log(char* str_log, int size) | ||
| 214 | log_data[size++] = LOG_TAIL; | 217 | log_data[size++] = LOG_TAIL; |
| 215 | log_data[size++] = 0; | 218 | log_data[size++] = 0; |
| 216 | 219 | ||
| 217 | - printf("%s", str_log); | 220 | + // if is error msg, then print color msg. |
| 221 | + // \033[1;31m : red text code in shell | ||
| 222 | + // \033[1;31m : normal text code | ||
| 223 | + if (_level == SrsLogLevel::Error) { | ||
| 224 | + printf("\033[1;31m%s\033[0m", str_log); | ||
| 225 | + } else { | ||
| 226 | + printf("%s", str_log); | ||
| 227 | + } | ||
| 218 | } | 228 | } |
| @@ -91,7 +91,7 @@ public: | @@ -91,7 +91,7 @@ public: | ||
| 91 | virtual void error(const char* tag, int context_id, const char* fmt, ...); | 91 | virtual void error(const char* tag, int context_id, const char* fmt, ...); |
| 92 | private: | 92 | private: |
| 93 | virtual bool generate_header(const char* tag, int context_id, const char* level_name, int* header_size); | 93 | virtual bool generate_header(const char* tag, int context_id, const char* level_name, int* header_size); |
| 94 | - virtual void write_log(char* str_log, int size); | 94 | + virtual void write_log(char* str_log, int size, int _level); |
| 95 | }; | 95 | }; |
| 96 | 96 | ||
| 97 | #endif | 97 | #endif |
-
请 注册 或 登录 后发表评论