Changeset 375 for cpp/frams/loggers


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

Renamed logging functions to more intuitive and simple names

Location:
cpp/frams/loggers
Files:
6 deleted
4 copied
1 moved

Legend:

Unmodified
Added
Removed
  • cpp/frams/loggers/loggers.cpp

    r374 r375  
    33// See LICENSE.txt for details.
    44
    5 #include "mhandlers.h"
     5#include "loggers.h"
    66#include <common/stl-util.h>
    77
    8 void _HmessageSingleLine(const char *o, const char *m, const char *txt, int w)
     8void _logMessageSingleLine(const char *o, const char *m, int w, const char *txt)
    99{
    10         tlsGetRef(message_handler_manager_instance).send(o, m, txt, w);
     10        tlsGetRef(message_handler_manager_instance).send(o, m, w, txt);
    1111}
    1212
    13 THREAD_LOCAL_DEF(MessageHandlerManager, message_handler_manager_instance);
     13THREAD_LOCAL_DEF(LoggerManager, message_handler_manager_instance);
    1414
    15 void MessageHandlerManager::send(int level, const char *o, const char *m, const char *bl, int w)
     15void LoggerManager::send(int level, const char *o, const char *m, int w, const char *bl)
    1616{
    1717        if (level >= handlers.size()) level = handlers.size() - 1;
     
    1919        for (int i = level; i >= 0; i--)
    2020        {
    21                 MessageHandlerBase *r = handlers(i);
    22                 if ((!(r->options & MessageHandlerBase::Paused)) &&
    23                         ((!blocked) || (r->options & MessageHandlerBase::CannotBeBlocked)))
     21                LoggerBase *r = handlers(i);
     22                if ((!(r->options & LoggerBase::Paused)) &&
     23                        ((!blocked) || (r->options & LoggerBase::CannotBeBlocked)))
    2424                {
    25                         r->handle(o, m, bl, w);
    26                         if (!(r->options & MessageHandlerBase::DontBlock)) blocked = 1;
     25                        r->handle(o, m, w, bl);
     26                        if (!(r->options & LoggerBase::DontBlock)) blocked = 1;
    2727                }
    2828        }
    2929}
    3030
    31 int MessageHandlerManager::add(MessageHandlerBase *h)
     31int LoggerManager::add(LoggerBase *h)
    3232{
    3333        h->manager = this;
     
    3636}
    3737
    38 void MessageHandlerManager::remove(int i)
     38void LoggerManager::remove(int i)
    3939{
    40         MessageHandlerBase *h = handlers(i);
     40        LoggerBase *h = handlers(i);
    4141        h->manager = NULL;
    4242        handlers.remove(i);
    4343}
    4444
    45 void MessageHandlerManager::remove(MessageHandlerBase *h)
     45void LoggerManager::remove(LoggerBase *h)
    4646{
    4747        int i;
     
    5050}
    5151
    52 void MessageHandlerManager::removeAll()
     52void LoggerManager::removeAll()
    5353{
    5454        while (handlers.size() > 0)
     
    5858//////////////////////////////////
    5959
    60 void MessageHandlerBase::send(const char *o, const char *m, const char *bl, int w)
     60void LoggerBase::send(const char *o, const char *m, int w, const char *bl)
    6161{
    6262        if (!isEnabled()) return;
    6363        int level = manager->find(this);
    64         if (level >= 0) manager->send(level - 1, o, m, bl, w);
     64        if (level >= 0) manager->send(level - 1, o, m, w, bl);
    6565}
    6666
    67 void MessageHandlerBase::Hprintf(const char *o, const char *m, int w, const char *bl, ...)
     67void LoggerBase::logPrintf(const char *o, const char *m, int w, const char *bl, ...)
    6868{
    6969        if (!isEnabled()) return;
     
    7373        buf = ssprintf_va(bl, argptr);
    7474        va_end(argptr);
    75         send(o, m, buf.c_str(), w);
     75        send(o, m, w, buf.c_str());
    7676}
    7777
    7878
    79 void MessageHandlerBase::enable()
     79void LoggerBase::enable()
    8080{
    8181        if (isEnabled()) return;
     
    8383}
    8484
    85 void MessageHandlerBase::disable()
     85void LoggerBase::disable()
    8686{
    8787        if (!isEnabled()) return;
     
    8989}
    9090
    91 void MessageHandlerBase::pause()
     91void LoggerBase::pause()
    9292{
    9393        if (isPaused()) return;
     
    9595}
    9696
    97 void MessageHandlerBase::resume()
     97void LoggerBase::resume()
    9898{
    9999        if (!isPaused()) return;
     
    103103/////////////////////////////////
    104104
    105 void MessageHandlerToMemory::handle(const char *o, const char *m, const char *bl, int w)
     105void LoggerToMemory::handle(const char *o, const char *m, int w, const char *bl)
    106106{
    107107        if (w > maxlevel) maxlevel = w;
    108         if (w >= HMLV_INFO) infocount++;
    109         if (w >= HMLV_WARN) warncount++;
    110         if (w >= HMLV_ERROR) errcount++;
     108        if (w >= LOG_INFO) infocount++;
     109        if (w >= LOG_WARN) warncount++;
     110        if (w >= LOG_ERROR) errcount++;
    111111
    112112        if (w >= minleveltostore)
     
    118118                        {
    119119                                if (msgs.len() > 0) msgs += '\n';
    120                                 msgs += o; msgs += "::"; msgs += m;
    121                                 msgs += " - "; msgs += bl;
     120                                msgs += SString::sprintf(LOG_FORMAT,LOG_LEVEL[w+1],o,m,bl);
    122121                        }
    123122                }
  • cpp/frams/loggers/loggers.h

    r374 r375  
    33// See LICENSE.txt for details.
    44
    5 #ifndef _MHANDLERS_H_
    6 #define _MHANDLERS_H_
     5#ifndef _FRAMS_LOGGERS_H_
     6#define _FRAMS_LOGGERS_H_
    77
    88#include <frams/util/list.h>
    99#include <frams/util/sstring.h>
    10 #include <common/hmessage.h>
     10#include <common/log.h>
    1111#include <common/threads.h>
    1212
    13 class MessageHandlerBase;
     13class LoggerBase;
    1414
    15 class MessageHandlerManager
     15class LoggerManager
    1616{
    17         friend class MessageHandlerBase;
    18         SListTempl<MessageHandlerBase*> handlers;
    19         void send(int level, const char *o, const char *m, const char *bl, int w);
     17        friend class LoggerBase;
     18        SListTempl<LoggerBase*> handlers;
     19        void send(int level, const char *o, const char *m, int w, const char *bl);
    2020public:
    21         int find(MessageHandlerBase *r) { return handlers.find(r); }
    22         int add(MessageHandlerBase *r);
     21        int find(LoggerBase *r) { return handlers.find(r); }
     22        int add(LoggerBase *r);
    2323        void remove(int i);
    24         void remove(MessageHandlerBase *r);
     24        void remove(LoggerBase *r);
    2525        void removeAll();
    26         void send(const char *o, const char *m, const char *bl, int w)
     26        void send(const char *o, const char *m, int w, const char *bl)
    2727        {
    28                 send(handlers.size() - 1, o, m, bl, w);
     28                send(handlers.size() - 1, o, m, w, bl);
    2929        }
    30         ~MessageHandlerManager() { removeAll(); }
     30        ~LoggerManager() { removeAll(); }
    3131};
    3232
    33 extern THREAD_LOCAL_DECL(MessageHandlerManager, message_handler_manager_instance);
     33extern THREAD_LOCAL_DECL(LoggerManager, message_handler_manager_instance);
    3434
    3535////////////////////////////////////////
    3636
    37 class MessageHandlerBase
     37class LoggerBase
    3838{
    39         friend class MessageHandlerManager;
     39        friend class LoggerManager;
    4040protected:
    41         MessageHandlerManager* manager;
     41        LoggerManager* manager;
    4242        int options;
    4343
    4444public:
    4545
    46         enum HandlerOptions
     46        enum LoggerOptions
    4747        {
    4848                DontBlock = 1, CannotBeBlocked = 2, Enable = 4, Paused = 8
    4949        };
    5050
    51         void Hprintf(const char *o, const char *m, int w, const char *bl, ...);
    52         void send(const char *o, const char *m, const char *bl, int w);
     51        void logPrintf(const char *o, const char *m, int w, const char *bl, ...);
     52        void send(const char *o, const char *m, int w, const char *bl);
    5353
    5454        bool isEnabled() { return manager ? true : false; }
     
    5959        void resume();
    6060
    61         MessageHandlerBase(int opts = 0) :manager(NULL), options(opts)
     61        LoggerBase(int opts = 0) :manager(NULL), options(opts)
    6262        {
    6363                if (options&Enable) enable();
    6464        }
    65         virtual ~MessageHandlerBase()
     65        virtual ~LoggerBase()
    6666        {
    6767                disable();
    6868        }
    6969
    70         virtual void handle(const char *o, const char *m, const char *bl, int w) {}
     70        virtual void handle(const char *o, const char *m, int w, const char *bl) {}
    7171};
    7272
    7373///////////////////////////////////////////
    7474
    75 class MessageHandlerToMemory : public MessageHandlerBase
     75class LoggerToMemory : public LoggerBase
    7676{
    7777protected:
     
    8181public:
    8282
    83         void reset() { maxlevel = HMLV_INFO - 1; errcount = warncount = storedcount = infocount = 0; msgs = 0; }
     83        void reset() { maxlevel = LOG_INFO - 1; errcount = warncount = storedcount = infocount = 0; msgs = 0; }
    8484
    8585        enum Options2
     
    9595        const SString& getMessages() { return msgs; }
    9696
    97         MessageHandlerToMemory(int opts = 0, int minimal_level_to_store = HMLV_ERROR) :MessageHandlerBase(opts), minleveltostore(minimal_level_to_store)
     97        LoggerToMemory(int opts = 0, int minimal_level_to_store = LOG_ERROR) :LoggerBase(opts), minleveltostore(minimal_level_to_store)
    9898        {
    9999                reset();
    100100        }
    101101
    102         void handle(const char *o, const char *m, const char *bl, int w);
     102        void handle(const char *o, const char *m, int w, const char *bl);
    103103};
    104104
    105 class RedirectingMessageHandler : public MessageHandlerBase
     105class RedirectingLogger : public LoggerBase
    106106{
    107         MessageHandlerManager *other_manager;
     107        LoggerManager *other_manager;
    108108public:
    109         RedirectingMessageHandler(MessageHandlerManager *other_mgr,int opts=0)
    110                 :MessageHandlerBase(opts), other_manager(other_mgr) {}
     109        RedirectingLogger(LoggerManager *other_mgr,int opts=0)
     110                :LoggerBase(opts), other_manager(other_mgr) {}
    111111
    112         void handle(const char *o, const char *m, const char *bl, int w)
     112        void handle(const char *o, const char *m, int w, const char *bl)
    113113        {
    114                 other_manager->send(o, m, bl, w);
     114                other_manager->send(o, m, w, bl);
    115115        }
    116116};
  • cpp/frams/loggers/loggertostdout.cpp

    r374 r375  
    33// See LICENSE.txt for details.
    44
    5 #include "stdouthandler.h"
     5#include "loggertostdout.h"
    66#ifdef SHP
    77#include <FBaseSys.h> //AppLog
     
    1010#endif
    1111
    12 void MessageHandlerToStdout::handle(const char *o, const char *m, const char *bl, int w)
     12void LoggerToStdout::handle(const char *o, const char *m, int w, const char *bl)
    1313{
    1414        if (w < -1) w = -1; else if (w>3) w = 3;
    1515#ifdef SHP
    16         AppLog(HMSG_FORMAT "\n",HMSG_LEVEL[w+1],o,m,bl);
     16        AppLog(LOG_FORMAT "\n",LOG_LEVEL[w+1],o,m,bl);
    1717#else
    1818        if (file)
    19                 file->printf(HMSG_FORMAT "\n", HMSG_LEVEL[w + 1], o, m, bl);
     19                file->printf(LOG_FORMAT "\n", LOG_LEVEL[w + 1], o, m, bl);
    2020        else
    21                 printf(HMSG_FORMAT "\n", HMSG_LEVEL[w + 1], o, m, bl);
     21                printf(LOG_FORMAT "\n", LOG_LEVEL[w + 1], o, m, bl);
    2222#endif
    2323}
  • cpp/frams/loggers/loggertostdout.h

    r374 r375  
    33// See LICENSE.txt for details.
    44
    5 #ifndef _STDOUTHANDLER_H_
    6 #define _STDOUTHANDLER_H_
     5#ifndef _STDOUT_LOGGER_H_
     6#define _STDOUT_LOGGER_H_
    77
    8 #include "mhandlers.h"
     8#include "loggers.h"
    99#include <frams/virtfile/virtfile.h>
    1010
    11 class MessageHandlerToStdout : public MessageHandlerBase
     11class LoggerToStdout : public LoggerBase
    1212{
    1313        VirtFILE *file;
    1414public:
    15         MessageHandlerToStdout(int opts = 0, VirtFILE *_file = NULL) :MessageHandlerBase(opts), file(_file) {}
    16         void handle(const char *o, const char *m, const char *bl, int w);
     15        LoggerToStdout(int opts = 0, VirtFILE *_file = NULL) :LoggerBase(opts), file(_file) {}
     16        void handle(const char *o, const char *m, int w, const char *bl);
    1717};
    1818
Note: See TracChangeset for help on using the changeset viewer.