feature:
1.Add spdlog to save log file 2.Add program options to connect specific broadcast code and decide whether to save log file 3.Add comments in readme for windows 64-bit project compilation
This commit is contained in:
@@ -48,7 +48,7 @@ bool IOLoop::Init() {
|
||||
#endif
|
||||
|
||||
if (rv != APR_SUCCESS) {
|
||||
LOG_ERROR << PrintAPRStatus(rv) << std::endl;
|
||||
LOG_ERROR(PrintAPRStatus(rv));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -141,14 +141,14 @@ void IOLoop::Loop() {
|
||||
}
|
||||
|
||||
if (rv != APR_SUCCESS && !APR_STATUS_IS_TIMEUP(rv) && !APR_STATUS_IS_EINTR(rv)) {
|
||||
LOG_ERROR << PrintAPRStatus(rv) << std::endl;
|
||||
LOG_ERROR(PrintAPRStatus(rv));
|
||||
}
|
||||
}
|
||||
|
||||
bool IOLoop::Wakeup() {
|
||||
apr_status_t rv = apr_pollset_wakeup(pollset_);
|
||||
if (rv != APR_SUCCESS) {
|
||||
LOG_ERROR << PrintAPRStatus(rv) << std::endl;
|
||||
LOG_ERROR(PrintAPRStatus(rv));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2019 Livox. All rights reserved.
|
||||
//
|
||||
// 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 "logging.h"
|
||||
|
||||
std::shared_ptr<spdlog::logger> logger = NULL;
|
||||
bool is_save_log_file = false;
|
||||
|
||||
void InitLogger() {
|
||||
std::vector<spdlog::sink_ptr> sinkList;
|
||||
auto consoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||
consoleSink->set_level(spdlog::level::debug);
|
||||
sinkList.push_back(consoleSink);
|
||||
|
||||
if (is_save_log_file) {
|
||||
auto rotateSink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("livox_log.txt", 1024 * 1024 * 5, 2);
|
||||
rotateSink->set_level(spdlog::level::debug);
|
||||
sinkList.push_back(rotateSink);
|
||||
}
|
||||
|
||||
logger = std::make_shared<spdlog::logger>("console", begin(sinkList), end(sinkList));
|
||||
spdlog::register_logger(logger);
|
||||
logger->set_level(spdlog::level::debug);
|
||||
logger->flush_on(spdlog::level::debug);
|
||||
}
|
||||
|
||||
void UninitLogger() {
|
||||
spdlog::drop_all();
|
||||
}
|
||||
@@ -24,16 +24,42 @@
|
||||
|
||||
#ifndef LIVOX_LOGGING_H_
|
||||
#define LIVOX_LOGGING_H_
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include "../include/third_party/spdlog/spdlog/spdlog.h"
|
||||
#include "../include/third_party/spdlog/spdlog/sinks/stdout_color_sinks.h"
|
||||
#include "../include/third_party/spdlog/spdlog/sinks/rotating_file_sink.h"
|
||||
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1) : __FILE__)
|
||||
#ifdef _WIN32
|
||||
#define __FILENAME__ (strrchr(__FILE__, '\\') ? (strrchr(__FILE__, '\\') + 1):__FILE__)
|
||||
#else
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1):__FILE__)
|
||||
#endif
|
||||
|
||||
#define LOG_TRACE std::cout << "TRACE " << __FILENAME__ << ":" << __LINE__ << " " << __FUNCTION__ << " "
|
||||
#define LOG_DEBUG std::cout << "DEBUG " << __FILENAME__ << ":" << __LINE__ << " " << __FUNCTION__ << " "
|
||||
#define LOG_INFO std::cout << "INFO " << __FILENAME__ << ":" << __LINE__ << " " << __FUNCTION__ << " "
|
||||
#define LOG_WARN std::cout << "WARN " << __FILENAME__ << ":" << __LINE__ << " " << __FUNCTION__ << " "
|
||||
#define LOG_ERROR std::cout << "ERROR " << __FILENAME__ << ":" << __LINE__ << " " << __FUNCTION__ << " "
|
||||
#define LOG_FATAL std::cout << "FATAL " << __FILENAME__ << ":" << __LINE__ << " " << __FUNCTION__ << " "
|
||||
#ifndef suffix
|
||||
#define suffix(msg) std::string(msg).append(" [")\
|
||||
.append(__FILENAME__).append("] [").append(__func__)\
|
||||
.append("] [").append(std::to_string(__LINE__))\
|
||||
.append("]").c_str()
|
||||
#endif
|
||||
|
||||
#ifndef SPDLOG_TRACE_ON
|
||||
#define SPDLOG_TRACE_ON
|
||||
#endif
|
||||
|
||||
#ifndef SPDLOG_DEBUG_ON
|
||||
#define SPDLOG_DEBUG_ON
|
||||
#endif
|
||||
|
||||
extern std::shared_ptr<spdlog::logger> logger;
|
||||
extern bool is_save_log_file;
|
||||
|
||||
void InitLogger();
|
||||
void UninitLogger();
|
||||
|
||||
#define LOG_TRACE(msg, ...) logger->trace(suffix(msg), ##__VA_ARGS__)
|
||||
#define LOG_DEBUG(msg, ...) logger->debug(suffix(msg), ##__VA_ARGS__)
|
||||
#define LOG_INFO(msg, ...) logger->info(suffix(msg), ##__VA_ARGS__)
|
||||
#define LOG_WARN(msg, ...) logger->warn(suffix(msg), ##__VA_ARGS__)
|
||||
#define LOG_ERROR(msg, ...) logger->error(suffix(msg), ##__VA_ARGS__)
|
||||
#define LOG_FATAL(msg, ...) logger->critical(suffix(msg), ##__VA_ARGS__)
|
||||
|
||||
#endif // LIVOX_LOGGING_H_
|
||||
|
||||
Reference in New Issue
Block a user