serializer.serialize(input_filename, output);
+ cout << "Write " << output.tellp() << " bytes" << endl;
+
return 0;
}
}
uint8_t* Serializer::serialize(const std::string config_path, size_t &size) {
- tslog::init();
+ tslog::init(tslog::ldp_log_level::DEFAULT);
ldp_xml::StorageBackendXML xmlStorage;
if (!xmlStorage.init(config_path.c_str())) {
namespace tslog {
-int8_t g_verbosity{-1};
+ldp_log_level g_verbosity{ldp_log_level::SILENT};
pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
bool get_log_env(char const *name) {
return ldp_log_mode && '0' != *ldp_log_mode;
}
-void init() {
- g_verbosity = get_log_env("LDP_LOG") ? get_log_env("LDP_VERBOSE") : -1;
+void init(ldp_log_level level) {
+ g_verbosity = get_log_env("LDP_LOG") ? (get_log_env("LDP_VERBOSE") ? ldp_log_level::DEBUG : ldp_log_level::VERBOSE): level;
}
-bool enabled() { return g_verbosity >= 0; }
-bool verbose() { return g_verbosity > 0; }
+bool enabled(ldp_log_level level) { return level <= g_verbosity; }
-void flush() {
- if (tslog::enabled()) {
+void flush(ldp_log_level level) {
+ if (tslog::enabled(level)) {
pthread_mutex_lock(&g_mutex);
std::cout << std::flush;
pthread_mutex_unlock(&g_mutex);
LOGW("%s", warning.c_str());
}
+void logDebug(const std::string &debug)
+{
+ log(debug, "\n");
+ LOGD("%s", debug.c_str());
+}
+
+void logVerbose(const std::string &verbose)
+{
+ log_verbose(verbose, "\n");
+ LOGD("%s", verbose.c_str());
+}
+
std::ostream &operator<<(std::ostream &stream, const print_errno &p) {
char buf[256];
return stream << strerror_r(p.err, buf, sizeof(buf));
}
-LogLock::LogLock() {
- locked = tslog::enabled();
+LogLock::LogLock(ldp_log_level level) {
+ locked = tslog::enabled(level);
if (locked)
pthread_mutex_lock(&g_mutex);
}
namespace tslog
{
+ enum class ldp_log_level {
+ SILENT,
+ ERROR,
+ WARNING,
+ DEFAULT = WARNING,
+ DEBUG,
+ VERBOSE
+ };
/** Checks value of environmental variable with given name */
bool get_log_env(char const *name);
/** Checks environmental variables and sets global variable defining if logs are enabled */
- void init();
+ void init(ldp_log_level level = ldp_log_level::SILENT);
/** Checks if logs are enabled */
- bool enabled();
-
- /** Checks if verbosity is enabled */
- bool verbose();
+ bool enabled(ldp_log_level level = ldp_log_level::DEBUG);
- void flush();
+ void flush(ldp_log_level level = ldp_log_level::ERROR);
void logError(const std::string &error);
void logWarning(const std::string &warning);
+ void logDebug(const std::string &debug);
+ void logVerbose(const std::string &verbose);
template <typename ...Args>
void log_to_stream(std::ostream &stream, const Args &...args) {
}
template <typename ...Args>
- void log(const Args &...args) { if (enabled()) log_to_stream(std::cout, args...); }
+ void log(const Args &...args) { if (enabled(ldp_log_level::DEBUG)) log_to_stream(std::cout, args...); }
+
+ template <typename ...Args>
+ void log_error(const Args &...args) { if (enabled(ldp_log_level::ERROR)) log_to_stream(std::cout, args...); }
+
+ template <typename ...Args>
+ void log_warning(const Args &...args) { if (enabled(ldp_log_level::WARNING)) log_to_stream(std::cout, args...); }
template <typename ...Args>
- void log_verbose(const Args &...args) { if (verbose()) log_to_stream(std::cout, args...); }
+ void log_verbose(const Args &...args) { if (enabled(ldp_log_level::VERBOSE)) log_to_stream(std::cout, args...); }
struct print_errno {
int err;
class LogLock {
bool locked;
public:
- LogLock();
+ LogLock(ldp_log_level level = ldp_log_level::ERROR);
~LogLock();
};
}