130 lines
3.8 KiB
C++
130 lines
3.8 KiB
C++
/***********************************************************************
|
|
* flog.h - Interface of the FINAL CUT 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/>. *
|
|
***********************************************************************/
|
|
|
|
/* Standalone class
|
|
* ════════════════
|
|
*
|
|
* ▕▔▔▔▔▔▔▏
|
|
* ▕ FLog ▏
|
|
* ▕▁▁▁▁▁▁▏
|
|
*/
|
|
|
|
#ifndef FLOG_H
|
|
#define FLOG_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 <ostream>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
#include <final/fstring.h>
|
|
|
|
namespace finalcut
|
|
{
|
|
|
|
using namespace std::placeholders;
|
|
|
|
//----------------------------------------------------------------------
|
|
// class FLog
|
|
//----------------------------------------------------------------------
|
|
|
|
class FLog : public std::stringbuf
|
|
{
|
|
public:
|
|
// Using-declaration
|
|
using FLogPrint = std::function<void(const std::string&)>;
|
|
|
|
// Enumerations
|
|
enum LogLevel
|
|
{
|
|
Info, Warn, Error, Debug
|
|
};
|
|
|
|
enum LineEnding
|
|
{
|
|
LF, CR, CRLF
|
|
};
|
|
|
|
|
|
// Constructor
|
|
FLog();
|
|
|
|
// Destructor
|
|
~FLog() override;
|
|
|
|
template <typename T>
|
|
FLog& operator << (const T& s);
|
|
FLog& operator << (std::ostream&(*)(std::ostream&));
|
|
FLog& operator << (LogLevel);
|
|
|
|
virtual const FString getClassName() const;
|
|
virtual void info (const std::string&) = 0;
|
|
virtual void warn (const std::string&) = 0;
|
|
virtual void error (const std::string&) = 0;
|
|
virtual void debug (const std::string&) = 0;
|
|
virtual void setOutputStream (const std::ostream&) = 0;
|
|
virtual void setLineEnding (LineEnding) = 0;
|
|
virtual void enableTimestamp() = 0;
|
|
virtual void disableTimestamp() = 0;
|
|
|
|
protected:
|
|
int sync() override;
|
|
|
|
// Data member
|
|
LogLevel level{Info};
|
|
LineEnding end_of_line{CRLF};
|
|
|
|
private:
|
|
// Data member
|
|
FLogPrint current_log{std::bind(&FLog::info, this, _1)};
|
|
std::ostream stream{this};
|
|
};
|
|
|
|
// FLog inline functions
|
|
//----------------------------------------------------------------------
|
|
template <typename T>
|
|
inline FLog& FLog::operator << (const T& s)
|
|
{
|
|
stream << s;
|
|
return *this;
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
inline FLog& FLog::operator << (std::ostream&(*pf)(std::ostream&))
|
|
{
|
|
pf(stream);
|
|
return *this;
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
inline const FString FLog::getClassName() const
|
|
{ return "FLog"; }
|
|
|
|
} // namespace finalcut
|
|
|
|
#endif // FLOG_H
|