21 std::cout << s << std::flush;
25 ss << s << std::flush;
30 ss.str(std::string());
43 stream = makeAuto<std::ofstream>();
47 stream->open(path.
native(), mode);
49 throw IoError(
"Error opening FileLogger at " + path.
native());
57 auto write = [
this](
const std::string& s) {
59 std::time_t t = std::time(
nullptr);
60 *stream << std::put_time(std::localtime(&t),
"%b %d, %H:%M:%S -- ");
62 *stream << s << std::flush;
66 stream->open(path.
native(), std::ostream::app);
90 std::string printedName = functionName;
91 std::size_t n = printedName.find(
'(');
92 if (n != std::string::npos) {
94 printedName = printedName.substr(0, n);
97 printedName =
replaceAll(printedName,
"Sph::",
"");
103 const std::string prefix = std::string(4 * context.
indent,
' ') + std::to_string(context.
indent);
115 const std::string prefix = std::string(4 * context.
indent,
' ');
123 context.
logger = std::move(logger);
#define SPH_ASSERT(x,...)
void setVerboseLogger(AutoPtr< ILogger > &&logger)
Creates a global verbose logger.
Logging routines of the run.
#define NAMESPACE_SPH_END
std::string replaceFirst(const std::string &source, const std::string &old, const std::string &s)
Replaces first occurence of string with a new string.
std::string replaceAll(const std::string &source, const std::string &old, const std::string &s)
Replaces all occurences of string with a new string.
virtual void writeString(const std::string &s) override
Logs a string message.
FileLogger(const Path &path, const Flags< Options > flags=EMPTY_FLAGS)
@ ADD_TIMESTAMP
Adds a time of writing before each message.
constexpr INLINE bool has(const TEnum flag) const
Checks if the object has a given flag.
virtual void writeString(const std::string &s)=0
Logs a string message.
void write(TArgs &&... args)
Creates and logs a message by concatenating arguments.
Exception thrown when file cannot be read, it has invalid format, etc.
Object representing a path on a filesystem.
std::string native() const
Returns the native version of the path.
Path parentPath() const
Returns the parent directory. If the path is empty or root, return empty path.
virtual void writeString(const std::string &s) override
Logs a string message.
virtual void writeString(const std::string &s) override
Logs a string message.
void clean()
Removes all written messages from the string.
std::string toString() const
Returns all written messages as a string. Messages are not erased from the logger by this.
int64_t elapsed(const TimerUnit unit) const
Returns elapsed time in timer units. Does not reset the timer.
VerboseLogGuard(const std::string &functionName)
Creates a guard, should be at the very beginning of a function/scope.
Outcome createDirectory(const Path &path, const Flags< CreateDirectoryFlag > flags=CreateDirectoryFlag::ALLOW_EXISTING)
Creates a directory with given path. Creates all parent directories as well.
ScopedConsole(const Console console)
AutoPtr< ILogger > logger