忙活了好久,才搞清楚。。。。。
首先注意配置文件:
定义了日志的输出位置,可以修改
然后再讲一下如何使用
在clion里面,修改启动参数
初始化日志库
std::cout << "Hello, World!" << std::endl;
srs_error_t err = srs_success;
// never use srs log(srs_trace, srs_error, etc) before config parse the option,
// which will load the log config and apply it.
if ((err = _srs_config->parse_options(argc, argv)) != srs_success) {
srs_error_wrap(err, "config parse options");
}
// change the work dir and set cwd.
int r0 = 0;
string cwd = _srs_config->get_work_dir();
if (!cwd.empty() && cwd != "./" && (r0 = chdir(cwd.c_str())) == -1) {
srs_error_new(-1, "chdir to %s, r0=%d", cwd.c_str(), r0);
}
if ((err = _srs_config->initialize_cwd()) != srs_success) {
srs_error_wrap(err, "config cwd");
}
// config parsed, initialize log.
if ((err = _srs_log->initialize()) != srs_success) {
srs_error_wrap(err, "log initialize");
}
写日志:
srs_error_t tt = srs_error_new(-1, "send message");
srs_trace("11111111111111111111");
srs_info("333333");
srs_error("666666");
srs_error("Failed, %s",srs_error_desc(tt).c_str());
注意最后一种模式,可以打印堆栈信息。
日志截图如下: