Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Tutorial: Targeted Multiplexing

Tutorials
2008-09-19
2013-05-20
  • Matt Wilson
    Matt Wilson
    2008-09-19

    This is a series of mini-tutorials that answer Juan M's query about how to target the output of a given log statement to a given back-end.

    See http://sourceforge.net/forum/forum.php?thread_id=2186546&forum_id=475314 for more information.

     
    • Matt Wilson
      Matt Wilson
      2008-09-19

      Targeted Multiplexing: Step 1
      -------------------------------------

      We'll start simple with the following case:
      * the application is Windows
      * there are two back-ends: WindowsDebugger and WindowsConsole
      * all messages go to the WindowsDebugger
      * only specially indicated messages go the WindowsConsole

      This is achieved as follows:

      enum
      {
          Debugger    =    1,
          Console     =    2
      };

      pan_be_N_t    PAN_BE_N_BACKEND_LIST[] =
      {
          PANTHEIOS_BE_N_STDFORM_ENTRY(Debugger, pantheios_be_WindowsDebugger, 0),
          PANTHEIOS_BE_N_STDFORM_ENTRY(Console, pantheios_be_WindowsConsole, PANTHEIOS_BE_N_F_ID_MUST_MATCH_CUSTOM28),
          PANTHEIOS_BE_N_TERMINATOR_ENTRY
      };

      /* ////////////////////////////////////////////////////////////////////// */

      int main(int argc, char** argv)
      {
          // This goes only to debugger
          pantheios::log_DEBUG("main(", pantheios::args(argc, argv), ")");

          // This goes to console and debugger
          pantheios::log(pantheios::debug(Console), "Isn't targeted multiplexing great?!");

          return EXIT_SUCCESS;
      }

      The PANTHEIOS_BE_N_F_ID_MUST_MATCH_CUSTOM28 flag causes be.N to only output to the given back-end when the severity extra information, specified by using the function call operator of one of the levels instances {pantheios::debug, pantheios::informational, ..., pantheios::emergency}, matches the back-end's back-end identifier.

      I'll cover more sophisticated uses in the next post

      HTH

      Matt

       
    • Matt Wilson
      Matt Wilson
      2008-09-20

      Targeted Multiplexing: Step 2
      -------------------------------------

      Next we'll refine the first step (http://sourceforge.net/forum/message.php?msg_id=5292436) as follows:
      * instead of all messages going to the WindowsDebugger, it will recognise only those messages that are _not_ directly targeted to another back-end

      This is achieved as follows:

      enum
      {
      Debugger = 1,
      Console = 2
      };

      pan_be_N_t PAN_BE_N_BACKEND_LIST[] =
      {
      PANTHEIOS_BE_N_STDFORM_ENTRY(Debugger, pantheios_be_WindowsDebugger, PANTHEIOS_BE_N_F_IGNORE_NONMATCHED_CUSTOM28_ID),
      PANTHEIOS_BE_N_STDFORM_ENTRY(Console, pantheios_be_WindowsConsole, PANTHEIOS_BE_N_F_ID_MUST_MATCH_CUSTOM28),
      PANTHEIOS_BE_N_TERMINATOR_ENTRY
      };

      /* ////////////////////////////////////////////////////////////////////// */

      int main(int argc, char** argv)
      {
      // This goes only to debugger
      pantheios::log_DEBUG("main(", pantheios::args(argc, argv), ")");

      // This goes to console and debugger
      pantheios::log(pantheios::debug(Console), "Isn't targeted multiplexing great?!");

      return EXIT_SUCCESS;
      }

      The PANTHEIOS_BE_N_F_IGNORE_NONMATCHED_CUSTOM28_ID flag causes be.N to only output to the given back-end when the severity extra information, specified by using the function call operator of one of the levels instances {pantheios::debug, pantheios::informational, ..., pantheios::emergency}, is not specified (i.e is 0), or matches the back-end's back-end identifier.

      HTH

      Matt

       
  • So I'm trying the same thing - targeted output to both windows console and file under VS9 on windows 7 x64. What happens is that only windows console actually logs. as soon as i
    //#include <pantheios/implicit_link/be.WindowsConsole.WithCallback.h>
    no logging to file occurs. Once the the console implicit link #include is commented out , the code logs to file properly. 
    Here is the code

    #include "stdafx.h"

    #include <pantheios/pantheios.hpp>
    #include <pantheios/inserters/args.hpp>
    #include <pantheios/inserters/integer.hpp>
    #include <pantheios/backends/bec.WindowsConsole.h>
    #include <pantheios/backends/bec.file.h>
    #include <pantheios/frontends/fe.N.h>
    #include <pantheios/backends/be.N.h>
    #include <pantheios/backends/bec.file.h>

    #include <stdlib.h>

    #include <iostream>
    #include <string>

    extern "C" const char PANTHEIOS_FE_PROCESS_IDENTITY = "n-test";

    enum
    {
    File = 1,
    Debugger = 2,
    Console = 3
    };

    pan_fe_N_t PAN_FE_N_SEVERITY_CEILINGS  =
    {
    { 1,  PANTHEIOS_SEV_NOTICE    } /* Filters out everything below 'notice' */
    , { 2,  PANTHEIOS_SEV_DEBUG     } /* Allows all severities */
    , { 3,  PANTHEIOS_SEV_ERROR     } /* Allows only 'error', 'critical', 'alert', 'emergency' */
    , { 0,  PANTHEIOS_SEV_NOTICE    } /* Terminates the array; sets the default ceiling to 'notice' */
    };

    pan_be_N_t PAN_BE_N_BACKEND_LIST =
    {
    PANTHEIOS_BE_N_STDFORM_ENTRY(File, pantheios_be_file, 0),
    PANTHEIOS_BE_N_STDFORM_ENTRY(Console, pantheios_be_WindowsConsole, 0),
    PANTHEIOS_BE_N_TERMINATOR_ENTRY
    };

    // console init
    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 = init->colours;
    init->colours = init->colours;

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

    // file init
    PANTHEIOS_CALL(void) pantheios_be_file_getAppInit(int /*backEndId*/, pan_be_file_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;
    #endif
    }

    int _tmain(int argc, _TCHAR* argv)
    {

    pantheios_be_file_setFilePath(PSTR("aaa.log"), PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BEID_ALL);

    pantheios::log_DEBUG("main(", pantheios::args(argc, argv), ")");
    pantheios::log_INFORMATIONAL(__FUNCTION__, ":", pantheios::integer(__LINE__) ,  ",  hi there");

    pantheios::log_NOTICE("notice");
    pantheios::log_WARNING("warning");
    pantheios::log_CRITICAL("critical");

    pantheios_be_file_setFilePath(NULL, PANTHEIOS_BEID_ALL);

    return EXIT_SUCCESS;
    }

     
  • correction to last post:
    only console logs (no file logging happens) with:

    #include <pantheios/implicit_link/be.WindowsConsole.WithCallback.h>
    #include <pantheios/implicit_link/be.file.WithCallback.h>

    And as soon as i comment out the #include <pantheios/implicit_link/be.WindowsConsole.WithCallback.h> line, the program starts logging to console.

    I just started playing with pantheios a couple hours ago so maybe i'm doing something lame. I really like pantheios so far - nice job!