~vbursian/research-assistant/intervers

« back to all changes in this revision

Viewing changes to RANet/Log.cpp

  • Committer: Viktor Bursian
  • Date: 2013-06-06 15:10:08 UTC
  • Revision ID: vbursian@gmail.com-20130606151008-6641eh62f0lgx8jt
Tags: version_0.3.0
version 0.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
/*! @file Log.cpp   Собирает структурированную трассировочную информацию.
 
3
- Part of RANet - Research Assistant Net Library (based on ANSI C++).
 
4
- Copyright(C) 2011, Viktor E. Bursian, St.Petersburg, Russia.
 
5
                     Viktor.Bursian@mail.ioffe.ru
 
6
*///////////////////////////////////////////////////////////////////////////////
 
7
#include "Log.h"
 
8
#include <iostream>
 
9
namespace RA {
 
10
//------------------------------------------------------------------------------
 
11
 
 
12
namespace RANet {
 
13
 
 
14
sLog                          Log;
 
15
 
 
16
};
 
17
 
 
18
//--------------------------------------------------------------- sLog::sItem---
 
19
 
 
20
sLog::sItem::sItem (psItem    parent
 
21
                   ,unsigned int  level
 
22
                   ,eSeverity severity
 
23
                   ,sString   topic
 
24
                   ,sString   message )
 
25
    :TheTime()
 
26
    ,TheSeverity(severity)
 
27
    ,TheTopic(topic)
 
28
    ,TheMessage(message)
 
29
    ,TheLevel(level)
 
30
    ,TheParent(parent)
 
31
{
 
32
 
 
33
};
 
34
 
 
35
 
 
36
sString  sLog::sItem::Text () const
 
37
{
 
38
  sString                     T;
 
39
  T += TheTime.Text();
 
40
  T += "  ";
 
41
//  T << TheSeverity;
 
42
//  T += " \t";
 
43
  T += TheTopic;
 
44
  T += " \t";
 
45
  T += TheMessage;
 
46
  return T;
 
47
};
 
48
 
 
49
//---------------------------------------------------------------------- sLog---
 
50
 
 
51
sLog::~sLog()
 
52
{
 
53
  Items.clear();
 
54
};
 
55
 
 
56
 
 
57
sLog::sLog()
 
58
    :CurrentBlock(NULL)
 
59
    ,CurrentLevel(0)
 
60
    ,TheShowSeverity(Admin)
 
61
{
 
62
};
 
63
 
 
64
 
 
65
void  sLog::Put (eSeverity  severity
 
66
                ,sString    topic
 
67
                ,sString    message )
 
68
{
 
69
  #ifndef RANET_DEBUG
 
70
    if( severity <= Debug )
 
71
      return;
 
72
  #endif
 
73
  psItem                      I( new sItem(CurrentBlock
 
74
                                          ,CurrentLevel
 
75
                                          ,severity
 
76
                                          ,topic
 
77
                                          ,message ) );
 
78
  if(    (  (severity >= TheShowSeverity)
 
79
         && (TopicsToHide.count(topic) == 0) )
 
80
      || (TopicsToShow.count(topic) != 0) ){
 
81
    for( unsigned int i = 0 ; i < I->Level() ; i++)  std::cout << "\t";
 
82
    std::cout << (literal)(I->Text()) << std::endl;
 
83
  };
 
84
  delete I;
 
85
};
 
86
 
 
87
 
 
88
void  sLog::OpenBlock (eSeverity  severity
 
89
                      ,sString    topic
 
90
                      ,sString    message )
 
91
{
 
92
  #ifndef RANET_DEBUG
 
93
    if( severity <= Debug )
 
94
      return;
 
95
  #endif
 
96
  Put(severity,topic,message);
 
97
  CurrentLevel++;
 
98
};
 
99
 
 
100
 
 
101
void  sLog::OpenBlock (eSeverity  severity
 
102
                      ,sString    topic   )
 
103
{
 
104
  OpenBlock(severity,topic,"started");
 
105
};
 
106
 
 
107
 
 
108
void  sLog::CloseBlock (eSeverity  severity
 
109
                       ,sString    topic)
 
110
{
 
111
  #ifndef RANET_DEBUG
 
112
    if( severity <= Debug )
 
113
      return;
 
114
  #endif
 
115
//  if( ! CurrentBlock || (severity != CurrentBlock->TheSeverity)
 
116
//                     || (topic != CurrentBlock->TheTopic)       ){
 
117
//    Put(,,"");
 
118
//  };
 
119
  #ifdef RANET_DEBUG
 
120
    Put(severity,topic,"finished"); //  duration=   total=");
 
121
  #endif
 
122
  CurrentLevel--;
 
123
};
 
124
 
 
125
 
 
126
void  sLog::SetShowSeverity (eSeverity  severity)
 
127
{
 
128
  TheShowSeverity = severity;
 
129
};
 
130
 
 
131
 
 
132
void  sLog::AlwaysHide (sString  topic)
 
133
{
 
134
  TopicsToHide.insert(topic);
 
135
  TopicsToShow.erase(topic);
 
136
};
 
137
 
 
138
 
 
139
void  sLog::AlwaysShow (sString  topic)
 
140
{
 
141
  TopicsToShow.insert(topic);
 
142
  TopicsToHide.erase(topic);
 
143
};
 
144
 
 
145
//------------------------------------------------------------------------------
 
146
}; //namespace RA
 
147
 
 
148