#define PANTHEIOS_NO_INCLUDE_OS_AND_3PTYLIB_STRING_ACCESS // Faster compilation
#include <pantheios/pantheios.hpp>
#include <pantheios/backend.h>
#include <pantheios/util/string/strdup.h>
#include <pantheios/init_codes.h>
#include <pantheios/util/memory/auto_buffer_selector.hpp>
#include <platformstl/system/system_traits.hpp>
#include <exception>
#include <new>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
# if defined(STLSOFT_COMPILER_IS_MSVC)
# pragma warning(disable : 4702)
# endif
#endif
PANTHEIOS_EXTERN_C const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("example.cpp.misc.extended_severity_information");
#define PSTR(x) PANTHEIOS_LITERAL_STRING(x)
int main()
{
try
{
pantheios::log(pantheios::notice, PSTR("Hello"));
pantheios::log(pantheios::notice(2), PSTR("Hello"));
return EXIT_SUCCESS;
}
catch(std::bad_alloc&)
{
pantheios::log(pantheios::alert, PSTR("out of memory"));
}
catch(std::exception& x)
{
pantheios::log_CRITICAL(PSTR("Exception: "), x);
}
catch(...)
{
pantheios::logputs(pantheios::emergency, PSTR("Unexpected unknown error"));
}
return EXIT_FAILURE;
}
PANTHEIOS_CALL(int) pantheios_be_init(
PAN_CHAR_T const* processIdentity
, void*
, void** ptoken
)
{
*ptoken = pantheios::util::strdup_nothrow(processIdentity);
return (NULL == *ptoken) ? PANTHEIOS_INIT_RC_OUT_OF_MEMORY : PANTHEIOS_INIT_RC_SUCCESS;
}
PANTHEIOS_CALL(void) pantheios_be_uninit(void *token)
{
pantheios::util::strfree(static_cast<PAN_CHAR_T*>(token));
}
PANTHEIOS_CALL(int) pantheios_be_logEntry(
void*
, void* beToken
, int severity
, PAN_CHAR_T const* entry
, size_t cchEntry
)
{
int severityLevel = severity & 0x0f;
int customInfo28 = severity >> 4;
try
{
pantheios::util::auto_buffer_selector<char, 256>::type prefixes(static_cast<size_t>(customInfo28));
PAN_CHAR_T const* severity = pantheios::getStockSeverityString(severityLevel);
FILE* stm = (severityLevel < pantheios::notice) ? stderr : stdout;
PAN_CHAR_T const* processId = static_cast<PAN_CHAR_T const*>(beToken);
platformstl::system_traits<char>::str_set(&prefixes[0], prefixes.size(), ' ');
#ifdef PANTHEIOS_USE_WIDE_STRINGS
return ::fwprintf(stm
, L"[%s; %s]:%.*s %.*s\n"
, processId, severity
, int(prefixes.size()), prefixes.data()
, int(cchEntry), entry);
#else
return ::fprintf( stm
, "[%s; %s]:%.*s %.*s\n"
, processId, severity
, int(prefixes.size()), prefixes.data()
, int(cchEntry), entry);
#endif
}
catch(std::exception &)
{
return 0;
}
}