finalcut/src/include/final/flogger.h

149 lines
4.8 KiB
C
Raw Normal View History

2020-05-13 23:47:14 +02:00
/***********************************************************************
* flogger.h - The FINAL CUT text logger *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2020 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
2020-05-24 02:15:43 +02:00
/* Inheritance diagram
*
2020-05-13 23:47:14 +02:00
*
2020-05-24 02:15:43 +02:00
*
* std::stringbuf
*
*
*
*
* FLog
*
*
*
*
* FLogger
*
2020-05-13 23:47:14 +02:00
*/
#ifndef FLOGGER_H
#define FLOGGER_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <chrono>
#include <iomanip>
#include "final/flog.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FLogger
//----------------------------------------------------------------------
class FLogger : public FLog
{
public:
// Constructor
FLogger();
// Destructor
~FLogger() override;
// Methods
const FString getClassName() const override;
void info (const std::string&) override;
void warn (const std::string&) override;
void error (const std::string&) override;
void debug (const std::string&) override;
void setOutputStream (const std::ostream&) override;
void setLineEnding (LineEnding) override;
void enableTimestamp() override;
void disableTimestamp() override;
private:
// Methods
void newlineReplace (std::string&, const std::string&);
const std::string getTimeString();
const std::string getEOL();
void printLogLine (const std::string&);
// Data member
bool timestamp{false};
std::ostream output{std::cerr.rdbuf()};
};
// FLogger inline functions
//----------------------------------------------------------------------
inline const FString FLogger::getClassName() const
{ return "FLogger"; }
//----------------------------------------------------------------------
inline void FLogger::info (const std::string& msg)
{
setLevel() = Info;
2020-05-13 23:47:14 +02:00
printLogLine (msg);
}
//----------------------------------------------------------------------
inline void FLogger::warn (const std::string& msg)
{
setLevel() = Warn;
2020-05-13 23:47:14 +02:00
printLogLine (msg);
}
//----------------------------------------------------------------------
inline void FLogger::error (const std::string& msg)
{
setLevel() = Error;
2020-05-13 23:47:14 +02:00
printLogLine (msg);
}
//----------------------------------------------------------------------
inline void FLogger::debug (const std::string& msg)
{
setLevel() = Debug;
2020-05-13 23:47:14 +02:00
printLogLine (msg);
}
//----------------------------------------------------------------------
inline void FLogger::setOutputStream (const std::ostream& os)
{ output.rdbuf(os.rdbuf()); }
//----------------------------------------------------------------------
inline void FLogger::setLineEnding (LineEnding eol)
{ setEnding() = eol; }
2020-05-13 23:47:14 +02:00
//----------------------------------------------------------------------
inline void FLogger::enableTimestamp()
{ timestamp = true; }
//----------------------------------------------------------------------
inline void FLogger::disableTimestamp()
{ timestamp = false; }
} // namespace finalcut
#endif // FLOGGER_H