Changeset 375 for cpp/common


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

Renamed logging functions to more intuitive and simple names

Location:
cpp/common
Files:
3 edited
2 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}
  • cpp/common/log.h

    r372 r375  
    33// See LICENSE.txt for details.
    44
    5 #ifndef _HMESSAGE_H_
    6 #define _HMESSAGE_H_
     5#ifndef _COMMON_LOG_H_
     6#define _COMMON_LOG_H_
    77
    88#include <stdarg.h>
    99
    10 extern const char* HMSG_LEVEL[];
    11 #define HMSG_FORMAT "%s%s.%s: %s"
    12 #define HMSG_MULTILINE_CONTINUATION "..."
     10extern const char* LOG_LEVEL[];
     11#define LOG_FORMAT "%s%s.%s: %s"
     12#define LOG_MULTILINE_CONTINUATION "..."
    1313
    14 void Hprintf(const char *o,const char *m,int w,const char *bl, ...);
    15 void Hprintf_va(const char *o,const char *m,int w,const char *bl,va_list va); //a different name than Hprintf - otherwise the compiler could confuse the "string" parameter with va_list and could call the wrong function
    16 void printH(const char *bl,...); //a shorthand for printf (a different name again to avoid the risk of confusion with the two functions above. This would be unlikely but possible when the argument types would match)
    17 void Hmessage(const char *o,const char *m,const char *txt,int w);
    1814
    19 void _HmessageSingleLine(const char *o,const char *m,const char *txt,int w); //don't call this directly - it is used internally
     15void logPrintf(const char *obj, const char *method, int level, const char *msgf, ...);
     16void logPrintf_va(const char *obj, const char *method, int level, const char *msgf, va_list va); //a different name than logPrintf - otherwise the compiler could confuse the "string" parameter with va_list and could call the wrong function
     17void log_printf(const char *msgf, ...); //a shorthand for printf (a different name again to avoid the risk of confusion with the two functions above. This would be unlikely but possible when the argument types would match)
     18void logMessage(const char *obj, const char *method, int level, const char *msg);
    2019
    21 #define HMLV_DEBUG -1
    22 #define HMLV_INFO 0
    23 #define HMLV_WARN 1
    24 #define HMLV_ERROR 2
    25 #define HMLV_CRITICAL 3
     20void _logMessageSingleLine(const char *obj, const char *method, int level, const char *msg); //don't call this directly - it is used internally
    2621
    27 /*
    28 w: weight (importance) of a message
    29 -1:debugging information, not needed for final users
    30 0: information
    31 1: warning or corrected error
    32 2: uncorrected error. can cause malfunction
    33 3: serious error, causes side effects. user should save what can be saved and restart the application
    34 */
     22
     23
     24//level (importance) of a message
     25#define LOG_DEBUG -1 //debugging information, not needed for final users
     26#define LOG_INFO 0 //information
     27#define LOG_WARN 1 //warning or corrected error
     28#define LOG_ERROR 2 //uncorrected error, can cause malfunction
     29#define LOG_CRITICAL 3 //serious error, causes side effects. User should save what can be saved and restart the application
    3530
    3631#endif
  • cpp/common/nonstd_math.cpp

    r372 r375  
    8181// But it was resolved by restarting windows and cleaning all intermediate compilation files :o (restarting windows was the key element! restarting BC++Builder and deleting files would not help)
    8282
    83 #include "hmessage.h"
     83#include "log.h"
    8484
    8585unsigned int fp_control_word_std;
     
    8989{
    9090        //unsigned int was=_clear87();
    91         //Hprintf("","fpExceptInit",HMLV_INFO,"control87 status before clear was %08x", was);
     91        //logPrintf("","fpExceptInit",LOG_INFO,"control87 status before clear was %08x", was);
    9292        fp_control_word_std=_control87(0, 0);             //4978 = 1001101110010
    9393        // Make the new fp env same as the old one, except for the changes we're going to make
     
    9898{
    9999        unsigned int was=_clear87(); //trzeba czyscic zeby nie bylo exception...
    100         //Hprintf("","fpExceptEnable ",HMLV_INFO,"control87 status before clear was %08x", was);
     100        //logPrintf("","fpExceptEnable ",LOG_INFO,"control87 status before clear was %08x", was);
    101101        _control87(fp_control_word_std, 0xffffffff);
    102         //Hprintf("","fpExceptEnable ",HMLV_INFO,"control87 flags are %08x", _control87(0, 0)); //kontrola co sie ustawilo
     102        //logPrintf("","fpExceptEnable ",LOG_INFO,"control87 flags are %08x", _control87(0, 0)); //kontrola co sie ustawilo
    103103}
    104104
     
    106106{
    107107        unsigned int was=_clear87(); //trzeba czyscic zeby nie bylo exception...
    108         //Hprintf("","fpExceptDisable",HMLV_INFO,"control87 status before clear was %08x", was);
     108        //logPrintf("","fpExceptDisable",LOG_INFO,"control87 status before clear was %08x", was);
    109109        _control87(fp_control_word_muted, 0xffffffff);
    110         //Hprintf("","fpExceptDisable",HMLV_INFO,"control87 flags are %08x", _control87(0, 0)); //kontrola co sie ustawilo
     110        //logPrintf("","fpExceptDisable",LOG_INFO,"control87 flags are %08x", _control87(0, 0)); //kontrola co sie ustawilo
    111111}
    112112
  • cpp/common/nonstd_stdio.cpp

    r374 r375  
    242242
    243243#ifdef __ANDROID__
    244 #include "hmessage.h"
     244#include "log.h"
    245245#include "nonstd.h"
    246246#include "nonstd_stl.h"
     
    248248{
    249249        string respath=getAppResourcesDir();
    250         //printH("Opening '%s', mode='%s'",path,mode);
    251         //printH("getAppResourcesDir()='%s'",respath.c_str());
     250        //log_printf("Opening '%s', mode='%s'",path,mode);
     251        //log_printf("getAppResourcesDir()='%s'",respath.c_str());
    252252        NvFile *rfile=NULL; //can only read
    253253        FILE *rwfile=NULL;
     
    256256                path+=respath.length(); //strip the prefix, we need a relative path in assets
    257257                if (strstr(mode,"w"))
    258                         printH("Warning: attempt to open a read-only resource '%s' in writable mode '%s'",path,mode);
     258                        log_printf("Warning: attempt to open a read-only resource '%s' in writable mode '%s'",path,mode);
    259259                rfile=NvFOpen(path); //"mode" not supported! can only read
    260                 //printH("Opened RES file as %p",rfile);
     260                //log_printf("Opened RES file as %p",rfile);
    261261                if (rfile==NULL) return NULL;
    262262        } else //a "normal" access (HOME)
    263263        {
    264264                rwfile=fopen(path,mode);
    265                 //printH("Opened HOME file as %p",rwfile);
     265                //log_printf("Opened HOME file as %p",rwfile);
    266266                if (rwfile==NULL) return NULL;
    267267        }
  • cpp/common/stl-util.cpp

    r374 r375  
    99#include "Convert.h"
    1010#include "nonstd.h"
    11 #include "hmessage.h"
     11#include "log.h"
    1212#include <assert.h>
    1313#ifdef USE_VIRTFILE
     
    103103        }
    104104        if (warn_on_missing_file && !ok)
    105                 Hprintf("stl-util", "readCompleteFile", HMLV_WARN, "Couldn't open file '%s'", filename);
     105                logPrintf("stl-util", "readCompleteFile", LOG_WARN, "Couldn't open file '%s'", filename);
    106106        return ok;
    107107}
     
    129129        }
    130130        if (warn_on_fail && !ok)
    131                 Hprintf("stl-util", "writeCompleteFile", HMLV_WARN, "couldn't write file '%s'", filename);
     131                logPrintf("stl-util", "writeCompleteFile", LOG_WARN, "couldn't write file '%s'", filename);
    132132        return ok;
    133133}
Note: See TracChangeset for help on using the changeset viewer.