Ignore:
Timestamp:
03/12/15 04:19:45 (9 years ago)
Author:
Maciej Komosinski
Message:

Error message formatting: - "[x] x::x - " -> "[x] x.x: "
Error managers support configurable multi-line "call stack" messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/errmgr/errmanager.cpp

    r286 r336  
    88void _FramMessageSingleLine(const char *o, const char *m, const char *txt, int w)
    99{
    10 tlsGetRef(errmgr_instance).send(o,m,txt,w);
     10        tlsGetRef(errmgr_instance).send(o, m, txt, w);
    1111}
    1212
    13 THREAD_LOCAL_DEF(ErrorManager,errmgr_instance);
     13THREAD_LOCAL_DEF(ErrorManager, errmgr_instance);
    1414
    15 void ErrorManager::send(int level,const char *o,const char *m,const char *bl,int w)
     15void ErrorManager::send(int level, const char *o, const char *m, const char *bl, int w)
    1616{
    17 if (level>=handlers.size()) level=handlers.size()-1;
    18 bool blocked=0;
    19 for(int i=level;i>=0;i--)
     17        if (level >= handlers.size()) level = handlers.size() - 1;
     18        bool blocked = 0;
     19        for (int i = level; i >= 0; i--)
    2020        {
    21         ErrorHandlerBase *r=handlers(i);
    22         if ((!blocked)||(r->options & ErrorHandlerBase::CannotBeBlocked))
    23                 r->handle(o,m,bl,w);
    24         if (!(r->options & ErrorHandlerBase::DontBlock)) blocked=1;
     21                ErrorHandlerBase *r = handlers(i);
     22                if ((!(r->options & ErrorHandlerBase::Paused)) &&
     23                        ((!blocked) || (r->options & ErrorHandlerBase::CannotBeBlocked)))
     24                {
     25                        r->handle(o, m, bl, w);
     26                        if (!(r->options & ErrorHandlerBase::DontBlock)) blocked = 1;
     27                }
    2528        }
    2629}
     
    2831int ErrorManager::add(ErrorHandlerBase *h)
    2932{
    30 h->mgr=this;
    31 handlers+=h;
    32 return handlers.size()-1;
     33        h->mgr = this;
     34        handlers += h;
     35        return handlers.size() - 1;
    3336}
    3437
    3538void ErrorManager::remove(int i)
    3639{
    37 ErrorHandlerBase *h=handlers(i);
    38 h->mgr=0;
    39 handlers.remove(i);
     40        ErrorHandlerBase *h = handlers(i);
     41        h->mgr = 0;
     42        handlers.remove(i);
    4043}
    4144
    4245void ErrorManager::remove(ErrorHandlerBase *h)
    4346{
    44 int i;
    45 if ((i=handlers.find(h))<0) return;
    46 remove(i);
     47        int i;
     48        if ((i = handlers.find(h)) < 0) return;
     49        remove(i);
    4750}
    4851
    4952void ErrorManager::removeAll()
    5053{
    51 while(handlers.size()>0)
    52         remove(handlers.size()-1);
     54        while (handlers.size() > 0)
     55                remove(handlers.size() - 1);
    5356}
    5457
    5558//////////////////////////////////
    5659
    57 void ErrorHandlerBase::send(const char *o,const char *m,const char *bl,int w)
     60void ErrorHandlerBase::send(const char *o, const char *m, const char *bl, int w)
    5861{
    59 if (!isEnabled()) return;
    60 int level=mgr->find(this);
    61 if (level>=0) mgr->send(level-1,o,m,bl,w);
     62        if (!isEnabled()) return;
     63        int level = mgr->find(this);
     64        if (level >= 0) mgr->send(level - 1, o, m, bl, w);
    6265}
    6366
    64 void ErrorHandlerBase::FMprintf(const char *o,const char *m,int w,const char *bl, ...)
     67void ErrorHandlerBase::FMprintf(const char *o, const char *m, int w, const char *bl, ...)
    6568{
    66 if (!isEnabled()) return;
    67 string buf;
    68 va_list argptr;
    69 va_start(argptr,bl);
    70 buf=ssprintf_va(bl,argptr);
    71 va_end(argptr);
    72 send(o,m,buf.c_str(),w);
     69        if (!isEnabled()) return;
     70        string buf;
     71        va_list argptr;
     72        va_start(argptr, bl);
     73        buf = ssprintf_va(bl, argptr);
     74        va_end(argptr);
     75        send(o, m, buf.c_str(), w);
    7376}
    7477
     
    7679void ErrorHandlerBase::enable()
    7780{
    78 if (isEnabled()) return;
    79 tlsGetRef(errmgr_instance).add(this);
     81        if (isEnabled()) return;
     82        tlsGetRef(errmgr_instance).add(this);
    8083}
    8184
    8285void ErrorHandlerBase::disable()
    8386{
    84 if (!isEnabled()) return;
    85 tlsGetRef(errmgr_instance).remove(this);
     87        if (!isEnabled()) return;
     88        tlsGetRef(errmgr_instance).remove(this);
     89}
     90
     91void ErrorHandlerBase::pause()
     92{
     93        if (isPaused()) return;
     94        options |= Paused;
     95}
     96
     97void ErrorHandlerBase::resume()
     98{
     99        if (!isPaused()) return;
     100        options &= ~Paused;
    86101}
    87102
    88103/////////////////////////////////
    89104
    90 void ErrorHandler::handle(const char *o,const char *m,const char *bl,int w)
     105void ErrorHandler::handle(const char *o, const char *m, const char *bl, int w)
    91106{
    92 if (w>maxlevel) maxlevel=w;
    93 if (w>=FMLV_INFO) infocount++;
    94 if (w>=FMLV_WARN) warncount++;
    95 if (w>=FMLV_ERROR) errcount++;
     107        if (w > maxlevel) maxlevel = w;
     108        if (w >= FMLV_INFO) infocount++;
     109        if (w >= FMLV_WARN) warncount++;
     110        if (w >= FMLV_ERROR) errcount++;
    96111
    97 if (w>=storlevel)
     112        if (w >= storlevel)
    98113        {
    99         storcount++;
    100         if (options & (StoreFirstMessage|StoreAllMessages))
     114                storcount++;
     115                if (options & (StoreFirstMessage | StoreAllMessages))
    101116                {
    102                 if (!((options&StoreFirstMessage)&&(msgs.len()>0)))
     117                        if (!((options&StoreFirstMessage) && (msgs.len() > 0)))
    103118                        {
    104                         if (msgs.len()>0) msgs+='\n';
    105                         msgs+=o; msgs+="::"; msgs+=m;
    106                         msgs+=" - "; msgs+=bl;
     119                                if (msgs.len() > 0) msgs += '\n';
     120                                msgs += o; msgs += "::"; msgs += m;
     121                                msgs += " - "; msgs += bl;
    107122                        }
    108123                }
Note: See TracChangeset for help on using the changeset viewer.