Flow123d
JS_before_hm-1822-gbb48b12e9
|
Go to the documentation of this file.
29 if( a.size() > b.size() )
std::swap(a,b) ;
30 return std::string( a.begin(), std::mismatch( a.begin(), a.end(), b.begin() ).first ) ;
65 : type_(type), every_process_(false), line_(0)
88 "Wrn",
"Msg",
"Log",
"Dbg",
"Err"};
89 int type_idx = msg_type;
92 return type_names[type_idx];
94 return type_names[type_idx + 5];
126 case MsgType::warning:
133 case MsgType::message:
147 #ifdef FLOW123D_DEBUG
175 stream << setfill(
' ');
179 std::stringstream message_stream;
184 std::istringstream istream(scr_stream.str());
185 while(std::getline(istream, segment)) {
189 message_stream << std::setw(18) <<
"";
191 message_stream << segment <<
"\n";
194 stream << message_stream.str();
195 stream << std::flush;
203 stream << setfill(
' ');
206 std::stringstream message_stream;
212 std::istringstream istream(file_stream.str());
213 while(std::getline(istream, segment)) {
214 segments.push_back(segment);
216 if (segments.size() > 1) {
217 message_stream <<
" - |" <<
"\n";
218 for (
auto seg : segments)
219 message_stream << std::setw(4) <<
"" << seg <<
"\n";
220 }
else if (segments.size() == 1) {
221 message_stream <<
" - " << segments[0] <<
"\n";
224 stream << message_stream.str();
225 stream << std::flush;
233 #ifdef FLOW123D_SOURCE_DIR
234 string common_path =
cmn_prefix(
string(FLOW123D_SOURCE_DIR), file_name);
235 file_name.erase (0, common_path.size());
246 stream << setiosflags(ios::left) << std::setw(5) << rank.str();
248 stream << std::setw(5) <<
"";
252 if (
type_ == MsgType::debug) {
261 stream <<
"- -" << std::setw(13) <<
"" <<
"[ ";
266 else stream <<
"null";
StreamMask streams_mask_
Mask of logger, specifies streams in actual time into which to be written.
static StreamMask cerr
Predefined mask of std::cerr output.
static const std::string msg_type_string(MsgType msg_type, bool full_format=true)
Return string value of given MsgType in full or shorter format (e.g. "WARNING" of "Wrn")
Helper class, store mask specifying streams.
static StreamMask log
Predefined mask of log file output.
bool every_process_
Flag marked if log message is printing for all processes or only for zero process.
void swap(nlohmann::json &j1, nlohmann::json &j2) noexcept(is_nothrow_move_constructible< nlohmann::json >::value and is_nothrow_move_assignable< nlohmann::json >::value)
exchanges the values of two JSON objects
std::stringstream cerr_stream_
Store messages printed to cerr output stream.
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
std::stringstream file_stream_
Store messages printed to file.
bool no_log_
Turn off logger file output.
void print_to_screen(std::ostream &stream, std::stringstream &scr_stream, StreamMask mask)
Print formated message to given screen stream if mask corresponds with streams_mask_.
std::string file_name_
Actual file.
bool print_screen_header(std::stringstream &scr_stream)
Print header to screen stream, helper method called from print_to_screen.
StreamMask operator&(const StreamMask &other)
Logger & every_proc()
Set flag every_process_ to true.
StreamMask full_streams_mask_
Mask of logger, specifies all streams into which to be written in logger message.
Logger(MsgType type)
Constructor.
std::string compact_file_name(std::string file_name)
Return compact (relative) path to the given source file.
static LoggerOptions & get_instance()
Getter of singleton instance object.
int get_mpi_rank()
Returns number of actual process, if MPI is not supported returns -1.
std::string date_time_
Actual date and time.
void set_mask()
Set streams_mask_ according to the type of message.
std::string cmn_prefix(std::string a, std::string b)
Helper function, use for shorten the code point path.
MsgType type_
Type of message.
void print_to_file(std::ofstream &stream, std::stringstream &file_stream, StreamMask mask)
Print formated message to given file stream if mask corresponds with streams_mask_.
Logger & set_context(const char *file_name, const char *function, const int line)
Stores values for printing out line number, function, etc.
bool is_init()
Check if singleton instance object is initialize.
MsgType
Enum of types of Logger messages.
static StreamMask cout
Predefined mask of std::cout output.
std::stringstream cout_stream_
Store messages printed to cout output stream.
Logger & operator<<(Logger &log, StreamMask mask)
StreamMask operator|(const StreamMask &other)
Global macros to enhance readability and debugging, general constants.
StreamMask()
Empty constructor.
std::string function_
Actual function.
int mpi_rank_
Actual process (if MPI is supported)
Class for storing logger messages.
void print_file_header(std::stringstream &file_stream)
Print header to file stream, helper method called from print_to_file.
static std::string format_hh_mm_ss()