Changeset 375 for cpp/common/log.cpp


Ignore:
Timestamp:
04/26/15 00:59:09 (9 years ago)
Author:
Maciej Komosinski
Message:

Renamed logging functions to more intuitive and simple names

File:
1 moved

Legend:

Unmodified
Added
Removed
  • cpp/common/log.cpp

    r372 r375  
    33// See LICENSE.txt for details.
    44
    5 #include "hmessage.h"
     5#include "log.h"
    66#include <common/nonstd_stdio.h>
    77#include "stl-util.h"
    88#include "Convert.h"
    99
    10 const char* HMSG_LEVEL[]={"[DEBUG] ","","[WARN] ","[ERROR] ","[CRITICAL] "};
     10const char* LOG_LEVEL[] = { "[DEBUG] ", "", "[WARN] ", "[ERROR] ", "[CRITICAL] " };
    1111
    12 void Hmessage(const char *o, const char *m, const char *txt, int w)
     12void logMessage(const char *obj, const char *method, int level, const char *msg)
    1313{
    1414        int line = 0; //all lines except the first one get the "..." prefix
     
    1616        do
    1717        {
    18                 nextsep = strchr(txt, '\n');
     18                nextsep = strchr(msg, '\n');
    1919                if (nextsep == NULL) //last chunk, until the end
    20                         nextsep = strchr(txt, '\0');
    21                 if ((nextsep > txt) && (nextsep[-1] == '\r'))
     20                        nextsep = strchr(msg, '\0');
     21                if ((nextsep > msg) && (nextsep[-1] == '\r'))
    2222                        nextsep--;
    2323                if (line == 0)
    2424                {
    2525                        if (*nextsep == 0) //there was only one line! no need to modify it in any way.
    26                                 _HmessageSingleLine(o, m, txt, w);
     26                                _logMessageSingleLine(obj, method, level, msg);
    2727                        else //first line from multi-line
    28                                 _HmessageSingleLine(o, m, string(txt, nextsep - txt).c_str(), w);
     28                                _logMessageSingleLine(obj, method, level, string(msg, nextsep - msg).c_str());
    2929                }
    3030                else //consecutive lines from multi-line
    31                         _HmessageSingleLine(o, m, (HMSG_MULTILINE_CONTINUATION + string(txt, nextsep - txt)).c_str(), w); //could also add line numbers like ...(3)... but let's keep the prefix short and simple
     31                        _logMessageSingleLine(obj, method, level, (LOG_MULTILINE_CONTINUATION + string(msg, nextsep - msg)).c_str()); //could also add line numbers like ...(3)... but let's keep the prefix short and simple
    3232                line++;
    3333                if ((nextsep[0] == '\r') && (nextsep[1] == '\n'))
    34                         txt = nextsep + 2;
     34                        msg = nextsep + 2;
    3535                else if (*nextsep)
    36                         txt = nextsep + 1;
     36                        msg = nextsep + 1;
    3737        } while (*nextsep);
    3838}
    3939
    4040
    41 void Hprintf_va(const char *o,const char *m,int w,const char *bl,va_list va)
     41void logPrintf_va(const char *obj, const char *method, int level, const char *msgf, va_list va)
    4242{
    43         string buf=ssprintf_va(bl,va);
    44         Hmessage(o,m,buf.c_str(),w);
     43        string buf = ssprintf_va(msgf, va);
     44        logMessage(obj, method, level, buf.c_str());
    4545}
    4646
    47 void Hprintf(const char *o,const char *m,int w,const char *bl, ...)
     47void logPrintf(const char *obj, const char *method, int level, const char *msgf, ...)
    4848{
    4949        va_list argptr;
    50         va_start(argptr,bl);
    51         Hprintf_va(o,m,w,bl,argptr);
     50        va_start(argptr, msgf);
     51        logPrintf_va(obj, method, level, msgf, argptr);
    5252        va_end(argptr);
    5353}
    5454
    55 void printH(const char *bl,...)
     55void log_printf(const char *msgf, ...)
    5656{
    5757        va_list argptr;
    58         va_start(argptr,bl);
    59         Hprintf_va("Message","printf",HMLV_INFO,bl,argptr);
     58        va_start(argptr, msgf);
     59        logPrintf_va("Message", "printf", LOG_INFO, msgf, argptr);
    6060        va_end(argptr);
    6161}
Note: See TracChangeset for help on using the changeset viewer.