3 #include "ScopeLogger.h"
4 #include "helpers/Active.h"
5 #include "parameters/Scope.h"
7 #include "gui/LogFrame.h"
54 DBOUT(L
"" << message.c_str());
60 logbookentries.push_back(message+L
"\r\n");
63 if ( logframe !=
nullptr )
64 logbooktext = logframe->GetLogText();
67 if ( logbooktext.length() > 2 )
68 if ( logbooktext.substr(logbooktext.length()-2, 2) != L
"\r\n" )
69 logbooktext += L
"\r\n";
72 logbooktext += message+L
"\r\n";
83 if ( logframe !=
nullptr )
84 logframe->ReplaceLogText(logbooktext);
86 if ( !userlogfile.is_open() )
87 userlogfile.open(file_path, std::ios_base::out | std::ios_base::trunc);
91 return ControllerReturnStatus::finished;
96 Impl(
const log_message_type& filem = log_all,
const log_message_type& consolem = log_all,
const log_message_type& logboxm = log_all)
99 , file_messages(filem)
100 , console_message(consolem)
101 , logframe_message(logboxm)
103 , logbookentries(1, L
"")
105 Log(L
"Logbook started", log_info);
109 if ( userlogfile.is_open() )
114 void SetFilepath(
const std::wstring& _filepath = L
"C:\\ScopeData") {
115 if ( !filepath_set ) {
118 userlogfile.open(file_path);
119 if ( userlogfile.bad() )
120 throw std::invalid_argument(
"Unable to open user log file\n");
125 Log(L
"Logfile started", log_info);
130 void Log(
const std::wstring& message,
const log_message_type& msgtype) {
133 std::wostringstream logmsg;
134 logmsg << st.wHour << L
":" << std::setfill(L
'0') << std::setw(2) << st.wMinute << L
"::" << st.wSecond << L
" - ";
143 logframe = _logframe;
149 return this->logframe->m_hWnd;
154 return logframe!=
nullptr;
159 if ( logframe !=
nullptr )
160 logbooktext = logframe->GetLogText();
166 logbooktext = logframe->GetLogText();
Impl(const log_message_type &filem=log_all, const log_message_type &consolem=log_all, const log_message_type &logboxm=log_all)
Create logfiles.
std::wofstream userlogfile
File with user comments and logging of performed scans etc.
Active< ControllerReturnStatus > active
Active object for running the loggings.
Thread-safe lock-free bool to signal a requested stop to the worker function currently executed in th...
void Quit()
Send lambda with done=true to the worker, join the worker thread, and clear the packaged task queue...
void GetUserLoggings()
Gets the text in the logbook window and calls FlushLogbox.
ControllerReturnStatus WriteToLogbox(StopCondition *const sc, const std::wstring message, const log_message_type msgtype)
Writes message to the logbook window.
std::wstring logbooktext
the complete log text as a string
Impl(const Impl &i)
disable copy
ControllerReturnStatus FlushLogbox(StopCondition *const sc)
Updates the logbook window , writes complete logbook to disk, overwrites the old logbook on disk...
void SetFilepath(const std::wstring &_filepath=L"C:\\ScopeData")
Sets the filepath and creates logfile.
Implementation class of the ScopeLogger.
gui::CLogFrame * logframe
pointer to the log window frame
std::future< RT > Send(const Command &_cmd)
Sends a worker function/packaged task to the queue to be executed in the Active's thread...
log_message_type console_message
which message types to print out on debug console
std::wstring GetCurrentDateString()
In here all declarations for all kinds of datatypes Scope needs.
Frame window class for the log.
void AttachLogFrame(gui::CLogFrame *const _logframe)
Attaches a CLogFrame as the logbook window.
#define DBOUT(s)
A debug output to the debug console.
Impl operator=(const Impl &i)
disable assignment
ControllerReturnStatus WriteToConsole(StopCondition *const sc, const std::wstring message)
Writes message to debug console.
void DetachLogFrame()
Detaches a CLogFrame.
void Shutdown()
Shutdown the Active, called from Run in scope.cpp.
log_message_type file_messages
which message types to save to disk
bool filepath_set
true if file path set and files opened
std::wstring file_path
path string for log file
log_message_type logframe_message
which message types to print in log frame
void Log(const std::wstring &message, const log_message_type &msgtype)
Logs a message.
std::list< std::wstring > logbookentries
a vector of all log entries done by scope
HWND GetLogFrameWindow()
Saves log frame parameters into Window (for recreating windows on startup)
std::wstring GetCurrentTimeString(const bool &_filenamecompatible)