mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 02:40:14 +00:00
Logger: moved most of the logic to C++ stream
Most of the logic was moved to the C++ implementation, log_msg() is now using the ostream. This allows use of colors from rang.hpp also in log messages.
This commit is contained in:
@@ -32,7 +32,7 @@ export INCLUDE='src;C:\msys64\home\toor\AJA\ajalibraries\ajantv2\includes;C:\msy
|
||||
cp src/video_capture/aja.cpp aja_capture.cpp
|
||||
cp src/video_display/aja.cpp aja_display.cpp
|
||||
|
||||
run_vs12 cl //LD //DAJA_WINDOWS //DMSWindows //DAJA_NTV2SDK_VERSION_MAJOR=13 aja_capture.cpp aja_display.cpp src/video_capture/aja_win32_utils.cpp src/video_capture_params.cpp src/utils/config_file.cpp ../AJA/lib/libajantv2.lib advapi32.lib user32.lib winmm.lib //Feaja
|
||||
run_vs12 cl //LD //D_XKEYCHECK_H //DAJA_WINDOWS //DMSWindows //DAJA_NTV2SDK_VERSION_MAJOR=13 aja_capture.cpp aja_display.cpp src/video_capture/aja_win32_utils.cpp src/video_capture_params.cpp src/utils/config_file.cpp ../AJA/lib/libajantv2.lib advapi32.lib user32.lib winmm.lib //Feaja
|
||||
cp aja.lib /usr/local/lib
|
||||
cp aja.dll /usr/local/bin
|
||||
|
||||
|
||||
@@ -38,12 +38,18 @@
|
||||
#ifndef CONFIG_MSVC_H
|
||||
#define CONFIG_MSVC_H
|
||||
|
||||
#if defined _MSC_VER && !defined WIN32
|
||||
#if defined _MSC_VER
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <process.h> // getpid()
|
||||
|
||||
#if _MSC_VER <= 1800
|
||||
#define constexpr
|
||||
#define noexcept
|
||||
#endif
|
||||
|
||||
|
||||
static inline char * strtok_r(char *str, const char *delim, char **save);
|
||||
|
||||
/*
|
||||
@@ -69,7 +75,7 @@ static inline char *strtok_r(char *s, const char *delimiters, char **lasts)
|
||||
|
||||
#define ATTRIBUTE(a)
|
||||
|
||||
#define snprintf(x, y, ...) sprintf(x, __VA_ARGS__)
|
||||
#define snprintf _snprintf
|
||||
#define strncasecmp(x, y, z) strcmp(x, y)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -94,24 +94,6 @@ void log_msg(int level, const char *format, ...)
|
||||
}
|
||||
#endif /* WIN32 */
|
||||
|
||||
rang::fg color = rang::fg::reset;
|
||||
rang::style style = rang::style::reset;
|
||||
|
||||
switch (level) {
|
||||
case LOG_LEVEL_FATAL: color = rang::fg::red; style = rang::style::bold; break;
|
||||
case LOG_LEVEL_ERROR: color = rang::fg::red; break;
|
||||
case LOG_LEVEL_WARNING: color = rang::fg::yellow; break;
|
||||
case LOG_LEVEL_NOTICE: color = rang::fg::green; break;
|
||||
}
|
||||
|
||||
auto timestamp = (char *) alloca((3 /* "[] " */ + 20 /* 64b int dec */ + 1 /* dot */ + 3 /* ms */) /* time */ + 1);
|
||||
timestamp[0] = '\0';
|
||||
if (log_level >= LOG_LEVEL_VERBOSE) {
|
||||
unsigned long long time_ms = time_since_epoch_in_ms();
|
||||
sprintf(timestamp, "[%llu.%03llu] ", time_ms / 1000,
|
||||
time_ms % 1000);
|
||||
}
|
||||
|
||||
// get number of required bytes
|
||||
va_start(ap, format);
|
||||
int size = vsnprintf(NULL, 0, format, ap);
|
||||
@@ -126,8 +108,7 @@ void log_msg(int level, const char *format, ...)
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
std::cerr << style << color << timestamp <<
|
||||
buffer << rang::style::reset << rang::fg::reset;
|
||||
LOG(level) << buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
29
src/debug.h
29
src/debug.h
@@ -61,20 +61,37 @@ void log_msg(int log_level, const char *format, ...);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include "compat/platform_time.h"
|
||||
#include "rang.hpp"
|
||||
|
||||
// Log, version 0.1: a simple logging class
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
inline Logger(int l) : level(l) {}
|
||||
inline ~Logger() {
|
||||
log_msg(level, os.str().c_str());
|
||||
std::cerr << rang::style::reset << rang::fg::reset;
|
||||
}
|
||||
inline std::ostringstream& Get() {
|
||||
return os;
|
||||
inline std::ostream& Get() {
|
||||
rang::fg color = rang::fg::reset;
|
||||
rang::style style = rang::style::reset;
|
||||
|
||||
switch (level) {
|
||||
case LOG_LEVEL_FATAL: color = rang::fg::red; style = rang::style::bold; break;
|
||||
case LOG_LEVEL_ERROR: color = rang::fg::red; break;
|
||||
case LOG_LEVEL_WARNING: color = rang::fg::yellow; break;
|
||||
case LOG_LEVEL_NOTICE: color = rang::fg::green; break;
|
||||
}
|
||||
std::cerr << style << color;
|
||||
if (log_level >= LOG_LEVEL_VERBOSE) {
|
||||
unsigned long long time_ms = time_since_epoch_in_ms();
|
||||
std::cerr << "[" << std::fixed << std::setprecision(3) << time_ms / 1000.0 << "] ";
|
||||
}
|
||||
|
||||
return std::cerr;
|
||||
}
|
||||
protected:
|
||||
std::ostringstream os;
|
||||
private:
|
||||
int level;
|
||||
};
|
||||
|
||||
@@ -40,10 +40,10 @@
|
||||
#include "config_unix.h"
|
||||
#include "config_win32.h"
|
||||
#endif
|
||||
#include "config_msvc.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <winsock2.h>
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#include "audio/audio.h"
|
||||
@@ -51,10 +51,6 @@
|
||||
#include "debug.h"
|
||||
#include "host.h"
|
||||
#include "lib_common.h"
|
||||
#if defined _MSC_VER && _MSC_VER <= 1800 // VS 2013
|
||||
#define constexpr
|
||||
#define noexcept
|
||||
#endif
|
||||
#include "rang.hpp"
|
||||
#include "utils/video_frame_pool.h"
|
||||
#include "video.h"
|
||||
|
||||
@@ -70,10 +70,6 @@
|
||||
#include "host.h"
|
||||
#include "lib_common.h"
|
||||
#include "video_display.h"
|
||||
#if defined _MSC_VER && _MSC_VER <= 1800 // VS 2013
|
||||
#define constexpr
|
||||
#define noexcept
|
||||
#endif
|
||||
#include "rang.hpp"
|
||||
#include "video.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user