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.

118 lines
4.4 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: examples/c/example.c.N/example.c.N.c
  3. *
  4. * Purpose: C example program for Pantheios. Demonstrates:
  5. *
  6. * - use of be.N back-end library that multiplexes output to
  7. * various concrete back-ends
  8. * - use of fe.N front-end library, that arbitrates output
  9. * for be.N
  10. *
  11. * Created: 5th December 2006
  12. * Updated: 22nd March 2010
  13. *
  14. * www: http://www.pantheios.org/
  15. *
  16. * License: This source code is placed into the public domain 2006
  17. * by Synesis Software Pty Ltd. There are no restrictions
  18. * whatsoever to your use of the software.
  19. *
  20. * This software is provided "as is", and any warranties,
  21. * express or implied, of any kind and for any purpose, are
  22. * disclaimed.
  23. *
  24. * ////////////////////////////////////////////////////////////////////// */
  25. /* PlatformSTL Header Files */
  26. #include <platformstl/platformstl.h> /* for platform discrimination */
  27. /* Pantheios Header Files */
  28. #include <pantheios/pantheios.h> /* main Pantheios C header file */
  29. #include <pantheios/frontends/fe.N.h>
  30. #include <pantheios/backends/be.N.h>
  31. #include <pantheios/backends/bec.file.h>
  32. #include <pantheios/backends/bec.fprintf.h>
  33. #include <pantheios/backends/bec.null.h>
  34. #if defined(PLATFORMSTL_OS_IS_UNIX)
  35. # include <pantheios/backends/bec.syslog.h>
  36. #elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  37. # include <pantheios/backends/bec.WindowsSyslog.h>
  38. #else /* ? OS */
  39. # error Operating system not discriminated
  40. #endif /* OS */
  41. /* Standard C Header Files */
  42. #include <stdlib.h> /* for exit codes */
  43. /* /////////////////////////////////////////////////////////////////////////
  44. * Globals
  45. */
  46. /* Define the stock front-end process identity, so that it links when using
  47. * fe.N, fe.simple, etc. */
  48. const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("example.c.N");
  49. pan_fe_N_t PAN_FE_N_SEVERITY_CEILINGS[] =
  50. {
  51. { 1, PANTHEIOS_SEV_NOTICE } /* Filters out everything below 'notice' */
  52. , { 2, PANTHEIOS_SEV_DEBUG } /* Allows all severities */
  53. , { 3, PANTHEIOS_SEV_ERROR } /* Allows only 'error', 'critical', 'alert', 'emergency' */
  54. , { 0, PANTHEIOS_SEV_NOTICE } /* Terminates the array; sets the default ceiling to 'notice' */
  55. };
  56. pan_be_N_t PAN_BE_N_BACKEND_LIST[] =
  57. {
  58. PANTHEIOS_BE_N_STDFORM_ENTRY(1, pantheios_be_file, 0)
  59. , PANTHEIOS_BE_N_STDFORM_ENTRY(2, pantheios_be_fprintf, 0)
  60. , PANTHEIOS_BE_N_STDFORM_ENTRY(3, pantheios_be_null, 0)
  61. #if defined(PLATFORMSTL_OS_IS_UNIX)
  62. , PANTHEIOS_BE_N_STDFORM_ENTRY(4, pantheios_be_syslog, 0)
  63. #elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  64. , PANTHEIOS_BE_N_STDFORM_ENTRY(4, pantheios_be_WindowsSyslog, 0)
  65. #endif /* OS */
  66. , PANTHEIOS_BE_N_STDFORM_ENTRY(5, pantheios_be_file, 0)
  67. , PANTHEIOS_BE_N_TERMINATOR_ENTRY
  68. };
  69. /* ////////////////////////////////////////////////////////////////////// */
  70. int main()
  71. {
  72. /* Must initialise Pantheios, when using from C (and there are no C++
  73. * compilation units in the link-unit).
  74. *
  75. * If this is not done, undefined behaviour will ensue ...
  76. */
  77. if(pantheios_init() < 0)
  78. {
  79. return EXIT_FAILURE;
  80. }
  81. else
  82. {
  83. pantheios_logputs(PANTHEIOS_SEV_DEBUG, PANTHEIOS_LITERAL_STRING("debug"));
  84. pantheios_logputs(PANTHEIOS_SEV_INFORMATIONAL, PANTHEIOS_LITERAL_STRING("info"));
  85. pantheios_logputs(PANTHEIOS_SEV_NOTICE, PANTHEIOS_LITERAL_STRING("notice"));
  86. pantheios_logputs(PANTHEIOS_SEV_WARNING, PANTHEIOS_LITERAL_STRING("warn"));
  87. pantheios_be_file_setFilePath(PANTHEIOS_LITERAL_STRING("file-1.log"), PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BE_FILE_F_TRUNCATE, 1);
  88. pantheios_logputs(PANTHEIOS_SEV_ERROR, PANTHEIOS_LITERAL_STRING("error"));
  89. pantheios_logputs(PANTHEIOS_SEV_CRITICAL, PANTHEIOS_LITERAL_STRING("critical"));
  90. pantheios_logputs(PANTHEIOS_SEV_ALERT, PANTHEIOS_LITERAL_STRING("alert"));
  91. pantheios_logputs(PANTHEIOS_SEV_EMERGENCY, PANTHEIOS_LITERAL_STRING("emergency"));
  92. pantheios_be_file_setFilePath(PANTHEIOS_LITERAL_STRING("file-5.log"), 0, 0, 5);
  93. /* Must uninitialise Pantheios.
  94. *
  95. * pantheios_uninit() must be called once for each successful (>=0)
  96. * invocation of pantheios_init().
  97. */
  98. pantheios_uninit();
  99. return EXIT_SUCCESS;
  100. }
  101. }
  102. /* ////////////////////////////////////////////////////////////////////// */