You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.8 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/scratch/test.scratch.be.syslog/test.scratch.be.syslog.cpp
  3. *
  4. * Purpose: C++ example program for Pantheios. Demonstrates:
  5. *
  6. * - use of custom severity level information for tabbing output
  7. * - definition of a custom back-end that supports tabbed output
  8. * - use of pantheios::logputs() in bail-out conditions
  9. *
  10. * Created: 10th November 2010
  11. * Updated: 6th August 2012
  12. *
  13. * www: http://www.pantheios.org/
  14. *
  15. * License: This source code is placed into the public domain 2010
  16. * by Synesis Software Pty Ltd. There are no restrictions
  17. * whatsoever to your use of the software.
  18. *
  19. * This software is provided "as is", and any warranties,
  20. * express or implied, of any kind and for any purpose, are
  21. * disclaimed.
  22. *
  23. * ////////////////////////////////////////////////////////////////////// */
  24. /* This inclusion required for suppressing warnings during NoX (No eXception-support) configurations. */
  25. #include <pantheios/util/test/compiler_warnings_suppression.first_include.h>
  26. /* Pantheios Header Files */
  27. #include <pantheios/pantheios.hpp>
  28. #include <pantheios/backend.h>
  29. #include <pantheios/backends/bec.syslog.h>
  30. /* STLSoft Header Files */
  31. #include <platformstl/synch/sleep_functions.h>
  32. /* Standard C/C++ Header Files */
  33. #include <exception> // for std::exception
  34. #include <string> // for std::string
  35. #include <stdio.h> // for fprintf()
  36. #include <stdlib.h> // for exit codes
  37. #include <string.h> // for memset()
  38. #include <pantheios/util/test/compiler_warnings_suppression.last_include.h>
  39. /* ////////////////////////////////////////////////////////////////////// */
  40. // Define the fe.simple process identity, so that it links when using fe.simple
  41. PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.scratch.be.syslog");
  42. /* ////////////////////////////////////////////////////////////////////// */
  43. int main()
  44. {
  45. unsigned shortPause = 1250;
  46. try
  47. {
  48. pantheios::log_NOTICE("Hi!");
  49. platformstl::micro_sleep(shortPause);
  50. pantheios::log_NOTICE("This is your logger, calling.");
  51. platformstl::micro_sleep(shortPause);
  52. pantheios::log_NOTICE("Here come some diagnostic logging statements ...");
  53. platformstl::micro_sleep(shortPause);
  54. pantheios::log_DEBUG("just being pedantic");
  55. platformstl::micro_sleep(shortPause);
  56. pantheios::log_INFORMATIONAL("you can ignore this");
  57. platformstl::micro_sleep(shortPause);
  58. pantheios::log_NOTICE("this is noteworthy");
  59. platformstl::micro_sleep(shortPause);
  60. pantheios::log_WARNING("there may be a problem");
  61. platformstl::micro_sleep(shortPause);
  62. pantheios::log_ERROR("there is a problem");
  63. platformstl::micro_sleep(shortPause);
  64. pantheios::log_CRITICAL("there is a serious problem");
  65. platformstl::micro_sleep(shortPause);
  66. pantheios::log_ALERT("there is a very serious problem");
  67. platformstl::micro_sleep(shortPause);
  68. pantheios::log_EMERGENCY("aargh! I'm operating in contradiction to my design!");
  69. platformstl::micro_sleep(90000);
  70. return EXIT_SUCCESS;
  71. }
  72. catch(std::bad_alloc &)
  73. {
  74. pantheios::log_CRITICAL("out of memory");
  75. }
  76. catch(std::exception &x)
  77. {
  78. pantheios::log_ALERT("Exception: ", x);
  79. }
  80. catch(...)
  81. {
  82. pantheios::logputs(pantheios::emergency, "Unexpected unknown error");
  83. }
  84. return EXIT_FAILURE;
  85. }
  86. /* ///////////////////////////// end of file //////////////////////////// */