Skip to content

Commit

Permalink
fix(dede): support all version of spdlog while building with syslog
Browse files Browse the repository at this point in the history
Add common header with all configuration options for spdlog
  • Loading branch information
Bycob authored and sileht committed Sep 14, 2020
1 parent 28ab168 commit 81f47c9
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 39 deletions.
18 changes: 6 additions & 12 deletions src/apistrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
#ifndef APISTRATEGY_H
#define APISTRATEGY_H

#include "dd_types.h"
#include "services.h"
#include <spdlog/spdlog.h>

#ifdef USE_DD_SYSLOG
#include <spdlog/sinks/syslog_sink.h>
#else
#include <spdlog/sinks/stdout_sinks.h>
#define SPDLOG_ENABLE_SYSLOG
#endif

#include "dd_types.h"
#include "services.h"
#include "dd_spdlog.h"

namespace dd
{

Expand All @@ -43,11 +41,7 @@ namespace dd
public:
APIStrategy()
{
#ifdef USE_DD_SYSLOG
_logger = spdlog::syslog_logger("api");
#else
_logger = spdlog::stdout_logger_mt("api");
#endif
_logger = DD_SPDLOG_LOGGER("api");
};
~APIStrategy()
{
Expand Down
2 changes: 1 addition & 1 deletion src/backends/caffe/caffemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "mlmodel.h"
#include "apidata.h"
#include <spdlog/spdlog.h>
#include "dd_spdlog.h"
#include <string>

namespace dd
Expand Down
2 changes: 1 addition & 1 deletion src/backends/caffe2/caffe2model.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "mlmodel.h"
#include "apidata.h"
#include <spdlog/spdlog.h>
#include "dd_spdlog.h"
#include <string>
#include <google/protobuf/message.h>

Expand Down
2 changes: 1 addition & 1 deletion src/backends/dlib/dlibmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "mlmodel.h"
#include "apidata.h"
#include <spdlog/spdlog.h>
#include "dd_spdlog.h"
#include <string>

namespace dd
Expand Down
2 changes: 1 addition & 1 deletion src/backends/ncnn/ncnnmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#ifndef NCNNMODEL_H
#define NCNNMODEL_H

#include <spdlog/spdlog.h>
#include "dd_spdlog.h"
#include "mlmodel.h"
#include "apidata.h"

Expand Down
2 changes: 1 addition & 1 deletion src/backends/tensorrt/tensorrtmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef TENSORRTMODEL_H
#define TENSORRTMODEL_H

#include <spdlog/spdlog.h>
#include "dd_spdlog.h"
#include "mlmodel.h"
#include "apidata.h"

Expand Down
2 changes: 1 addition & 1 deletion src/backends/tf/tfmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "mlmodel.h"
#include "apidata.h"
#include <spdlog/spdlog.h>
#include "dd_spdlog.h"
#include <string>

namespace dd
Expand Down
17 changes: 16 additions & 1 deletion src/backends/torch/llogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@
#ifndef LLOGGING_H
#define LLOGGING_H

#ifdef USE_DD_SYSLOG
#define SPDLOG_ENABLE_SYSLOG
#endif

#include <spdlog/spdlog.h>

#ifdef USE_DD_SYSLOG
#if SPDLOG_VER_MAJOR > 0
#include <spdlog/sinks/syslog_sinks.h>
#endif
#endif

#include <boost/algorithm/string.hpp>
#include <iostream>

Expand Down Expand Up @@ -167,8 +178,12 @@ class CaffeLogger
{
_console = spdlog::get("torchlib");
if (!_console)
#ifdef USE_SYSLOG
#ifdef USE_DD_SYSLOG
#if SPDLOG_VER_MAJOR > 0
_console = spdlog::syslog_logger_mt("torchlib");
#else
_console = spdlog::syslog_logger("torchlib");
#endif
#else
_console = spdlog::stdout_logger_mt("torchlib");
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/backends/xgb/xgbmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "mlmodel.h"
#include "apidata.h"
#include <spdlog/spdlog.h>
#include "dd_spdlog.h"
#include <string>
#include <unordered_map>

Expand Down
2 changes: 1 addition & 1 deletion src/chain_actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "apidata.h"
#include "chain.h"
#include <memory>
#include <spdlog/spdlog.h>
#include "dd_spdlog.h"

namespace dd
{
Expand Down
22 changes: 22 additions & 0 deletions src/dd_spdlog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

#ifdef USE_DD_SYSLOG
#define SPDLOG_ENABLE_SYSLOG
#endif

#include <spdlog/spdlog.h>

#if SPDLOG_VER_MAJOR > 0
#ifdef USE_DD_SYSLOG
#include <spdlog/sinks/syslog_sinks.h>
#define DD_SPDLOG_LOGGER spdlog::syslog_logger_mt
#else
#include <spdlog/sinks/stdout_sinks.h>
#define DD_SPDLOG_LOGGER spdlog::stdout_logger_mt
#endif
#else
#ifdef USE_DD_SYSLOG
#define DD_SPDLOG_LOGGER spdlog::syslog_logger
#else
#define DD_SPDLOG_LOGGER spdlog::stdout_logger_mt
#endif
#endif
4 changes: 3 additions & 1 deletion src/generators/net_caffe.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
#define NET_CAFFE_H

#include "net_generator.h"

#include "caffe.pb.h"
#include <spdlog/spdlog.h>
#include "caffe/caffe.hpp"
#include "dd_spdlog.h"

namespace dd
{
Expand Down
2 changes: 1 addition & 1 deletion src/httpjsonapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "ext/rapidjson/stringbuffer.h"
#include "ext/rapidjson/reader.h"
#include "ext/rapidjson/writer.h"
#include <spdlog/spdlog.h>
#include "dd_spdlog.h"
#include <gflags/gflags.h>
#include "utils/httpclient.hpp"
#include <boost/iostreams/filtering_stream.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/inputconnectorstrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#ifndef WIN32
#include "utils/httpclient.hpp"
#endif
#include <spdlog/spdlog.h>
#include "dd_spdlog.h"
#include <exception>

namespace dd
Expand Down
2 changes: 1 addition & 1 deletion src/mllibstrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "apidata.h"
#include "utils/fileops.hpp"
#include <spdlog/spdlog.h>
#include "dd_spdlog.h"
#include <atomic>
#include <exception>
#include <mutex>
Expand Down
12 changes: 6 additions & 6 deletions src/mlservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@
#ifndef MLSERVICE_H
#define MLSERVICE_H

#ifdef USE_DD_SYSLOG
#define SPDLOG_ENABLE_SYSLOG
#endif

#include "mllibstrategy.h"
#include "mlmodel.h"
#include "outputconnectorstrategy.h"
#include <string>
#include <future>
#include <mutex>
//#include <shared_mutex>
#include "spdlog/sinks/stdout_sinks.h"
#include "dd_spdlog.h"
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/lock_types.hpp>
#include <unordered_map>
Expand Down Expand Up @@ -108,11 +112,7 @@ namespace dd
mlmodel),
_sname(sname), _description(description), _tjobs_counter(0)
{
#ifdef USE_DD_SYSLOG
this->_logger = spdlog::syslog_logger(_sname);
#else
this->_logger = spdlog::stdout_logger_mt(_sname);
#endif
this->_logger = DD_SPDLOG_LOGGER(_sname);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/outputconnectorstrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <numeric>
#include <Eigen/Dense>
#include "utils/utils.hpp"
#include <spdlog/spdlog.h>
#include "dd_spdlog.h"

namespace dd
{
Expand Down
13 changes: 6 additions & 7 deletions src/services.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#ifndef SERVICES_H
#define SERVICES_H

#ifdef USE_DD_SYSLOG
#define SPDLOG_ENABLE_SYSLOG
#endif

#include "utils/variant.hpp"
#include "mlservice.h"
#include "apidata.h"
Expand Down Expand Up @@ -60,12 +64,11 @@
#ifdef USE_TENSORRT
#include "backends/tensorrt/tensorrtlib.h"
#endif
#include <spdlog/spdlog.h>
#include "dd_spdlog.h"
#include <vector>
#include <mutex>
#include <chrono>
#include <iostream>
#include <spdlog/spdlog.h>

namespace dd
{
Expand Down Expand Up @@ -886,11 +889,7 @@ namespace dd
{
try
{
#ifdef USE_DD_SYSLOG
auto chain_logger = spdlog::syslog_logger(cname);
#else
auto chain_logger = spdlog::stdout_logger_mt(cname);
#endif
auto chain_logger = DD_SPDLOG_LOGGER(cname);

std::chrono::time_point<std::chrono::system_clock> tstart
= std::chrono::system_clock::now();
Expand Down

0 comments on commit 81f47c9

Please sign in to comment.