Parameter to specify a logging file
This commit is contained in:
parent
c1b2699e53
commit
0ff67da077
|
@ -1,3 +1,7 @@
|
||||||
|
2020-06-07 Markus Gans <guru.mail@muenster.de>
|
||||||
|
* The --log-file parameter stores log output to any file. The file
|
||||||
|
can be viewed directly on another terminal with "tail -f".
|
||||||
|
|
||||||
2020-06-06 Markus Gans <guru.mail@muenster.de>
|
2020-06-06 Markus Gans <guru.mail@muenster.de>
|
||||||
* Now, the terminal is not initialized before the method show()
|
* Now, the terminal is not initialized before the method show()
|
||||||
is called. Or you force it explicitly via the FApplication object.
|
is called. Or you force it explicitly via the FApplication object.
|
||||||
|
|
|
@ -163,6 +163,10 @@ class DirectLogger final : public finalcut::FLog
|
||||||
// An implementation is not required in this context
|
// An implementation is not required in this context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void flush() override
|
||||||
|
{
|
||||||
|
output.flush();
|
||||||
|
}
|
||||||
|
|
||||||
void setOutputStream (const std::ostream& os) override
|
void setOutputStream (const std::ostream& os) override
|
||||||
{ output.rdbuf(os.rdbuf()); }
|
{ output.rdbuf(os.rdbuf()); }
|
||||||
|
|
|
@ -310,7 +310,7 @@ int main (int argc, char* argv[])
|
||||||
// Force terminal initialization without calling show()
|
// Force terminal initialization without calling show()
|
||||||
term_app.initTerminal();
|
term_app.initTerminal();
|
||||||
|
|
||||||
if ( term_app.isQuit() )
|
if ( finalcut::FApplication::isQuit() )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
std::cout << "--------\r\nFTermcap\r\n--------\r\n\n";
|
std::cout << "--------\r\nFTermcap\r\n--------\r\n\n";
|
||||||
|
|
|
@ -1067,9 +1067,6 @@ int main (int argc, char* argv[])
|
||||||
finalcut::FTerm::redefineDefaultColors(true);
|
finalcut::FTerm::redefineDefaultColors(true);
|
||||||
finalcut::FTerm::setTermTitle (title);
|
finalcut::FTerm::setTermTitle (title);
|
||||||
|
|
||||||
// Force vt100 encoding
|
|
||||||
//finalcut::FTerm::setEncoding(finalcut::fc::VT100);
|
|
||||||
|
|
||||||
// Sets the terminal size to 94×30
|
// Sets the terminal size to 94×30
|
||||||
//finalcut::FTerm::setTermSize(FSize{94, 30});
|
//finalcut::FTerm::setTermSize(FSize{94, 30});
|
||||||
|
|
||||||
|
|
|
@ -84,12 +84,12 @@ SmallWindow::SmallWindow (finalcut::FWidget* parent)
|
||||||
right_arrow.ignorePadding();
|
right_arrow.ignorePadding();
|
||||||
right_arrow.setGeometry (FPoint{int(getWidth()) - 1, 2}, FSize{1, 1});
|
right_arrow.setGeometry (FPoint{int(getWidth()) - 1, 2}, FSize{1, 1});
|
||||||
|
|
||||||
top_left_label = "menu";
|
top_left_label.setText("menu");
|
||||||
top_left_label.setForegroundColor (wc->label_inactive_fg);
|
top_left_label.setForegroundColor (wc->label_inactive_fg);
|
||||||
top_left_label.setEmphasis();
|
top_left_label.setEmphasis();
|
||||||
top_left_label.setGeometry (FPoint{1, 1}, FSize{6, 1});
|
top_left_label.setGeometry (FPoint{1, 1}, FSize{6, 1});
|
||||||
|
|
||||||
top_right_label = "zoom";
|
top_right_label.setText("zoom");
|
||||||
top_right_label.setAlignment (fc::alignRight);
|
top_right_label.setAlignment (fc::alignRight);
|
||||||
top_right_label.setForegroundColor (wc->label_inactive_fg);
|
top_right_label.setForegroundColor (wc->label_inactive_fg);
|
||||||
top_right_label.setEmphasis();
|
top_right_label.setEmphasis();
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
* <http://www.gnu.org/licenses/>. *
|
* <http://www.gnu.org/licenses/>. *
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -366,7 +367,56 @@ void FApplication::init (uInt64 key_time, uInt64 dblclick_time)
|
||||||
mouse->setDblclickInterval (dblclick_time);
|
mouse->setDblclickInterval (dblclick_time);
|
||||||
|
|
||||||
// Initialize logging
|
// Initialize logging
|
||||||
getLog()->setLineEnding(FLog::CRLF);
|
if ( ! getStartOptions().logfile_stream.is_open() )
|
||||||
|
getLog()->setLineEnding(FLog::CRLF);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FApplication::setTerminalEncoding (const FString& enc_str)
|
||||||
|
{
|
||||||
|
const FString& enc = enc_str.toLower();
|
||||||
|
|
||||||
|
if ( enc.includes("utf8") )
|
||||||
|
getStartOptions().encoding = fc::UTF8;
|
||||||
|
else if ( enc.includes("vt100") )
|
||||||
|
getStartOptions().encoding = fc::VT100;
|
||||||
|
else if ( enc.includes("pc") )
|
||||||
|
getStartOptions().encoding = fc::PC;
|
||||||
|
else if ( enc.includes("ascii") )
|
||||||
|
getStartOptions().encoding = fc::ASCII;
|
||||||
|
else if ( enc.includes("help") )
|
||||||
|
showParameterUsage();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto ftermdata = FTerm::getFTermData();
|
||||||
|
ftermdata->setExitMessage ( "Unknown encoding \"" + enc_str
|
||||||
|
+ "\"\n(Valid encodings are utf8, "
|
||||||
|
+ "vt100, pc and ascii)" );
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FApplication::setLogFile (const FString& filename)
|
||||||
|
{
|
||||||
|
// Get the global logger object
|
||||||
|
FLog& log = *FApplication::getLog();
|
||||||
|
auto& log_stream = getStartOptions().logfile_stream;
|
||||||
|
log_stream.open(filename, std::ofstream::out);
|
||||||
|
|
||||||
|
if ( log_stream.is_open() )
|
||||||
|
{
|
||||||
|
log.setOutputStream(log_stream);
|
||||||
|
log.enableTimestamp();
|
||||||
|
log.setLineEnding (finalcut::FLog::LF);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto ftermdata = FTerm::getFTermData();
|
||||||
|
ftermdata->setExitMessage ( "Could not open log file \""
|
||||||
|
+ FString(optarg) + "\"" );
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@ -379,6 +429,7 @@ void FApplication::cmd_options (const int& argc, char* argv[])
|
||||||
static struct option long_options[] =
|
static struct option long_options[] =
|
||||||
{
|
{
|
||||||
{"encoding", required_argument, nullptr, 0 },
|
{"encoding", required_argument, nullptr, 0 },
|
||||||
|
{"log-file", required_argument, nullptr, 0 },
|
||||||
{"no-mouse", no_argument, nullptr, 0 },
|
{"no-mouse", no_argument, nullptr, 0 },
|
||||||
{"no-optimized-cursor", no_argument, nullptr, 0 },
|
{"no-optimized-cursor", no_argument, nullptr, 0 },
|
||||||
{"no-terminal-detection", no_argument, nullptr, 0 },
|
{"no-terminal-detection", no_argument, nullptr, 0 },
|
||||||
|
@ -409,28 +460,10 @@ void FApplication::cmd_options (const int& argc, char* argv[])
|
||||||
if ( c == 0 )
|
if ( c == 0 )
|
||||||
{
|
{
|
||||||
if ( std::strcmp(long_options[idx].name, "encoding") == 0 )
|
if ( std::strcmp(long_options[idx].name, "encoding") == 0 )
|
||||||
{
|
setTerminalEncoding(FString(optarg));
|
||||||
FString encoding{optarg};
|
|
||||||
encoding = encoding.toLower();
|
|
||||||
|
|
||||||
if ( encoding.includes("utf8") )
|
if ( std::strcmp(long_options[idx].name, "log-file") == 0 )
|
||||||
getStartOptions().encoding = fc::UTF8;
|
setLogFile(FString(optarg));
|
||||||
else if ( encoding.includes("vt100") )
|
|
||||||
getStartOptions().encoding = fc::VT100;
|
|
||||||
else if ( encoding.includes("pc") )
|
|
||||||
getStartOptions().encoding = fc::PC;
|
|
||||||
else if ( encoding.includes("ascii") )
|
|
||||||
getStartOptions().encoding = fc::ASCII;
|
|
||||||
else if ( encoding.includes("help") )
|
|
||||||
showParameterUsage();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto ftermdata = FTerm::getFTermData();
|
|
||||||
ftermdata->setExitMessage ( "Unknown encoding "
|
|
||||||
+ std::string(encoding.c_str()) );
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( std::strcmp(long_options[idx].name, "no-mouse") == 0 )
|
if ( std::strcmp(long_options[idx].name, "no-mouse") == 0 )
|
||||||
getStartOptions().mouse_support = false;
|
getStartOptions().mouse_support = false;
|
||||||
|
@ -488,10 +521,12 @@ void FApplication::showParameterUsage()
|
||||||
<< " Display this help and exit\n"
|
<< " Display this help and exit\n"
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< "The Final Cut options:\n"
|
<< "The Final Cut options:\n"
|
||||||
<< " --encoding <name> "
|
<< " --encoding=<MODE> "
|
||||||
<< " Sets the character encoding mode\n"
|
<< " Sets the character encoding mode\n"
|
||||||
<< " "
|
<< " "
|
||||||
<< " {utf8, vt100, pc, ascii}\n"
|
<< " {utf8, vt100, pc, ascii}\n"
|
||||||
|
<< " --log-file=<FILE> "
|
||||||
|
<< " Writes log output to FILE\n"
|
||||||
<< " --no-mouse "
|
<< " --no-mouse "
|
||||||
<< " Disable mouse support\n"
|
<< " Disable mouse support\n"
|
||||||
<< " --no-optimized-cursor "
|
<< " --no-optimized-cursor "
|
||||||
|
@ -1199,6 +1234,8 @@ void FApplication::processLogger()
|
||||||
|
|
||||||
if ( ! logger->str().empty() )
|
if ( ! logger->str().empty() )
|
||||||
logger->pubsync();
|
logger->pubsync();
|
||||||
|
|
||||||
|
logger->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
|
@ -147,6 +147,8 @@ class FApplication : public FWidget
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
void init (uInt64, uInt64);
|
void init (uInt64, uInt64);
|
||||||
|
static void setTerminalEncoding (const FString&);
|
||||||
|
static void setLogFile (const FString&);
|
||||||
static void cmd_options (const int&, char*[]);
|
static void cmd_options (const int&, char*[]);
|
||||||
static FStartOptions& getStartOptions();
|
static FStartOptions& getStartOptions();
|
||||||
static void showParameterUsage();
|
static void showParameterUsage();
|
||||||
|
|
|
@ -89,6 +89,7 @@ class FLog : public std::stringbuf
|
||||||
virtual void warn (const std::string&) = 0;
|
virtual void warn (const std::string&) = 0;
|
||||||
virtual void error (const std::string&) = 0;
|
virtual void error (const std::string&) = 0;
|
||||||
virtual void debug (const std::string&) = 0;
|
virtual void debug (const std::string&) = 0;
|
||||||
|
virtual void flush() = 0;
|
||||||
virtual void setOutputStream (const std::ostream&) = 0;
|
virtual void setOutputStream (const std::ostream&) = 0;
|
||||||
virtual void setLineEnding (LineEnding) = 0;
|
virtual void setLineEnding (LineEnding) = 0;
|
||||||
virtual void enableTimestamp() = 0;
|
virtual void enableTimestamp() = 0;
|
||||||
|
|
|
@ -77,6 +77,7 @@ class FLogger : public FLog
|
||||||
void warn (const std::string&) override;
|
void warn (const std::string&) override;
|
||||||
void error (const std::string&) override;
|
void error (const std::string&) override;
|
||||||
void debug (const std::string&) override;
|
void debug (const std::string&) override;
|
||||||
|
void flush() override;
|
||||||
void setOutputStream (const std::ostream&) override;
|
void setOutputStream (const std::ostream&) override;
|
||||||
void setLineEnding (LineEnding) override;
|
void setLineEnding (LineEnding) override;
|
||||||
void enableTimestamp() override;
|
void enableTimestamp() override;
|
||||||
|
@ -127,6 +128,10 @@ inline void FLogger::debug (const std::string& msg)
|
||||||
printLogLine (msg);
|
printLogLine (msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
inline void FLogger::flush()
|
||||||
|
{ output.flush(); }
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
inline void FLogger::setOutputStream (const std::ostream& os)
|
inline void FLogger::setOutputStream (const std::ostream& os)
|
||||||
{ output.rdbuf(os.rdbuf()); }
|
{ output.rdbuf(os.rdbuf()); }
|
||||||
|
|
|
@ -35,7 +35,8 @@
|
||||||
#error "Only <final/final.h> can be included directly."
|
#error "Only <final/final.h> can be included directly."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <iostream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "final/fc.h"
|
#include "final/fc.h"
|
||||||
#include "final/fstring.h"
|
#include "final/fstring.h"
|
||||||
|
@ -82,7 +83,6 @@ class FStartOptions final
|
||||||
uInt8 sgr_optimizer : 1;
|
uInt8 sgr_optimizer : 1;
|
||||||
uInt8 vgafont : 1;
|
uInt8 vgafont : 1;
|
||||||
uInt8 newfont : 1;
|
uInt8 newfont : 1;
|
||||||
fc::encoding encoding{fc::UNKNOWN};
|
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST)
|
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST)
|
||||||
uInt8 meta_sends_escape : 1;
|
uInt8 meta_sends_escape : 1;
|
||||||
|
@ -95,6 +95,9 @@ class FStartOptions final
|
||||||
|
|
||||||
uInt16 dark_theme : 1;
|
uInt16 dark_theme : 1;
|
||||||
uInt16 : 15; // padding bits
|
uInt16 : 15; // padding bits
|
||||||
|
|
||||||
|
fc::encoding encoding{fc::UNKNOWN};
|
||||||
|
std::ofstream logfile_stream;
|
||||||
static FStartOptions* start_options;
|
static FStartOptions* start_options;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -59,17 +59,28 @@ class myLogger : public finalcut::FLog
|
||||||
output << "Debug: " << entry << std::endl;
|
output << "Debug: " << entry << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void flush() override
|
||||||
|
{
|
||||||
|
// An implementation is not required in this context
|
||||||
|
}
|
||||||
|
|
||||||
void setOutputStream (const std::ostream& os) override
|
void setOutputStream (const std::ostream& os) override
|
||||||
{ output.rdbuf(os.rdbuf()); }
|
{ output.rdbuf(os.rdbuf()); }
|
||||||
|
|
||||||
void setLineEnding (LineEnding) override
|
void setLineEnding (LineEnding) override
|
||||||
{ }
|
{
|
||||||
|
// An implementation is not required in this context
|
||||||
|
}
|
||||||
|
|
||||||
void enableTimestamp() override
|
void enableTimestamp() override
|
||||||
{ }
|
{
|
||||||
|
// An implementation is not required in this context
|
||||||
|
}
|
||||||
|
|
||||||
void disableTimestamp() override
|
void disableTimestamp() override
|
||||||
{ }
|
{
|
||||||
|
// An implementation is not required in this context
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Data member
|
// Data member
|
||||||
|
|
Loading…
Reference in New Issue