Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Tagged as

Using Callback Back-ends with the Pantheios Logging API Library

, 19 Jun 2008
A tutorial on using the Pantheios logging API library with Visual Studio, and customising output behaviour using callback back-ends.
pantheios.consolecallback.src.zip
LogToConsole
// LogToConsole.cpp : Defines the entry point for the console application.
//

////////////////////////////////////////////////////////////////////////////
// Includes

#include "stdafx.h"

/* Pantheios Header Files */
#include <pantheios/pantheios.hpp>
#include <pantheios/inserters/args.hpp>
#include <pantheios/backends/bec.WindowsConsole.h>

/* Standard C++ Header Files */
#include <iostream>
#include <string>

////////////////////////////////////////////////////////////////////////////
// Globals

extern "C" const char PANTHEIOS_FE_PROCESS_IDENTITY[] = "LogToConsole";

////////////////////////////////////////////////////////////////////////////
// Application initialisation callback

PANTHEIOS_CALL(void) pantheios_be_WindowsConsole_getAppInit(int /* backEndId */, pan_be_WindowsConsole_init_t* init) /* throw() */
{
#if 0
    STLSOFT_SUPPRESS_UNUSED(init);	// tell the compiler we're using it, to avoid warning
#else
    init->flags |=  PANTHEIOS_BE_INIT_F_NO_PROCESS_ID;
    init->flags |=  PANTHEIOS_BE_INIT_F_HIDE_DATE;
    init->flags |=  PANTHEIOS_BE_INIT_F_HIGH_RESOLUTION;

    init->colours[PANTHEIOS_SEV_DEBUG] = init->colours[PANTHEIOS_SEV_INFORMATIONAL];
    init->colours[PANTHEIOS_SEV_NOTICE] = init->colours[PANTHEIOS_SEV_INFORMATIONAL];

    //init->flags	=	PANTHEIOS_BE_WINDOWSCONSOLE_F_NO_COLOURS;   // Suppress severity-specific colouring of output
#endif
}

////////////////////////////////////////////////////////////////////////////
// main()

int _tmain(int argc, _TCHAR* argv[])
{
    try
    {
        pantheios::log_DEBUG("Entering main(", pantheios::args(argc, argv, pantheios::args::arg0FileOnly), ")");

#if 1
        pantheios::log_DEBUG("debug");
        pantheios::log_INFORMATIONAL("informational");
        pantheios::log_NOTICE("notice");
        pantheios::log_WARNING("warning");
        pantheios::log_ERROR("error");
        pantheios::log_CRITICAL("critical");
        pantheios::log_ALERT("alert");
        pantheios::log_EMERGENCY("EMERGENCY");
#endif

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

    return EXIT_FAILURE;
}

////////////////////////////// end of file /////////////////////////////////

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Matt (D) Wilson
Instructor / Trainer
Australia Australia
Software Development consultant, specialising in project remediation.
 
Creator of the FastFormat, Pantheios, STLSoft and VOLE open-source libraries.
 
Author of the books Extended STL, volume 1 (Addison-Wesley, 2007) and Imperfect C++ (Addison-Wesley, 2004).

| Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 19 Jun 2008
Article Copyright 2008 by Matt (D) Wilson
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid