Esempio n. 1
0
static int main_(int argc, char **argv)
{
#ifndef PANTHEIOS_USE_WIDE_STRINGS
    pantheios::log_DEBUG("main_(", pantheios::args(argc, argv), ")");
#endif

    {
        unsigned    flags = PANTHEIOS_BE_FILE_F_DISCARD_CACHED_CONTENTS | PANTHEIOS_BE_FILE_F_TRUNCATE;

        int res1 = pantheios_be_file_setFilePath(PSTR("test-%T-%D.log"), flags, flags, PANTHEIOS_BEID_LOCAL);

        pantheios_be_file_flush(PANTHEIOS_BEID_LOCAL);

        pantheios::log_NOTICE(PSTR("stmt 1"));
    }

#ifndef PANTHEIOS_USE_WIDE_STRINGS
    {
        pantheios::log_NOTICE("stmt 1");
        unsigned    flags = PANTHEIOS_BE_FILE_F_DISCARD_CACHED_CONTENTS | PANTHEIOS_BE_FILE_F_TRUNCATE;

        int res1 = pantheios_be_file_setFilePath(FILENAME_LOCAL, flags, flags, PANTHEIOS_BEID_LOCAL);

        pantheios::log_NOTICE("stmt 2");
        pantheios::log_NOTICE("stmt 3");

        int res2 = pantheios_be_file_setFilePath(FILENAME_REMOTE, flags, flags, PANTHEIOS_BEID_REMOTE);

        pantheios::log_NOTICE("stmt 4");
        pantheios::log_NOTICE("stmt 5");

        pantheios_be_file_setFilePath(NULL, PANTHEIOS_BEID_LOCAL);
        pantheios_be_file_setFilePath(NULL, PANTHEIOS_BEID_REMOTE);

        pantheios::log_NOTICE("stmt 6");
        pantheios::log_NOTICE("stmt 7");

        file_lines_t    local_lines(FILENAME_LOCAL);
        file_lines_t    remote_lines(FILENAME_REMOTE);

        const size_t    numLocal    =   local_lines.size();
        const size_t    numRemote   =   remote_lines.size();

        STLSOFT_ASSERT(4 == numLocal);
        STLSOFT_ASSERT(2 == numRemote);

        fs_traits_t::delete_file(FILENAME_LOCAL);
        fs_traits_t::get_last_error();
        fs_traits_t::delete_file(FILENAME_REMOTE);
        fs_traits_t::get_last_error();

        STLSOFT_SUPPRESS_UNUSED(res1);
        STLSOFT_SUPPRESS_UNUSED(res2);
    }
#endif

    pantheios::log_DEBUG(PSTR("exiting main_()"));

    return EXIT_SUCCESS;
}
static int main_(int /* argc */, char** /*argv*/)
{
    pantheios_be_file_setFilePath("normal.log", 0, 0, WG_LOG_FILE_ID);
    pantheios_be_file_setFilePath("error.log", 0, 0, WG_LOG_FILE_ERROR_ID);

    pantheios::log_WARNING("hello there all of you");
    pantheios::log_NOTICE("hello there console and main log");
    pantheios::log_DEBUG("hello there console");

    return EXIT_SUCCESS;
}
Esempio n. 3
0
int log_to_file() {
  pantheios::log_NOTICE("log-1"); 				// save until log file set
  pantheios_be_file_setFilePath(PSTR("mylogfile"), PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BEID_LOCAL); 		// sets log file; write "log-1" stmt
  pantheios::log_NOTICE("log-2"); 				// write "log-2" stmt
  pantheios_be_file_setFilePath(NULL); 				// close "mylogfile"

  pantheios::log_NOTICE("log-3"); 				// save until log file set
  pantheios_be_file_setFilePath(PSTR("mylogfile2"), PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BEID_LOCAL); 		// sets log file; write "log-3" stmt
  pantheios::log_NOTICE("log-4"); 				// write "log-4" stmt
  
  return 2;
} 								// closes "mylogfile2" during program closedown
Esempio n. 4
0
int main(int argc, char **argv)
{
  try
  {
#ifndef PANTHEIOS_USE_WIDE_STRINGS
    pantheios::log_DEBUG("main(", pantheios::args(argc, argv), ")");
#else /* ? !PANTHEIOS_USE_WIDE_STRINGS */
    STLSOFT_SUPPRESS_UNUSED(argc); STLSOFT_SUPPRESS_UNUSED(argv);
#endif /* !PANTHEIOS_USE_WIDE_STRINGS */

    pantheios::log_NOTICE(PSTR("stmt 1"));

    // Set the file name for the local back-end, truncating the
    // file's existing contents, if any.
    pantheios_be_file_setFilePath(PSTR("log.local"), PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BEID_LOCAL);

    pantheios::log_NOTICE(PSTR("stmt 2"));

    // Set the file name for the remote back-end.
    pantheios_be_file_setFilePath(PSTR("log.remote"), PANTHEIOS_BEID_REMOTE);

    pantheios::log_NOTICE(PSTR("stmt 3"));

    // Set the file name for all back-ends.
    pantheios_be_file_setFilePath(PSTR("log.all"));

    pantheios::log_NOTICE(PSTR("stmt 4"));

    pantheios::log_DEBUG(PSTR("exiting main()"));

    return EXIT_SUCCESS;
  }
  catch(std::bad_alloc&)
  {
    pantheios::log(pantheios::alert, PSTR("out of memory"));
  }
  catch(std::exception& x)
  {
  pantheios::log_CRITICAL(PSTR("Exception: "), pantheios::exception(x));
  }
  catch(...)
  {
    pantheios::logputs(pantheios::emergency, PSTR("Unexpected unknown error"));
  }

  return EXIT_FAILURE;
}
static void test_ROLL_ON_ENTRIES()
{
    // Create a file, with rolling quantum of

    unsigned    flags   =   0
                        |   PANTHEIOS_BE_FILE_F_DISCARD_CACHED_CONTENTS
                        |   PANTHEIOS_BE_FILE_F_TRUNCATE
                        |   PANTHEIOS_BE_FILE_F_ROLL_ON_ENTRY_COUNT
                        |   0;

    pantheios_be_file_setFilePath("rolling-log.test.remote", flags, flags, PANTHEIOS_BEID_REMOTE);

    const int   NUM_ENTRIES = 104;

    { for(size_t i = 0; i < NUM_ENTRIES; ++i)
    {
        pantheios::log_NOTICE("stmt #", pantheios::integer(i));
    }}

    pantheios_be_file_setFilePath(NULL, PANTHEIOS_BEID_REMOTE);

    { for(size_t i = 0; i < NUM_ENTRIES; i += ENTRY_QUANTUM)
    {
        size_t  index   =   i / ENTRY_QUANTUM;

        path_t  path    =   "rolling-log.test.remote";

        path /= pantheios::integer(index).c_str();


        file_lines_t    remote_lines(path);
        size_t          numRemote   =   remote_lines.size();

        STLSOFT_ASSERT(index < (NUM_ENTRIES / ENTRY_QUANTUM) ? ENTRY_QUANTUM == numRemote : (NUM_ENTRIES % ENTRY_QUANTUM) == numRemote);

        fs_traits_t::delete_file(path.c_str());
        fs_traits_t::get_last_error();
    }}
}
Esempio n. 6
0
int main()
{
  /* Must initialise Pantheios, when using from C (and there are no C++
   * compilation units in the link-unit).
   *
   * If this is not done, undefined behaviour will ensue ...
   */
  if(pantheios_init() < 0)
  {
    return EXIT_FAILURE;
  }
  else
  {
    pantheios_logputs(PANTHEIOS_SEV_DEBUG, PANTHEIOS_LITERAL_STRING("debug"));
    pantheios_logputs(PANTHEIOS_SEV_INFORMATIONAL, PANTHEIOS_LITERAL_STRING("info"));
    pantheios_logputs(PANTHEIOS_SEV_NOTICE, PANTHEIOS_LITERAL_STRING("notice"));
    pantheios_logputs(PANTHEIOS_SEV_WARNING, PANTHEIOS_LITERAL_STRING("warn"));

    pantheios_be_file_setFilePath(PANTHEIOS_LITERAL_STRING("file-1.log"), PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BE_FILE_F_TRUNCATE, 1);

    pantheios_logputs(PANTHEIOS_SEV_ERROR, PANTHEIOS_LITERAL_STRING("error"));
    pantheios_logputs(PANTHEIOS_SEV_CRITICAL, PANTHEIOS_LITERAL_STRING("critical"));
    pantheios_logputs(PANTHEIOS_SEV_ALERT, PANTHEIOS_LITERAL_STRING("alert"));
    pantheios_logputs(PANTHEIOS_SEV_EMERGENCY, PANTHEIOS_LITERAL_STRING("emergency"));

    pantheios_be_file_setFilePath(PANTHEIOS_LITERAL_STRING("file-5.log"), 0, 0, 5);

    /* Must uninitialise Pantheios.
     *
     * pantheios_uninit() must be called once for each successful (>=0)
     * invocation of pantheios_init().
     */
    pantheios_uninit();

    return EXIT_SUCCESS;
  }
}
Esempio n. 7
0
static int main_(int argc, char** argv)
{
  // This goes only to debugger
#ifndef PANTHEIOS_USE_WIDE_STRINGS
  pantheios::log_NOTICE(PSTR("main("), pantheios::args(argc, argv), PSTR(")"));
#else /* ? !PANTHEIOS_USE_WIDE_STRINGS */
  STLSOFT_SUPPRESS_UNUSED(argc); STLSOFT_SUPPRESS_UNUSED(argv);
#endif /* !PANTHEIOS_USE_WIDE_STRINGS */


  // This goes to console and debugger
  pantheios_be_file_setFilePath("p4.log");
  pantheios::log(pantheios::notice(beid_Syslog), PSTR("Isn't targeted multiplexing great?!"));
  pantheios::log(pantheios::notice(beid_Syslog), PSTR("Isn't targeted multiplexing great?!"));
  pantheios::log(pantheios::debug(beid_Syslog), PSTR("DEBUG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"));

  return EXIT_SUCCESS;
}
Esempio n. 8
0
int 
logging_init(const char* log_file_name) 
{

    try {
		pantheios_be_file_setFilePath(log_file_name);
#ifdef DEBUG
		pantheios::log_DEBUG("pantheios logging_init()");
#endif
		return 1;
    }
    catch(std::bad_alloc&){
        pantheios::log_ALERT("pantheios out of memory");
    }
    catch(std::exception& x){
        pantheios::log_CRITICAL("pantheios exception: ", x);
    }
    catch(...){
        pantheios::puts(pantheios::emergency, "pantheios unknown error");
    }

    return 2;
};
static int main_(int /*argc*/, char** /*argv*/)
{
    thread_handle_t   threads[32];

    pan::log_INFORMATIONAL(PSTR("main(): creating "), pan::integer(STLSOFT_NUM_ELEMENTS(threads)), PSTR(" threads"));

    { for(size_t i = 0; i < STLSOFT_NUM_ELEMENTS(threads); ++i)
    {
        void* arg = NULL;

#if defined(PLATFORMSTL_OS_IS_UNIX)

        pthread_mutex_lock(&s_mx);

        if(0 != pthread_create(&threads[i], NULL, thread_proc, arg))
        {
            pan::log_ALERT(PSTR("Failed to create thread "), pan::integer(i));

            pthread_mutex_unlock(&s_mx);

            return EXIT_FAILURE;
        }
        else
        {
            pthread_detach(threads[i]);
            ++s_activeThreads;
        }

        pthread_mutex_unlock(&s_mx);
#elif defined(PLATFORMSTL_OS_IS_WINDOWS)

        // NOTE: We are calling the Windows API function CreateThread()
        // directly, rather than going through beginthreadex() (or
        // equivalent), which is not the correct thing to do in a real
        // program, as CRT resources can be leaked.
        //
        // We do it this way in this case simply for portability of the
        // test program

        DWORD   threadId;

        threads[i] = CreateThread(NULL, 0, thread_proc, arg, 0, &threadId);

        if(NULL == threads[i])
        {
            winstl::error_desc  err;

            pan::log_ALERT(PSTR("Failed to create thread "), pan::integer(i), PSTR(": "), err);

            return EXIT_FAILURE;
        }

#else /* ? OS */
# error Operating system not discriminated
#endif /* 0 */
    }}

    s_showNotices &&
    pan::log_NOTICE(PSTR("main(): all "), pan::integer(STLSOFT_NUM_ELEMENTS(threads)), PSTR(" threads started"));

    platformstl::micro_sleep(SET_PATH_DELAY);

    s_showNotices &&
    pan::log_NOTICE(PSTR("main(): setting log file path"));

    pantheios_be_file_setFilePath(LOG_FILE_NAME, PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BE_FILE_F_TRUNCATE, 0);

    s_showNotices &&
    pan::log_NOTICE(PSTR("main(): waiting for threads to complete; this could take several minutes"));

#if defined(PLATFORMSTL_OS_IS_UNIX)

    for(;;)
    {
        pthread_mutex_lock(&s_mx);
        if(0 == s_activeThreads)
        {
            pthread_mutex_unlock(&s_mx);
            break;
        }
        else
        {
            pthread_cond_wait(&s_cv, &s_mx);
        }
        pthread_mutex_unlock(&s_mx);
    }

#elif defined(PLATFORMSTL_OS_IS_WINDOWS)

    ::WaitForMultipleObjects(STLSOFT_NUM_ELEMENTS(threads), &threads[0], true, INFINITE);

#else /* ? OS */
# error Operating system not discriminated
#endif /* 0 */

    s_showNotices &&
    pan::log_NOTICE(PSTR("main(): all "), pan::integer(STLSOFT_NUM_ELEMENTS(threads)), PSTR(" threads completed"));

    pantheios_be_file_setFilePath(NULL);

    int retVal = EXIT_SUCCESS;

    lines_t lines(LOG_FILE_NAME);

    { for(size_t i = 0; i != lines.size(); ++i)
    {
        lines_t::value_type const&  line = lines[i];

        string_view_t               scratch1;
        string_view_t               scratch2;
                                    
        string_view_t               prefix;
        string_view_t               left;
        string_view_t               middle;
        string_view_t               right;

        if( !stlsoft::split(line, PSTR('|'), prefix, scratch1) ||
            !stlsoft::split(scratch1, PSTR('|'), left, scratch2) ||
            !stlsoft::split(scratch2, PSTR('|'), middle, right))
        {
            pan::log_CRITICAL(PSTR("line does not have required format: ["), pan::integer(i), PSTR(": "), line, PSTR("]"));

            retVal = EXIT_FAILURE;
        }
        else
        {
            if(left != right)
            {
                pan::log_CRITICAL(PSTR("line prefix and suffix do not match: ["), pan::integer(i), PSTR(": "), line, PSTR("]"));

                retVal = EXIT_FAILURE;
            }
        }
    }}

    if(EXIT_SUCCESS == retVal)
    {
        s_showNotices &&
        pan::log_NOTICE(PSTR("all lines logged to file correctly"));
    }
    else
    {
        pan::log_CRITICAL(PSTR("multi-threaded use of be.file has been defective; please report to the Pantheios project"));
    }

    return retVal;
}