Logger.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ///
  2. /// \file System/Logger.hpp
  3. ///
  4. /// API calls for logger control.
  5. ///
  6. /// \copyright
  7. /// Copyright (c) 2014-2015 Josh Blum
  8. /// SPDX-License-Identifier: BSL-1.0
  9. ///
  10. #pragma once
  11. #include <Pothos/Config.hpp>
  12. #include <string>
  13. namespace Pothos {
  14. namespace System {
  15. /*!
  16. * Logger class contains static methods to deal with log configuration.
  17. */
  18. class POTHOS_API Logger
  19. {
  20. public:
  21. /*!
  22. * Start a listener for syslog messages from other processes.
  23. * The log messages will be forwarded to the default logger.
  24. * \return the port that this process is listening
  25. */
  26. static std::string startSyslogListener(void);
  27. /*!
  28. * Stop the syslog listener service.
  29. */
  30. static void stopSyslogListener(void);
  31. /*!
  32. * Start syslog forwarding to the given address.
  33. * \param addr the log destination in host:port format
  34. */
  35. static void startSyslogForwarding(const std::string &addr);
  36. /*!
  37. * Stop all syslog forwarding setup by startSyslogForwarding().
  38. */
  39. static void stopSyslogForwarding(void);
  40. /*!
  41. * Redirect standard IO to the logging facility.
  42. * This allows the user to capture standard IO debug messages
  43. * from subprocesses and servers that would otherwise be lost.
  44. * Because the default logging output directs to standard IO,
  45. * it is recommended to first change the default logging channel.
  46. * For example, startSyslogForwarding() will direct logs to UDP.
  47. * \param source the repoted source of the forwarded log messages
  48. */
  49. static void forwardStdIoToLogging(const std::string &source);
  50. /*!
  51. * Setup default logging for this process.
  52. * The default logger will log all non-informational logs to the console.
  53. * The logger can be configured with the following environment vars:
  54. * POTHOS_LOG_LEVEL - what level to display logs (default notice)
  55. * POTHOS_LOG_CHANNEL - how to display the logs (default color)
  56. * POTHOS_LOG_FILE - log file path if POTHOS_LOG_CHANNEL=file specified
  57. */
  58. static void setupDefaultLogging(void);
  59. private:
  60. //! private constructor: we don't make Logger instances
  61. Logger(void){}
  62. };
  63. } //namespace System
  64. } //namespace Pothos