src/Utilities.cpp
// returns ptr to static buffer filled with log string
returns ptr to static buffer filled with log string
returns ptr to static buffer filled with log string
const char* LogGetString (const char* szPath, int ln, const char* szFunc,
                          logLevelTy lvl, const char* szMsg, va_list args )
{
     static char aszMsg[2048];
    if ( lvl < logMSG )                             
    {
        const char* szFile = strrchr(szPath, PATH_DELIM_STD);  
        if ( !szFile ) szFile = szPath; else szFile++;
        snprintf(aszMsg, sizeof(aszMsg), "%s %s/XPMP2 %s %s:%d/%s: ",
                 GetMiscNetwTimeStr().c_str(),      
                 glob.logAcronym.c_str(), LOG_LEVEL[lvl],
                 szFile, ln, szFunc);
    }
    else
        snprintf(aszMsg, sizeof(aszMsg), "%s %s/XPMP2: ",
                 GetMiscNetwTimeStr().c_str(),          
                 glob.logAcronym.c_str());
    if (args) {
        vsnprintf(&aszMsg[strlen(aszMsg)],
                  sizeof(aszMsg)-strlen(aszMsg)-1,      
                  szMsg,
                  args);
    }
    size_t l = strlen(aszMsg);
    if ( aszMsg[l-1] != '\n' )
    {
        aszMsg[l]   = '\n';
        aszMsg[l+1] = 0;
    }
    return aszMsg;
}
const char * LogGetString ( const char * szPath , int ln , const char * szFunc , logLevelTy lvl , const char * szMsg , va_list args ) { static char aszMsg [ 2048 ] ; if ( lvl < logMSG ) { const char * szFile = strrchr ( szPath , PATH_DELIM_STD ) ; if ( ! szFile ) szFile = szPath ; else szFile ++ ; snprintf ( aszMsg , sizeof ( aszMsg ) , " " , GetMiscNetwTimeStr ( ) . c_str ( ) , glob . logAcronym . c_str ( ) , LOG_LEVEL [ lvl ] , szFile , ln , szFunc ) ; } else snprintf ( aszMsg , sizeof ( aszMsg ) , " " , GetMiscNetwTimeStr ( ) . c_str ( ) , glob . logAcronym . c_str ( ) ) ; if ( args ) { vsnprintf ( & aszMsg [ strlen ( aszMsg ) ] , sizeof ( aszMsg ) - strlen ( aszMsg ) - 1 , szMsg , args ) ; } size_t l = strlen ( aszMsg ) ; if ( aszMsg [ l - 1 ] != ' \n ' ) { aszMsg [ l ] = ' \n ' ; aszMsg [ l + 1 ] = 0 ; } return aszMsg ; }
returns ptr to static buffer filled with log string
returns ptr to static buffer filled with log string
// prepare timestamp // normal messages without, all other with location info // extract file from path // Running time stamp // Running time stamp // append given message // we save one char for the CR // ensure there's a trailing CR // return the static buffer