DebConfig.hh 1.91 KB
Newer Older
1
// (C) Copyright 2019 by Autodesk, Inc.
2
3
4
5
6

#ifndef BASE_DEBCONFIG_HH_INCLUDED
#define BASE_DEBCONFIG_HH_INCLUDED
#ifdef DEB_ON

Max Lyon's avatar
Max Lyon committed
7
#include <Base/Config/BaseDefines.hh>
8
9
10
11
#include <string>

namespace Debug {

12
13
 void print_char_to_cerr(const char _c); //!< print a char to cerr

14
15
/*! 
Access the global, per-process, configuration options of the Debug system.
16
\todo Make this a per-thread configuration.
17
*/
Max Lyon's avatar
Max Lyon committed
18
class BASEDLLEXPORT Config
19
20
{
public:
21
22
23
24
25
  //! Define the function type to print a character on the console
  typedef void (*print_function)(const char);

public:
  //! Modify the current configuration.
26
  static Config& modify();
27

28
29
30
31
32
33
  //! Query the current configuration.
  static const Config& query(); 

  //! Query the default configuration.
  static const Config& defaults(); 

34
public:
35
36
37
38
39
  //! The output level for all code in the absence of a config file.
  int output_level = 5;
  
  //! The deb out log filename, nullptr disables the debug output log file.
  const char* log_filename = nullptr;
40

41
42
  //! Function to deb out on the console, nullptr if output disabled.
  print_function console_print = print_char_to_cerr;
43

44
45
46
public:
  //! The output level for the given filename and function.
  int custom_level(const char* const _flnm, const char* const _fnct) const;
47

48
49
50
51
52
53
54
  /*! 
  Load the configuration file specified either by the environment variable
  or the filename if the the environment variable is not set. 
  \todo Document the config format.
  \return true if the configuration file was loaded properly, false otherwise.
  */ 
  bool load(const char* const _cnfg_envr, const char* const _cnfg_flnm);
55

56
57
private:
  class LevelFilterMap;
58
59

private:
60
  LevelFilterMap* lvl_fltrs_ = nullptr;
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

private:
  //! Private constructor
  Config();

  //! Private destructor
  ~Config();

  //! Disable copy
  Config(const Config&);

  //! Disable assignment
  Config& operator=(const Config&);
}; 

};//namespace Debug

#endif//DEB_ON
#endif//BASE_DEBCONFIG_HH_INCLUDED