print.cpp
Go to the documentation of this file.
1 /*
2  * OpenVINS: An Open Platform for Visual-Inertial Research
3  * Copyright (C) 2018-2023 Patrick Geneva
4  * Copyright (C) 2018-2023 Guoquan Huang
5  * Copyright (C) 2018-2023 OpenVINS Contributors
6  * Copyright (C) 2018-2019 Kevin Eckenhoff
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #include "print.h"
23 
24 using namespace ov_core;
25 
26 // Need to define the static variable for everything to work
28 
29 void Printer::setPrintLevel(const std::string &level) {
30  if (level == "ALL")
31  setPrintLevel(PrintLevel::ALL);
32  else if (level == "DEBUG")
33  setPrintLevel(PrintLevel::DEBUG);
34  else if (level == "INFO")
35  setPrintLevel(PrintLevel::INFO);
36  else if (level == "WARNING")
37  setPrintLevel(PrintLevel::WARNING);
38  else if (level == "ERROR")
39  setPrintLevel(PrintLevel::ERROR);
40  else if (level == "SILENT")
41  setPrintLevel(PrintLevel::SILENT);
42  else {
43  std::cout << "Invalid print level requested: " << level << std::endl;
44  std::cout << "Valid levels are: ALL, DEBUG, INFO, WARNING, ERROR, SILENT" << std::endl;
45  std::exit(EXIT_FAILURE);
46  }
47 }
48 
51  std::cout << "Setting printing level to: ";
52  switch (current_print_level) {
53  case PrintLevel::ALL:
54  std::cout << "ALL";
55  break;
56  case PrintLevel::DEBUG:
57  std::cout << "DEBUG";
58  break;
59  case PrintLevel::INFO:
60  std::cout << "INFO";
61  break;
62  case PrintLevel::WARNING:
63  std::cout << "WARNING";
64  break;
65  case PrintLevel::ERROR:
66  std::cout << "ERROR";
67  break;
68  case PrintLevel::SILENT:
69  std::cout << "SILENT";
70  break;
71  default:
72  std::cout << std::endl;
73  std::cout << "Invalid print level requested: " << level << std::endl;
74  std::cout << "Valid levels are: ALL, DEBUG, INFO, WARNING, ERROR, SILENT" << std::endl;
75  std::exit(EXIT_FAILURE);
76  }
77  std::cout << std::endl;
78 }
79 
80 void Printer::debugPrint(PrintLevel level, const char location[], const char line[], const char *format, ...) {
81  // Only print for the current debug level
82  if (static_cast<int>(level) < static_cast<int>(Printer::current_print_level)) {
83  return;
84  }
85 
86  // Print the location info first for our debug output
87  // Truncate the filename to the max size for the filepath
88  if (static_cast<int>(Printer::current_print_level) <= static_cast<int>(Printer::PrintLevel::DEBUG)) {
89  std::string path(location);
90  std::string base_filename = path.substr(path.find_last_of("/\\") + 1);
91  if (base_filename.size() > MAX_FILE_PATH_LEGTH) {
92  printf("%s", base_filename.substr(base_filename.size() - MAX_FILE_PATH_LEGTH, base_filename.size()).c_str());
93  } else {
94  printf("%s", base_filename.c_str());
95  }
96  printf(":%s ", line);
97  }
98 
99  // Print the rest of the args
100  va_list args;
101  va_start(args, format);
102  vprintf(format, args);
103  va_end(args);
104 }
ov_core::Printer::PrintLevel
PrintLevel
The different print levels possible.
Definition: print.h:54
ov_core::Printer::debugPrint
static void debugPrint(PrintLevel level, const char location[], const char line[], const char *format,...)
The print function that prints to stdout.
Definition: print.cpp:80
ov_core::Printer::current_print_level
static PrintLevel current_print_level
The current print level.
Definition: print.h:78
ov_core::Printer::setPrintLevel
static void setPrintLevel(const std::string &level)
Set the print level to use for all future printing to stdout.
Definition: print.cpp:29
print.h
ov_core::Printer::MAX_FILE_PATH_LEGTH
static constexpr uint32_t MAX_FILE_PATH_LEGTH
The max length for the file path. This is to avoid very long file paths from.
Definition: print.h:82
args
ov_core
Core algorithms for OpenVINS.
Definition: CamBase.h:30


ov_core
Author(s): Patrick Geneva , Kevin Eckenhoff , Guoquan Huang
autogenerated on Mon Jan 22 2024 03:08:17