00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #include <pantheios/pantheios.hpp>          
00028 #include <pantheios/backend.h>
00029 
00030 
00031 #include <stlsoft/memory/auto_buffer.hpp>   
00032 
00033 
00034 #include <exception>                        
00035 #include <string>                           
00036 #include <stdio.h>                          
00037 #include <stdlib.h>                         
00038 #include <string.h>                         
00039 
00040 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00041 # if defined(STLSOFT_COMPILER_IS_MSVC)
00042 #  pragma warning(disable : 4702)
00043 # endif 
00044 #endif 
00045 
00046 
00047 
00048 
00049 PANTHEIOS_EXTERN_C const char   FE_SIMPLE_PROCESS_IDENTITY[]    =   "example_cpp_custom_severity_levels";
00050 
00051 
00052 
00053 int main()
00054 {
00055   try
00056   {
00057     
00058 
00059     pantheios::log(pantheios::notice, "Hello");
00060 
00061     
00062     
00063 
00064     pantheios::log(pantheios::notice(2), "Hello");
00065 
00066 
00067     return EXIT_SUCCESS;
00068   }
00069   catch(std::bad_alloc &)
00070   {
00071     pantheios::log_CRITICAL("out of memory");
00072   }
00073   catch(std::exception &x)
00074   {
00075     pantheios::log_ALERT("Exception: ", x);
00076   }
00077   catch(...)
00078   {
00079     pantheios::puts(pantheios::emergency, "Unexpected unknown error");
00080   }
00081 
00082   return EXIT_FAILURE;
00083 }
00084 
00085 
00086 
00087 PANTHEIOS_CALL(int) pantheios_be_init(  char const  *processIdentity
00088                                     ,   void        * 
00089                                     ,   void        **ptoken)
00090 {
00091   *ptoken = ::strdup(processIdentity);
00092 
00093   return (NULL == *ptoken) ? -2 : 0;
00094 }
00095 
00096 PANTHEIOS_CALL(void) pantheios_be_uninit(void *token)
00097 {
00098   ::free(token);
00099 }
00100 
00101 PANTHEIOS_CALL(int) pantheios_be_logEntry(  void        * 
00102                                         ,   void        *beToken
00103                                         ,   int         severity
00104                                         ,   char const  *entry
00105                                         ,   size_t      cchEntry)
00106 {
00107   int     severityLevel   =   severity & 0x07;
00108   int     customInfo24    =   severity >> 8;
00109 
00110   try
00111   {
00112     stlsoft::auto_buffer<char, 256> prefixes(static_cast<size_t>(customInfo24));
00113     char const                      *severity   = pantheios::getSeverityString(severityLevel);
00114     FILE                            *stm        = (severityLevel < pantheios::notice) ? stderr : stdout;
00115     char const                      *processId  = static_cast<char const*>(beToken);
00116 
00117     memset(&prefixes[0], ' ', prefixes.size());
00118 
00119     return ::fprintf( stm
00120                     , "[%s; %s]:%.*s %.*s\n"
00121                     , processId, severity
00122                     , int(prefixes.size()), prefixes.data()
00123                     , int(cchEntry), entry);
00124   }
00125   catch(std::exception &)
00126   {
00127     return 0;
00128   }
00129 }
00130 
00131