1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Logger Class in C++

Discussion in 'C++' started by senseiwa, Jun 28, 2010.

  1. senseiwa

    senseiwa New Member

    Joined:
    Jun 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi! I am trying to implement a logger class that behaves like printf: this is the only requirement, to implement a member function that accepts a format and a variable number of arguments, just like printf.

    However, the static member Logger::log is implemented using old-style C streams:


    Code:
    void Logger::log(char *format, ...)
    {
    
    #ifdef DEBUG
        va_list args;
        char    *p;
        
        // Check for null argument list
        va_start(args, format);    
        p = va_arg(args, char*);
    
        va_end(args);
        
            //
        va_start(args, format);
        if (p == NULL)
        {
    
            fprintf(logger, "%s", format);
        }
        else
        {
            fvprintf(logger, format, args);
    
        }
        
        va_end(args);
    #endif
    }
    
    
    My question is simple. Is there a way of moving away the FILE* logger, replacing it with some C++ iostream-reletated class?

    Sorry for this (probably) simple question!


    Thanks and Cheers!
     

Share This Page