PeriDyno 1.0.0
Loading...
Searching...
No Matches
Log.h
Go to the documentation of this file.
1
25#pragma once
26
27#include <mutex>
28#include <thread>
29#include <string>
30#include <fstream>
31#include <iostream>
32#include <ctime>
33#include <queue>
34#include <cstdio>
35#include <cassert>
36#include <cstdarg>
37#include <atomic>
38#include <condition_variable>
39
40namespace dyno
41{
42 class Log
43 {
44 public:
53
54 struct Message {
56 std::string text;
57 tm* when;
58 };
59
60 static Log* instance();
61
62
69 static void sendMessage(MessageType type, const std::string& text);
70
74 static void setUserReceiver(void (*userFunc)(const Message&));
75
79 static void setLevel(MessageType level);
80
84 static void setOutput(const std::string& filename);
85
89 static const std::string& getOutput();
90
91 private:
92
93 Log();
94 ~Log();
95
96 void outputThread();
97
98 //Add a new message to log
99 void writeMessage(MessageType level, const char* format, ...);
100
101 private:
103
104 std::mutex mtx;
105 std::thread mThread;
106 std::condition_variable mCondition;
107
108 static std::atomic<Log*> sLogInstance;
109
110 static std::queue<Message> sMessageQueue;
112 static std::string sOutputFile;
113 static std::ofstream sOutputStream;
114 static void (*receiver)(const Message&);
115 };
116}
bool mRunning
Definition Log.h:102
static void(* receiver)(const Message &)
Definition Log.h:114
MessageType
Definition Log.h:46
@ Warning
Warning information.
Definition Log.h:49
@ Info
Information to user.
Definition Log.h:48
@ User
User specific message.
Definition Log.h:51
@ DebugInfo
Message with some debug information.
Definition Log.h:47
@ Error
Error information while executing something.
Definition Log.h:50
std::condition_variable mCondition
Definition Log.h:106
std::thread mThread
Definition Log.h:105
static void setLevel(MessageType level)
Set minimum level of message to be logged to file.
Definition Log.cpp:62
static std::queue< Message > sMessageQueue
Definition Log.h:110
static std::ofstream sOutputStream
Definition Log.h:113
static MessageType sLogLevel
Definition Log.h:111
static std::string sOutputFile
Definition Log.h:112
void writeMessage(MessageType level, const char *format,...)
Definition Log.cpp:24
std::mutex mtx
Definition Log.h:104
void outputThread()
Definition Log.cpp:120
static std::atomic< Log * > sLogInstance
Definition Log.h:108
static void setUserReceiver(void(*userFunc)(const Message &))
Set user function to receive newly sent messages to logger.
Definition Log.cpp:57
static const std::string & getOutput()
Get the filename of log.
Definition Log.cpp:81
static void sendMessage(MessageType type, const std::string &text)
Add a new message to log.
Definition Log.cpp:41
static void setOutput(const std::string &filename)
Open file where to log the messages.
Definition Log.cpp:67
static Log * instance()
Definition Log.cpp:86
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
std::string text
Definition Log.h:56
MessageType type
Definition Log.h:55