C ++ Magazine Cover Design

I would like to add a magazine to my application. I chose the logging library, but I would like to be able to switch to another library without changing the code that uses logging.

So I need some kind of magazine wrapper that's flexible enough to use almost any podcast library library.

Any suggestions for such a shell design?

EDIT: One function that I should have in this shell is component tagging. I want my algorithm class to display "X:" in front of its log lines, and my manager class should have "Y:". How to distribute these tags to the pallet log and how to create a mechanism for naming component tags is one major design issue here.

+5
source share
3 answers

It’s best to make the interface as simple as possible. Separate the registration user interface completely from how registration is actually performed.

Cross-cutting issues are always expensive to maintain, so making things harder will make you hate life.

Some library just wants something simple:

void logDebug(const std::string &msg);
void logWarning(const std::string &msg);
void logError(const std::string &msg);

They should not add or indicate any other context. In any case, no one can use this information, so you should not design it.

, , . , . , , .

, ( , ) , .

UPDATE:

, . , , , .

. , .

, X Y . , , . , - , .

, (, ). , . - , . , , .

void setLoggingContext("X:");

, RAII .

LoggingTag tag("X:");

, , . , , .

void foo() {
  LoggingTag tag("X:");
  logWarning("foo");
  bar();
  baz();
}

void bar() {
  LoggingTag tag("Y:");
  logWarning("bar");
  baz();
}

void baz() {
  logWarning("baz");
}

, . baz LoggingTag. , logWarning .

- , - .

struct LoggingTag {
  LoggingTag(const std::string &tag_) : tag(tag_) {}
  template<typename T>
    static LoggingTag ByType() {
      return LoggingTag(typeid(T).name());
    }
  std::string tag;
};

void foo() {
  LoggingTag tag = LogginTag::ByType<int>();
}

- typeid(T).name(), , .

+2

:

class Log {
public:
    virtual logString(const std::string&)=0;
};

template <typename T>
Log& operator<<(Log& logger, const T& object) {
        std::stringstream converter;
        converter << object;
        logger.logString(converter.str());
        return logger;
}

! , , logString...

+1

zf_log . (~ 2000k , ~ 10KB ) (. README.md). , . API, , , . . custom_output.c , syslog . , , (. ZF_LOG_LIBRARY_PREFIX ). , , , .

0
source

All Articles