-Wl,-rpath-link,$(CROSSROOT)/opt/vc/lib -Wl,-rpath-link,$(CROSSROOT)/usr/lib/arm-linux-gnueabihf \
-L=/opt/vc/lib -L=/usr/lib/arm-linux-gnueabihf
LIBPATHS =
-LIBS = -lpthread -lstdc++ -lrt -lbrcmEGL -lbrcmOpenVG -lopenmaxil -lbcm_host -lavformat -lavcodec \
+LIBS = -lpthread -lstdc++ -lrt -lbrcmEGL -lbrcmOpenVG -lopenmaxil -lbcm_host -lavformat -lavcodec -lfmt \
-lavutil -lswresample -lm -ldl -lfontconfig -lfreetype -lMagick++-6.Q16 -lMagickWand-6.Q16 -lMagickCore-6.Q16 -ljsoncpp
OBJECTS = $(OBJ_COMMON) $(OBJ_RASPBERRY)
INCLUDES = -isystem=/usr/include/arm-linux-gnueabihf -isystem=/opt/vc/include -isystem=/usr/include/freetype2 -isystem=/usr/include/arm-linux-gnueabihf/ImageMagick-6 -isystem=/usr/include/ImageMagick-6
-CXXFLAGS_DEV = $(DEFINES) -DDEV -g -O0 -Wall -Wextra -Wshadow -Werror=return-type -Wmissing-format-attribute -Wdisabled-optimization -Wmissing-declarations -Wmissing-noreturn -Winit-self -Woverloaded-virtual -Wold-style-cast -Wconversion -std=c++14 $(CXXFLAGS_EXTRA) $(INCLUDES)
+#CXXFLAGS_DEV = $(DEFINES) -DDEV -g -O0 -Wall -Wextra -Wshadow -Werror=return-type -Wmissing-format-attribute -Wdisabled-optimization -Wmissing-declarations -Wmissing-noreturn -Winit-self -Woverloaded-virtual -Wold-style-cast -Wconversion -std=c++14 $(CXXFLAGS_EXTRA) $(INCLUDES)
+CXXFLAGS_DEV = $(DEFINES) -DDEV -g -O0 -std=c++14 $(CXXFLAGS_EXTRA) $(INCLUDES)
CXXFLAGS_REL = $(DEFINES) -O3 -Wall -Werror -std=c++14 $(CXXFLAGS_EXTRA) $(INCLUDES)
.PHONY: clean fresh all install strip
--- /dev/null
+#include <iostream>
+
+#include "log.h"
+
+LogNT* LogNT::instance = NULL;
+
+LogNT::LogNT()
+{
+ instance = this;
+}
+
+LogNT::~LogNT()
+{
+ instance = NULL;
+}
+
+LogNT* LogNT::getInstance()
+{
+ return instance;
+}
+
+bool LogNT::init(const std::string& tfileName, bool tenabled)
+{
+ if (!tenabled) return true;
+
+ enabled = true;
+ fileName = tfileName; // Keep the filename for later?
+
+ if (!fileName.compare("stdout"))
+ {
+ outstream = &std::cout;
+ return true;
+ }
+
+ outstream = &logFile;
+ logFile.open(fileName);
+ if (!logFile.is_open()) return false;
+
+ return true;
+}
--- /dev/null
+/*
+ Copyright 2021 Chris Tallon
+
+ This file is part of VOMP.
+
+ VOMP is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ VOMP is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with VOMP. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#ifndef LOGNT_H
+#define LOGNT_H
+
+#include <string>
+#include <cstdarg>
+#include <iostream>
+#include <fstream>
+#include <mutex>
+#include <thread>
+#include <iomanip>
+#include <fmt/core.h>
+#include <fmt/ostream.h>
+#include <sys/time.h>
+
+#include "defines.h"
+
+
+class LogNT
+{
+ public:
+ LogNT();
+ ~LogNT();
+ static LogNT* getInstance();
+
+ bool init(const std::string& fileName, bool enabled);
+
+ enum levels { TRACE, DEBUG, INFO, WARN, ERROR, CRIT };
+
+ template<typename... Ts> void trace(const char* TAG, Ts... args) { log(TAG, TRACE, args...); }
+ template<typename... Ts> void debug(const char* TAG, Ts... args) { log(TAG, DEBUG, args...); }
+ template<typename... Ts> void info (const char* TAG, Ts... args) { log(TAG, INFO, args...); }
+ template<typename... Ts> void warn (const char* TAG, Ts... args) { log(TAG, WARN, args...); }
+ template<typename... Ts> void error(const char* TAG, Ts... args) { log(TAG, ERROR, args...); }
+ template<typename... Ts> void crit (const char* TAG, Ts... args) { log(TAG, CRIT, args...); }
+
+
+
+
+ template<typename T, typename... Ts>
+ void log(const char* TAG, int level, T fmtString, Ts... args)
+ {
+ if (!enabled) return;
+
+ struct timeval tv;
+ struct tm tms;
+ gettimeofday(&tv, NULL);
+ LOCALTIME_R(&tv.tv_sec, &tms);
+
+ std::lock_guard<std::mutex> lg(outLock);
+
+ *outstream << std::setfill('0')
+ << std::setw(2) << tms.tm_hour << ":"
+ << std::setw(2) << tms.tm_min << ":"
+ << std::setw(2) << tms.tm_sec << "."
+ << std::setw(6) << tv.tv_usec;
+
+ switch(level)
+ {
+ case TRACE: *outstream << " [trace] "; break;
+ case DEBUG: *outstream << " [debug] "; break;
+ case INFO: *outstream << " [info] "; break;
+ case WARN: *outstream << " [warn] "; break;
+ case ERROR: *outstream << " [error] "; break;
+ case CRIT: *outstream << " [CRIT] "; break;
+ }
+
+ *outstream << " " << std::this_thread::get_id() << " " << TAG << " - ";
+ fmt::print(*outstream, fmtString, args...);
+ *outstream << std::endl;
+ }
+
+ private:
+ static LogNT* instance;
+
+ bool enabled{};
+ std::string fileName;
+ std::ofstream logFile;
+ std::mutex outLock;
+ std::ostream* outstream;
+};
+
+#endif
#endif
#include "config.h"
+#include "log.h"
#include "oldlog.h"
#include "util.h"
#include "control.h"
Config* config;
Log* logger;
+LogNT* loggerNT;
Control* control;
// Temporary, will move to Config system NCONFIG
struct vt_mode old_vtmode;
#endif
+const char* TAG = "Main";
+
// Linux main function and sighandler
#ifndef WIN32
int main(int argc, char** argv)
shutdown(1);
}
- logger->log("Main", Log::INFO, "Starting up...");
+ logger->log("Main", Log::INFO, "Old log starting up...");
+
+
+
+ loggerNT = new LogNT();
+ if (!loggerNT)
+ {
+ printf("Failed to create LogNT object\n");
+ shutdown(1);
+ }
+
+ if (!loggerNT->init("stdout", debugEnabled ? 1 : 0)) // NCONFIG x2
+ {
+ printf("Could not initialise log object. Aborting.\n");
+ shutdown(1);
+ }
+
+ //logger->log("Main", Log::INFO, "Starting up...");
+ loggerNT->info(TAG, "Starting up...");
// Daemonize --------------------------------------------------------------------------------------------------
int sigBlockResult = pthread_sigmask(SIG_SETMASK, &set, NULL);
if (sigBlockResult)
{
- logger->log("Main", Log::EMERG, "Could not block signals: %i", sigBlockResult);
+ //logger->log("Main", Log::EMERG, "Could not block signals: %i", sigBlockResult);
+ loggerNT->crit(TAG, "Could not block signals: {}", sigBlockResult);
shutdown(1);
}
std::thread threadSignalReceiver(threadSignalReceiverFunction);
threadSignalReceiver.detach();
- logger->log("Main", Log::INFO, "Signal handlers set up successfully");
+ loggerNT->info(TAG, "Signal handlers set up successfully");
// VT Switching -----------------------------------------------------------------------------------------------
)
{
- logger->log("Main", Log::EMERG, "Could not open /dev/tty. Please change permissions");
+ loggerNT->warn(TAG, "Could not open /dev/tty. Please change permissions");
}
else
{
int free_vt;
if (ioctl(fdtty, VT_OPENQRY, &free_vt) == -1 || free_vt == -1)
{
- logger->log("Main", Log::EMERG, "Could not retrieve free virtual console, please change permissions");
+ loggerNT->crit(TAG, "Could not retrieve free virtual console, please change permissions");
}
else
{
// Test area ------------------------------------------------------------------------------------------------------
-
+ //shutdown(0);
// Run control ----------------------------------------------------------------------------------------------------
control = new Control();
if (!control)
{
- logger->log("Main", Log::EMERG, "Control module failed to create");
+ loggerNT->crit(TAG, "Control module failed to create");
shutdown(1);
}
if (!control->init(crashed))
{
- logger->log("Main", Log::EMERG, "Control module failed to initialise");
+ loggerNT->crit(TAG, "Control module failed to initialise");
delete control;
control = NULL;
shutdown(1);
{
if(sigwait(&set, &sig))
{
- logger->log("Main", Log::CRIT, "Sigwait returned fail - signal handler exiting");
+ loggerNT->crit(TAG, "Sigwait returned fail - signal handler exiting");
return;
}
- logger->log("Main", Log::NOTICE, "Signal received: %i", sig);
+ loggerNT->info(TAG, "Signal received: {}", sig);
if ((sig == SIGINT) || (sig == SIGTERM)) control->stop();
}
{
delete control;
control = NULL;
- logger->log("Main", Log::NOTICE, "Control module shut down");
+ loggerNT->info(TAG, "Control module shut down");
}
#ifdef HANDLE_VT_SWITCHING
if (logger)
{
- logger->log("Main", Log::NOTICE, "Log module shutting down... bye!\n\n");
+ loggerNT->info(TAG, "Log module shutting down... bye!\n\n");
logger->shutdown();
delete logger;
}
wprogressbar.o bitmap.o dvbsubtitles.o tfeed.o vteletextview.o \
teletextdecodervbiebu.o teletxt/txtfont.o movieinfo.o seriesinfo.o \
wmovieview.o wseriesview.o tvmedia.o wtvmedia.o wpictureview.o \
- osdvector.o surfacevector.o buffer.o config.o \
+ osdvector.o surfacevector.o buffer.o config.o log.o \
playervideorec.o playervideolive.o playerradiolive.o playerradiorec.o
OBJ_RASPBERRY = main.o threadp.o osdopenvg.o \
int init(int defaultLevel,const char* fileName, int enabled);
int shutdown();
+
+ [[deprecated]]
int log(const char *fromModule, int level,const char *message, ...);
+
+ [[deprecated]]
void logLongString(const char *fromModule, int level,const char *message);
int status();
void upLogLevel();
void downLogLevel();
+ [[deprecated]]
void setExternLogger(ExternLogger* log);
+ [[deprecated]]
void unsetExternLogger() {
extlog=NULL;
}