Loading...
Searching...
No Matches
logger.cpp
1/*---------------------------------------------------------------------------*\
2*
3* bitpit
4*
5* Copyright (C) 2015-2021 OPTIMAD engineering Srl
6*
7* -------------------------------------------------------------------------
8* License
9* This file is part of bitpit.
10*
11* bitpit is free software: you can redistribute it and/or modify it
12* under the terms of the GNU Lesser General Public License v3 (LGPL)
13* as published by the Free Software Foundation.
14*
15* bitpit is distributed in the hope that it will be useful, but WITHOUT
16* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18* License for more details.
19*
20* You should have received a copy of the GNU Lesser General Public License
21* along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22*
23\*---------------------------------------------------------------------------*/
24
25#include <array>
26#include <cassert>
27#include <cctype>
28#include <cmath>
29#include <chrono>
30#include <cstdio>
31#include <ctime>
32#include <fstream>
33#include <iomanip>
34#include <iostream>
35#include <memory>
36#include <sstream>
37#include <functional>
38#include <sys/types.h>
39#include <sys/stat.h>
40#include <type_traits>
41
42#include "compiler.hpp"
43#include "fileHandler.hpp"
44#include "logger.hpp"
45
46namespace bitpit{
47
63LoggerBuffer::LoggerBuffer(int nProcesses, int rank, std::size_t bufferSize)
64 : m_buffer(bufferSize + 1),
65 m_nProcesses(nProcesses), m_rank(rank),
66 m_consoleEnabled(false), m_console(&std::cout),
67 m_fileEnabled(false), m_file(nullptr),
68 m_settings(std::make_shared<Settings>())
69{
70 // Set the buffer
71 char *bufferBegin = &m_buffer.front();
72 setp(bufferBegin, bufferBegin + m_buffer.size() - 1);
73
74 // Initialize console stream
76
77 // Initialize file stream
78 setFileEnabled(false);
79
80 // Set parallel data
81 if (m_nProcesses > 1) {
82 int nDigits = static_cast<int>(std::ceil(log10(m_nProcesses)));
83 std::ostringstream convert;
84 convert << std::setw(nDigits) << m_rank;
85 m_rankPrefix = "#" + convert.str();
86 } else {
87 m_rankPrefix = "";
88 }
89
90 // Default settings
91 m_settings->context = "";
92 m_settings->indentation = 0;
93 m_settings->consoleTimestampEnabled = false;
94 m_settings->fileTimestampEnabled = false;
95}
96
101{
102 sync();
103}
104
111{
112 return m_nProcesses;
113}
114
121{
122 return m_rank;
123}
124
136LoggerBuffer::int_type LoggerBuffer::overflow(int_type character)
137{
138 if (character != traits_type::eof()) {
139 // Write the character to the buffer and then increment pptr() by
140 // calling pbump(1). It's always safe to write the charater to the
141 // buffer because we reserved an extra char at the end of our buffer
142 // in the constructor.
143 assert(std::less_equal<char *>()(pptr(), epptr()));
144 *pptr() = character;
145 pbump(1);
146
147 // Flush the stream
148 if (sync() == 0) {
149 return character;
150 }
151 }
152
153 return traits_type::eof();
154}
155
161int LoggerBuffer::sync()
162{
163 return flush(false);
164}
165
173int LoggerBuffer::flush(bool terminate)
174{
175 // Get buffer information
176 const char *bufferBegin = pbase();
177 const char *bufferEnd = pptr();
178 if (bufferBegin == bufferEnd) {
179 return 0;
180 }
181
182 // Flush buffer a line at the time
183 const char *lineBegin = nullptr;
184 const char *lineEnd = bufferBegin;
185 while (lineEnd != bufferEnd) {
186 // Update line information
187 lineBegin = lineEnd;
188 for (lineEnd = lineBegin; lineEnd != bufferEnd; ++lineEnd) {
189 if (*lineEnd == '\n') {
190 lineEnd += 1;
191 break;
192 }
193 }
194
195 // Detect if a new line must be added at the end of the line
196 bool terminateLine = false;
197 if (terminate && (lineEnd == bufferEnd)) {
198 if (bufferBegin == bufferEnd) {
199 terminateLine = true;
200 } else if (*(bufferEnd - 1) != '\n') {
201 terminateLine = true;
202 }
203 }
204
205 // Get timestamp
206 std::string consoleTimestamp;
207 std::string fileTimestamp;
208 if (m_settings->consoleTimestampEnabled || m_settings->fileTimestampEnabled) {
209 std::string timestamp = getTimestamp();
210 if (m_settings->consoleTimestampEnabled) {
211 consoleTimestamp = timestamp;
212 }
213 if (m_settings->fileTimestampEnabled) {
214 fileTimestamp = timestamp;
215 }
216 }
217
218 // Flush line to console
219 if (m_console && m_consoleEnabled) {
220 int status = flushLine(*m_console, lineBegin, lineEnd, consoleTimestamp, terminateLine);
221 if (status != 0) {
222 return status;
223 }
224 }
225
226 // Flush line to file
227 if (m_file && m_fileEnabled && m_file->is_open()) {
228 int status = flushLine(*m_file, lineBegin, lineEnd, fileTimestamp, terminateLine);
229 if (status != 0) {
230 return status;
231 }
232 }
233 }
234
235 // Reset the internal pointer
236 pbump(static_cast<int>(bufferBegin - bufferEnd));
237
238 return 0;
239}
240
254int LoggerBuffer::flushLine(std::ostream &stream, const char *begin, const char *end,
255 const std::string &timestamp, bool terminate)
256{
257 if (!timestamp.empty()) {
258 stream << "[" + timestamp + "] ";
259 if ((stream.rdstate() & std::ifstream::failbit) != 0) {
260 return -1;
261 }
262 }
263
264 if (!m_rankPrefix.empty()) {
265 stream << m_rankPrefix << " :: ";
266 if ((stream.rdstate() & std::ifstream::failbit) != 0) {
267 return -1;
268 }
269 }
270
271 if (!m_settings->context.empty()) {
272 stream << m_settings->context + " :: ";
273 if ((stream.rdstate() & std::ifstream::failbit) != 0) {
274 return -1;
275 }
276 }
277
278 for (int i = 0; i < m_settings->indentation; ++i) {
279 stream << " ";
280 if ((stream.rdstate() & std::ifstream::failbit) != 0) {
281 return -1;
282 }
283 }
284
285 stream.write(begin, end - begin);
286 if ((stream.rdstate() & std::ifstream::failbit) != 0) {
287 return -1;
288 }
289
290 if (terminate) {
291 stream << "\n";
292 if ((stream.rdstate() & std::ifstream::failbit) != 0) {
293 return -1;
294 }
295 }
296
297 return 0;
298}
299
306{
307 if (m_consoleEnabled == enabled) {
308 return;
309 }
310
311 flush(true);
312
313 m_consoleEnabled = enabled;
314}
315
321void LoggerBuffer::setConsoleStream(std::ostream *console)
322{
323 flush(true);
324
325 m_console = console;
326}
327
334{
335 return *m_console;
336}
337
348{
349 if (m_fileEnabled == enabled) {
350 return;
351 }
352
353 flush(true);
354
355 m_fileEnabled = enabled;
356}
357
363void LoggerBuffer::setFileStream(std::ofstream *file)
364{
365 flush(true);
366
367 m_file = file;
368}
369
376{
377 return *m_file;
378}
379
386{
387 return m_settings.get();
388}
389
395void LoggerBuffer::setSettings(const std::shared_ptr<Settings> &settings)
396{
397 if (settings.get() == m_settings.get()) {
398 return;
399 }
400
401 flush(true);
402
403 m_settings = settings;
404}
405
409std::string LoggerBuffer::getTimestamp() const
410{
411 static const std::string TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S";
412
413 auto currentClock = std::chrono::system_clock::now();
414 std::time_t currentTime = std::chrono::system_clock::to_time_t(currentClock);
415
416 auto seconds = std::chrono::duration_cast<std::chrono::seconds>(currentClock.time_since_epoch());
417 auto millisecs = std::chrono::duration_cast<std::chrono::milliseconds>(currentClock.time_since_epoch() - seconds);
418 std::array<char, 11> millisecsBuffer;
419 std::snprintf(millisecsBuffer.data(), millisecsBuffer.size(), "%03u", static_cast<unsigned int>(millisecs.count()));
420
421 std::string timestamp;
422 timestamp.resize(23);
423 std::strftime(&timestamp[0], timestamp.size(), TIMESTAMP_FORMAT.c_str(), localtime(&currentTime));
424 timestamp[19] = '.';
425 timestamp[20] = millisecsBuffer[0];
426 timestamp[21] = millisecsBuffer[1];
427 timestamp[22] = millisecsBuffer[2];
428
429 return timestamp;
430}
431
447Logger::Logger(const std::string &name, const std::shared_ptr<LoggerBuffer> &buffer)
448 : std::ios(nullptr), std::ostream(nullptr),
449 m_name(name),
450 m_buffer(buffer), m_bufferSettings(std::make_shared<LoggerBuffer::Settings>()),
451 m_defaultSeverity(log::LEVEL_INFO), m_defaultVisibility(log::VISIBILITY_MASTER),
452 m_consoleDisabledThreshold(log::LEVEL_NOTSET), m_consoleVerbosityThreshold(log::LEVEL_INFO),
453 m_fileDisabledThreshold(log::LEVEL_NOTSET), m_fileVerbosityThreshold(log::LEVEL_INFO)
454{
455 // St stream buffer
456 basic_ios<char>::rdbuf(m_buffer.get());
457
458 // Default settings
459 m_bufferSettings->context = "";
460 m_bufferSettings->indentation = 0;
461 m_bufferSettings->consoleTimestampEnabled = false;
462 m_bufferSettings->fileTimestampEnabled = true;
463}
464
483{
484 disableConsole(level);
485 disableFile(level);
486}
487
506{
507 m_consoleDisabledThreshold = level;
508}
509
528{
529 m_fileDisabledThreshold = level;
530}
531
538{
539 // Set default severity
540 assert(severity != log::Level::LEVEL_NOTSET);
541 m_defaultSeverity = severity;
542}
543
550{
551 return m_defaultSeverity;
552}
553
560{
561 setDefaultSeverity(priority);
562}
563
573
579void Logger::setDefaultVisibility(log::Visibility visibility)
580{
581 // Set default visibility
582 assert(visibility != log::VISIBILITY_NOTSET);
583 m_defaultVisibility = visibility;
584}
585
592{
593 return m_defaultVisibility;
594}
595
601void Logger::setVisibility(log::Visibility visibility)
602{
603 setDefaultVisibility(visibility);
604}
605
611log::Visibility Logger::getVisibility()
612{
613 return getDefaultVisibility();
614}
615
627{
628 setConsoleVerbosity(threshold);
629 setFileVerbosity(threshold);
630}
631
639{
642}
643
651{
652 return m_bufferSettings->consoleTimestampEnabled;
653}
654
661{
662 if (m_bufferSettings->consoleTimestampEnabled == enabled) {
663 return;
664 }
665
666 m_buffer->flush(true);
667
668 m_bufferSettings->consoleTimestampEnabled = enabled;
669}
670
681{
682 // Set verbosity threshold
683 m_consoleVerbosityThreshold = threshold;
684}
685
692void Logger::enableBufferStreams(log::Level severity, log::Visibility visibility)
693{
694 // Enable console stream
695 bool isConsoleEnabled = true;
696 if (severity <= m_consoleDisabledThreshold) {
697 isConsoleEnabled = false;
698 } else if (visibility == log::VISIBILITY_MASTER && (m_buffer->getRank() != 0)) {
699 isConsoleEnabled = false;
700 } else {
701 isConsoleEnabled = (severity >= m_consoleVerbosityThreshold);
702 }
703 m_buffer->setConsoleEnabled(isConsoleEnabled);
704
705 // Enable file stream
706 bool isFileEnabled = true;
707 if (severity <= m_fileDisabledThreshold) {
708 isFileEnabled = false;
709 } else if (visibility == log::VISIBILITY_MASTER && (m_buffer->getRank() != 0)) {
710 isFileEnabled = false;
711 } else {
712 isFileEnabled = (severity >= m_fileVerbosityThreshold);
713 }
714 m_buffer->setFileEnabled(isFileEnabled);
715}
716
727{
728 return m_consoleVerbosityThreshold;
729}
730
738{
739 return m_bufferSettings->fileTimestampEnabled;
740}
741
748{
749 if (m_bufferSettings->fileTimestampEnabled == enabled) {
750 return;
751 }
752
753 m_buffer->flush(true);
754
755 m_bufferSettings->fileTimestampEnabled = enabled;
756}
757
768{
769 // Set verbosity threshold
770 m_fileVerbosityThreshold = threshold;
771}
772
781{
782 return m_fileVerbosityThreshold;
783}
784
790void Logger::setContext(const std::string &context)
791{
792 if (m_bufferSettings->context == context) {
793 return;
794 }
795
796 m_buffer->flush(true);
797
798 m_bufferSettings->context = context;
799}
800
807{
808 return m_bufferSettings->context;
809}
810
817{
818 if (delta == 0) {
819 return;
820 }
821
822 m_buffer->flush(true);
823
824 m_bufferSettings->indentation += delta;
825}
826
833{
834 return m_bufferSettings->indentation;
835}
836
842std::string Logger::getName() const
843{
844 return m_name;
845}
846
852void Logger::println(const std::string &line)
853{
854 print(line + '\n');
855}
856
863void Logger::println(const std::string &line, log::Level severity)
864{
865 print(line + '\n', severity);
866}
867
874void Logger::println(const std::string &line, log::Visibility visibility)
875{
876 print(line + '\n', visibility);
877}
878
886void Logger::println(const std::string &line, log::Level severity, log::Visibility visibility)
887{
888 print(line + '\n', severity, visibility);
889}
890
896void Logger::print(const std::string &message)
897{
899}
900
907void Logger::print(const std::string &message, log::Level severity)
908{
909 print(message, severity, getDefaultVisibility());
910}
911
918void Logger::print(const std::string &message, log::Visibility visibility)
919{
920 print(message, getDefaultSeverity(), visibility);
921}
922
930void Logger::print(const std::string &message, log::Level severity, log::Visibility visibility)
931{
932 print<const std::string &>(message, severity, visibility);
933}
934
944/*
945 Initialize logger manager instance.
946*/
947std::unique_ptr<LoggerManager> LoggerManager::m_manager = nullptr;
948
949/*
950 Default name for the logger.
951*/
952std::string LoggerManager::BITPIT_LOG_NAME = "bitpit";
953
954/*
955 Default directory for the logger.
956*/
957std::string LoggerManager::BITPIT_LOG_DIRECTORY = ".";
958
962LoggerManager::LoggerManager()
963 : m_defaultName(BITPIT_LOG_NAME), m_defaultDirectory(BITPIT_LOG_DIRECTORY),
964 m_mode(log::MODE_SEPARATE)
965{
966
967}
968
973{
974 // Get a list of the loggers
975 std::vector<std::string> loggerNames;
976 loggerNames.reserve(m_loggers.size());
977 for (const auto &entry : m_loggers) {
978 loggerNames.push_back(entry.first);
979 }
980
981 // Destroy all the loggers
982 for (const std::string &name : loggerNames) {
983 destroy(name, true);
984 }
985}
986
993{
994 if (!m_manager) {
995 m_manager = std::unique_ptr<LoggerManager>(new LoggerManager());
996 }
997
998 return *m_manager;
999}
1000
1016Logger & LoggerManager::cout(log::Level defaultSeverity, log::Visibility defaultVisibility)
1017{
1018 return cout(m_defaultName, defaultSeverity, defaultVisibility);
1019}
1020
1040Logger & LoggerManager::cout(const std::string &name, log::Level defaultSeverity, log::Visibility defaultVisibility)
1041{
1042 // Get the logger
1043 if (m_loggers.count(name) == 0) {
1044 if (!isInitialized()) {
1045 setMode(log::MODE_SEPARATE);
1046 }
1047
1048 if (name == m_defaultName) {
1049 _create(name, false, m_defaultDirectory, 1, 0);
1050 } else {
1051 create(name, false, m_defaultDirectory, 1, 0);
1052 }
1053 }
1054
1055 Logger &logger = *(m_loggers.at(name));
1056
1057 // Set default properties
1058 if (defaultSeverity != log::Level::LEVEL_NOTSET) {
1059 logger.setDefaultSeverity(defaultSeverity);
1060 }
1061
1062 if (defaultVisibility != log::VISIBILITY_NOTSET) {
1063 logger.setDefaultVisibility(defaultVisibility);
1064 }
1065
1066 // Return the logger
1067 return logger;
1068}
1069
1082Logger & LoggerManager::critical(log::Visibility defaultVisibility)
1083{
1084 return critical(m_defaultName, defaultVisibility);
1085}
1086
1103Logger & LoggerManager::critical(const std::string &name, log::Visibility defaultVisibility)
1104{
1105 return cout(name, log::Level::LEVEL_CRITICAL, defaultVisibility);
1106}
1107
1120Logger & LoggerManager::error(log::Visibility defaultVisibility)
1121{
1122 return error(m_defaultName, defaultVisibility);
1123}
1124
1141Logger & LoggerManager::error(const std::string &name, log::Visibility defaultVisibility)
1142{
1143 return cout(name, log::Level::LEVEL_ERROR, defaultVisibility);
1144}
1145
1158Logger & LoggerManager::warning(log::Visibility defaultVisibility)
1159{
1160 return warning(m_defaultName, defaultVisibility);
1161}
1162
1179Logger & LoggerManager::warning(const std::string &name, log::Visibility defaultVisibility)
1180{
1181 return cout(name, log::Level::LEVEL_WARNING, defaultVisibility);
1182}
1183
1196Logger & LoggerManager::info(log::Visibility defaultVisibility)
1197{
1198 return info(m_defaultName, defaultVisibility);
1199}
1200
1217Logger & LoggerManager::info(const std::string &name, log::Visibility defaultVisibility)
1218{
1219 return cout(name, log::Level::LEVEL_INFO, defaultVisibility);
1220}
1221
1234Logger & LoggerManager::debug(log::Visibility defaultVisibility)
1235{
1236 return debug(m_defaultName, defaultVisibility);
1237}
1238
1255Logger & LoggerManager::debug(const std::string &name, log::Visibility defaultVisibility)
1256{
1257 return cout(name, log::Level::LEVEL_DEBUG, defaultVisibility);
1258}
1259
1269 int nProcesses, int rank)
1270{
1271 initialize(mode, m_defaultName, reset, m_defaultDirectory, nProcesses, rank);
1272}
1273
1283void LoggerManager::initialize(log::Mode mode, bool reset, const std::string &directory,
1284 int nProcesses, int rank)
1285{
1286 initialize(mode, m_defaultName, reset, directory, nProcesses, rank);
1287}
1288
1299void LoggerManager::initialize(log::Mode mode, const std::string &name, bool reset,
1300 const std::string &directory,
1301 int nProcesses, int rank)
1302{
1303 if (isInitialized()) {
1304 log::cout().println("Logger initialization has to be called before creating the loggers.");
1305 return;
1306 }
1307
1308 // Set mode
1309 setMode(mode);
1310
1311 // Set the dafault data
1312 m_defaultName = name;
1313 m_defaultDirectory = directory;
1314
1315 // Create the logger
1316 _create(m_defaultName, reset, directory, nProcesses, rank);
1317}
1318
1327void LoggerManager::create(const std::string &name, bool reset,
1328 int nProcesses, int rank)
1329{
1330 create(name, reset, m_defaultDirectory, nProcesses, rank);
1331}
1332
1342void LoggerManager::create(const std::string &name, bool reset,
1343 const std::string &directory,
1344 int nProcesses, int rank)
1345{
1346 // Its not possible to create a log with the default name nor a log
1347 // with the same name of an existent logger nor a log with an empty
1348 // name
1349 if (exists(name)) {
1350 m_loggerUsers[name]++;
1351
1352 cout(name) << "Detected an attemp to create the logger \"" << name << "\" twice" << std::endl;
1353 cout(name) << "The previously created logger will be used." << std::endl;
1354 return;
1355 } else if (name == m_defaultName) {
1356 cout(m_defaultName) << "Detected an attemp to overwrite the default logger" << std::endl;
1357 cout(m_defaultName) << "The name of the default logger is \"" << name << "\"" << std::endl;
1358 return;
1359 } else if (name == "") {
1360 cout() << "Detected an attemp to create a logger with an empty name" << std::endl;
1361 return;
1362 }
1363
1364 // Create the logger
1365 if (m_mode == log::MODE_SEPARATE) {
1366 _create(name, reset, directory, nProcesses, rank);
1367 } else {
1368 Logger &defaultLogger = cout(m_defaultName);
1369 _create(name, defaultLogger.m_buffer);
1370 }
1371}
1372
1384bool LoggerManager::destroy(const std::string &name, bool force)
1385{
1386 if (!exists(name)) {
1387 return false;
1388 }
1389
1390 // Decrement the users
1391 int &nUsers = m_loggerUsers[name];
1392 nUsers--;
1393
1394 // If the logger has no users we can delete it
1395 if (nUsers == 0 || force) {
1396 // Remove the logger from the manager
1397 m_loggers.erase(name);
1398 m_loggerUsers.erase(name);
1399
1400 // If the logger has it own file stream, delete it
1401 if (m_fileStreams.count(name) > 0) {
1402 // Close the stream
1403 std::ofstream &fileStream = *(m_fileStreams.at(name));
1404 fileStream.close();
1405
1406 // Remove the stream
1407 m_fileStreams.erase(name);
1408 }
1409
1410 return true;
1411 } else {
1412 return false;
1413 }
1414}
1415
1422bool LoggerManager::exists(const std::string &name) const
1423{
1424 return (m_loggers.count(name) != 0);
1425}
1426
1438{
1439 return (m_loggers.size() > 0);
1440}
1441
1457{
1458 if (isInitialized()) {
1459 cout().println("The policy has to be set before creating the loggers.");
1460 return false;
1461 }
1462
1463 m_mode = mode;
1464 return true;
1465}
1466
1473{
1474 return m_mode;
1475}
1476
1486void LoggerManager::_create(const std::string &name, bool reset,
1487 const std::string &directory,
1488 int nProcesses, int rank)
1489{
1490 // Get the file path
1491 FileHandler fileHandler;
1492 fileHandler.setDirectory(directory);
1493 fileHandler.setName(name);
1494 fileHandler.setAppendix("log");
1495 fileHandler.setParallel(nProcesses > 1);
1496 if (nProcesses > 1) {
1497 fileHandler.setBlock(rank);
1498 }
1499
1500 std::string filePath = fileHandler.getPath();
1501
1502 // Create the file stream
1503 std::ios_base::openmode fileMode;
1504 if (reset) {
1505 fileMode = std::ofstream::out;
1506 } else {
1507 fileMode = std::ofstream::app;
1508 }
1509
1510 m_fileStreams[name] = std::unique_ptr<std::ofstream>(new std::ofstream());
1511 std::ofstream &fileStream = *(m_fileStreams.at(name));
1512 fileStream.rdbuf()->pubsetbuf(0, 0);
1513 fileStream.open(filePath, fileMode);
1514
1515 // Use cout as console stream
1516 std::ostream &consoleStream = std::cout;
1517
1518 // Create the buffer
1519 std::shared_ptr<LoggerBuffer> buffer = std::make_shared<LoggerBuffer>(nProcesses, rank, 256);
1520 buffer->setFileStream(&fileStream);
1521 buffer->setConsoleStream(&consoleStream);
1522
1523 // Create the logger
1524 _create(name, buffer);
1525}
1526
1533void LoggerManager::_create(const std::string &name, std::shared_ptr<LoggerBuffer> &buffer)
1534{
1535 m_loggers[name] = std::unique_ptr<Logger>(new Logger(name, buffer));
1536 m_loggerUsers[name] = 1;
1537}
1538
1550{
1551 for (auto &entry : m_loggers) {
1552 entry.second->setVerbosities(threshold);
1553 }
1554}
1555
1566{
1567 for (auto &entry : m_loggers) {
1568 entry.second->setConsoleVerbosity(threshold);
1569 }
1570}
1571
1582{
1583 for (auto &entry : m_loggers) {
1584 entry.second->setFileVerbosity(threshold);
1585 }
1586}
1587
1594{
1595 return m_defaultName;
1596}
1597
1604{
1605 return m_defaultDirectory;
1606}
1607
1608// Logger global functions
1609namespace log {
1678 // Generic global functions
1679
1686 {
1687 return LoggerManager::manager();
1688 }
1689
1709
1726 Logger & cout(const std::string &name, log::Level defaultSeverity, log::Visibility defaultVisibility)
1727 {
1729 }
1730
1743 {
1745 }
1746
1760 Logger & critical(const std::string &name, log::Visibility defaultVisibility)
1761 {
1762 return manager().critical(name, defaultVisibility);
1763 }
1764
1777 Logger & error(log::Visibility defaultVisibility)
1778 {
1780 }
1781
1795 Logger & error(const std::string &name, log::Visibility defaultVisibility)
1796 {
1797 return manager().error(name, defaultVisibility);
1798 }
1799
1813 {
1815 }
1816
1830 Logger & warning(const std::string &name, log::Visibility defaultVisibility)
1831 {
1832 return manager().warning(name, defaultVisibility);
1833 }
1834
1847 Logger & info(log::Visibility defaultVisibility)
1848 {
1849 return manager().info(defaultVisibility);
1850 }
1851
1865 Logger & info(const std::string &name, log::Visibility defaultVisibility)
1866 {
1867 return manager().info(name, defaultVisibility);
1868 }
1869
1882 Logger & debug(log::Visibility defaultVisibility)
1883 {
1885 }
1886
1900 Logger & debug(const std::string &name, log::Visibility defaultVisibility)
1901 {
1902 return manager().debug(name, defaultVisibility);
1903 }
1904
1905 // Manipulators global functions
1906
1914 Logger & setContext(Logger &logger, const std::string &context)
1915 {
1916 logger.setContext(context);
1917
1918 return logger;
1919 }
1920
1933
1941 Logger & setDefaultSeverity(Logger &logger, const log::Level &severity)
1942 {
1943 logger.setDefaultSeverity(severity);
1944
1945 return logger;
1946 }
1947
1960
1969 {
1971
1972 return logger;
1973 }
1974
1987
1995 Logger & setDefaultVisibility(Logger &logger, const log::Visibility &visibility)
1996 {
1998
1999 return logger;
2000 }
2001
2014
2022 Logger & setVisibility(Logger &logger, const log::Visibility &visibility)
2023 {
2025
2026 return logger;
2027 }
2028
2041
2050 Logger & setVerbosities(Logger &logger, const log::Level &threshold)
2051 {
2052 logger.setVerbosities(threshold);
2053
2054 return logger;
2055 }
2056
2070
2078 Logger & setConsoleVerbosity(Logger &logger, const log::Level &threshold)
2079 {
2080 logger.setConsoleVerbosity(threshold);
2081
2082 return logger;
2083 }
2084
2097
2105 Logger & setFileVerbosity(Logger &logger, const log::Level &threshold)
2106 {
2107 logger.setFileVerbosity(threshold);
2108
2109 return logger;
2110 }
2111
2124
2134 Logger & disable(Logger &logger, const log::Level &level)
2135 {
2136 logger.disable(level);
2137
2138 return logger;
2139 }
2140
2155
2165 Logger & disableConsole(Logger &logger, const log::Level &level)
2166 {
2167 logger.disableConsole(level);
2168
2169 return logger;
2170 }
2171
2186
2196 Logger & disableFile(Logger &logger, const log::Level &level)
2197 {
2198 logger.disableFile(level);
2199
2200 return logger;
2201 }
2202
2217
2225 Logger & setIndentation(Logger &logger, const int &delta)
2226 {
2227 logger.setIndentation(delta);
2228
2229 return logger;
2230 }
2231
2241 {
2243 }
2244}
2245
2246}
Creates file names and checks status.
std::string getPath() const
void setParallel(bool p_)
void setDirectory(const std::string &d_)
void setName(const std::string &n_)
void setBlock(int b_)
void setAppendix(const std::string &a_)
std::ofstream & getFileStream()
Definition logger.cpp:375
LoggerBuffer(int nProcesses, int rank, std::size_t bufferSize=256)
Definition logger.cpp:63
void setFileEnabled(bool enabled)
Definition logger.cpp:347
void setSettings(const std::shared_ptr< Settings > &settings)
Definition logger.cpp:395
int getProcessCount() const
Definition logger.cpp:110
const Settings * getSettings() const
Definition logger.cpp:385
void setFileStream(std::ofstream *file)
Definition logger.cpp:363
void setConsoleEnabled(bool enabled)
Definition logger.cpp:305
std::ostream & getConsoleStream()
Definition logger.cpp:333
int flush(bool terminate)
Definition logger.cpp:173
int getRank() const
Definition logger.cpp:120
void setConsoleStream(std::ostream *console)
Definition logger.cpp:321
Manager for the loggers.
Definition logger.hpp:234
void create(const std::string &name, bool reset=false, int nProcesses=1, int rank=0)
Definition logger.cpp:1327
bool setMode(log::Mode mode)
Definition logger.cpp:1456
bool exists(const std::string &name) const
Definition logger.cpp:1422
Logger & debug(log::Visibility visibility=log::VISIBILITY_NOTSET)
Definition logger.cpp:1234
bool destroy(const std::string &name, bool force=false)
Definition logger.cpp:1384
void setVerbosities(log::Level threshold)
Definition logger.cpp:1549
Logger & critical(log::Visibility visibility=log::VISIBILITY_NOTSET)
Definition logger.cpp:1082
std::string getDefaultDirectory() const
Definition logger.cpp:1603
log::Mode getMode() const
Definition logger.cpp:1472
Logger & cout(log::Level defualtSeverity=log::Level::LEVEL_NOTSET, log::Visibility defualtVisibility=log::VISIBILITY_NOTSET)
Definition logger.cpp:1016
Logger & warning(log::Visibility visibility=log::VISIBILITY_NOTSET)
Definition logger.cpp:1158
static LoggerManager & manager()
Definition logger.cpp:992
Logger & error(log::Visibility visibility=log::VISIBILITY_NOTSET)
Definition logger.cpp:1120
void setFileVerbosity(log::Level threshold)
Definition logger.cpp:1581
std::string getDefaultName() const
Definition logger.cpp:1593
Logger & info(log::Visibility visibility=log::VISIBILITY_NOTSET)
Definition logger.cpp:1196
bool isInitialized() const
Definition logger.cpp:1437
void setConsoleVerbosity(log::Level threshold)
Definition logger.cpp:1565
void initialize(log::Mode mode, bool reset, int nProcesses, int rank)
Definition logger.cpp:1268
Message logger.
Definition logger.hpp:143
void setDefaultVisibility(log::Visibility visibility)
Definition logger.cpp:579
void setDefaultSeverity(log::Level severity)
Definition logger.cpp:537
void setVerbosities(log::Level threshold)
Definition logger.cpp:626
void setConsoleTimestampEnabled(bool enabled)
Definition logger.cpp:660
void setFileVerbosity(log::Level threshold)
Definition logger.cpp:767
log::Level getDefaultSeverity()
Definition logger.cpp:549
std::string getContext()
Definition logger.cpp:806
void setConsoleVerbosity(log::Level threshold)
Definition logger.cpp:680
void setPriority(log::Priority priority)
Definition logger.cpp:559
bool isConsoleTimestampEnabled() const
Definition logger.cpp:650
void disable(log::Level=log::Level::LEVEL_CRITICAL)
Definition logger.cpp:482
log::Visibility getDefaultVisibility()
Definition logger.cpp:591
log::Level getFileVerbosity()
Definition logger.cpp:780
void setIndentation(int delta)
Definition logger.cpp:816
void disableConsole(log::Level=log::Level::LEVEL_CRITICAL)
Definition logger.cpp:505
bool isFileTimestampEnabled() const
Definition logger.cpp:737
void setVisibility(log::Visibility visibility)
Definition logger.cpp:601
void setFileTimestampEnabled(bool enabled)
Definition logger.cpp:747
int getIndentation()
Definition logger.cpp:832
void println(const std::string &message)
Definition logger.cpp:852
void disableFile(log::Level=log::Level::LEVEL_CRITICAL)
Definition logger.cpp:527
std::string getName() const
Definition logger.cpp:842
void print(const std::string &message)
Definition logger.cpp:896
void setContext(const std::string &context)
Definition logger.cpp:790
void setTimestampEnabled(bool enabled)
Definition logger.cpp:638
log::Level getConsoleVerbosity()
Definition logger.cpp:726
log::Visibility getVisibility()
Definition logger.cpp:611
log::Priority getPriority()
Definition logger.cpp:569
LoggerManipulator< log::Level > defaultSeverity(const log::Level &severity)
Definition logger.cpp:1956
Logger & cout(log::Level defaultSeverity, log::Visibility defaultVisibility)
Definition logger.cpp:1705
LoggerManipulator< log::Visibility > defaultVisibility(const log::Visibility &visibility)
Definition logger.cpp:2010
LoggerManipulator< log::Level > verbosities(const log::Level &threshold)
Definition logger.cpp:2066
Logger & setPriority(Logger &logger, const log::Priority &priority)
Definition logger.cpp:1968
LoggerManipulator< log::Visibility > visibility(const log::Visibility &visibility)
Definition logger.cpp:2037
Logger & critical(log::Visibility defaultVisibility)
Definition logger.cpp:1742
Logger & disable(Logger &logger, const log::Level &level)
Definition logger.cpp:2134
LoggerManipulator< log::Level > consoleVerbosity(const log::Level &threshold)
Definition logger.cpp:2093
Logger & setDefaultSeverity(Logger &logger, const log::Level &severity)
Definition logger.cpp:1941
LoggerManipulator< log::Priority > priority(const log::Priority &priority)
Definition logger.cpp:1983
Logger & error(log::Visibility defaultVisibility)
Definition logger.cpp:1777
Logger & warning(log::Visibility defaultVisibility)
Definition logger.cpp:1812
LoggerManipulator< log::Level > fileVerbosity(const log::Level &threshold)
Definition logger.cpp:2120
Logger & debug(log::Visibility defaultVisibility)
Definition logger.cpp:1882
LoggerManipulator< int > indent(int delta)
Definition logger.cpp:2240
Logger & setFileVerbosity(Logger &logger, const log::Level &threshold)
Definition logger.cpp:2105
Logger & setVisibility(Logger &logger, const log::Visibility &visibility)
Definition logger.cpp:2022
Logger & info(log::Visibility defaultVisibility)
Definition logger.cpp:1847
Logger & disableConsole(Logger &logger, const log::Level &level)
Definition logger.cpp:2165
Logger & setDefaultVisibility(Logger &logger, const log::Visibility &visibility)
Definition logger.cpp:1995
LoggerManager & manager()
Definition logger.cpp:1685
Logger & setVerbosities(Logger &logger, const log::Level &threshold)
Definition logger.cpp:2050
Logger & setIndentation(Logger &logger, const int &delta)
Definition logger.cpp:2225
LoggerManipulator< std::string > context(const std::string &context)
Definition logger.cpp:1929
Logger & disableFile(Logger &logger, const log::Level &level)
Definition logger.cpp:2196
Logger & setConsoleVerbosity(Logger &logger, const log::Level &threshold)
Definition logger.cpp:2078
Logger & setContext(Logger &logger, const std::string &context)
Definition logger.cpp:1914
--- layout: doxygen_footer ---