Blue Brain BioExplorer
Logs.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  * All rights reserved. Do not distribute without permission.
4  *
5  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
6  *
7  * This library is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Lesser General Public License version 3.0 as published
9  * by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #pragma once
22 
23 #include <iostream>
24 
25 namespace core
26 {
27 #define CORE_PREFIX "CORE " // 16 characters
28 
29 #define PROGRESS_BAR_SIZE 50
30 
31 #define CORE_ERROR(__msg) std::cerr << "E [" << CORE_PREFIX << "] " << __msg << std::endl;
32 #define CORE_WARN(__msg) std::cerr << "W [" << CORE_PREFIX << "] " << __msg << std::endl;
33 #define CORE_INFO(__msg) std::cout << "I [" << CORE_PREFIX << "] " << __msg << std::endl;
34 
35 #ifdef NDEBUG
36 #define CORE_DEBUG(__msg)
37 #else
38 #define CORE_DEBUG(__msg) std::cout << "D [" << CORE_PREFIX << "] " << __msg << std::endl;
39 #endif
40 #define CORE_TIMER(__time, __msg) std::cout << "T [" << CORE_PREFIX << "] [" << __time << "] " << __msg << std::endl;
41 
42 #define CORE_THROW(__msg) \
43  { \
44  throw std::runtime_error(__msg); \
45  }
46 
47 #define CORE_PROGRESS(__msg, __progress, __maxValue) \
48  { \
49  std::cout << "I [" << CORE_PREFIX << "] ["; \
50  const float __mv = float(__maxValue); \
51  const float __p = float(__progress + 1); \
52  const uint32_t __pos = std::min(PROGRESS_BAR_SIZE, int(__p / __mv * PROGRESS_BAR_SIZE)); \
53  for (uint32_t __i = 0; __i < PROGRESS_BAR_SIZE; ++__i) \
54  { \
55  if (__i < __pos) \
56  std::cout << "="; \
57  else if (__i == __pos) \
58  std::cout << ">"; \
59  else \
60  std::cout << " "; \
61  } \
62  std::cout << "] " << std::min(__pos * 2, uint32_t(PROGRESS_BAR_SIZE * 2)) << "% " << __msg << "\r"; \
63  std::cout.flush(); \
64  }
65 
66 #define PLUGIN_REGISTER_ENDPOINT(__msg) CORE_INFO("Registering end-point '" << __msg << "'");
67 #define PLUGIN_REGISTER_RENDERER(__msg) CORE_INFO("Registering renderer '" << __msg << "'");
68 #define PLUGIN_REGISTER_LOADER(__msg) CORE_INFO("Registering loader '" << __msg << "'");
69 #define PLUGIN_REGISTER_CAMERA(__msg) CORE_INFO("Registering camera '" << __msg << "'");
70 } // namespace core