Version: 9.16.0
Logger.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#include "Logger.hxx"
21#include "LogRecord.hxx"
22
23#include <iostream>
24
25//#define _DEVDEBUG_
26#include "YacsTrace.hxx"
27
28using namespace YACS::ENGINE;
29
30Logger::Logger(const std::string& name):_name(name)
31{
32}
33
35{
36 reset();
37}
38
39const std::string& Logger::getName()
40{
41 return _name;
42}
43
44void Logger::log(int level,const std::string& message,const char* filename,int line)
45{
46 LogRecord* record=makeRecord(getName(),level,message,filename,line);
47 handle(record);
48}
49
50void Logger::error(const std::string& message,const char* filename,int line)
51{
52 log(LogRecord::ERROR,message,filename,line);
53}
54
55void Logger::fatal(const std::string& message,const char* filename,int line)
56{
57 log(LogRecord::FATAL,message,filename,line);
58}
59
60void Logger::warning(const std::string& message,const char* filename,int line)
61{
62 log(LogRecord::WARNING,message,filename,line);
63}
64
65LogRecord* Logger::makeRecord(const std::string& name,int level,const std::string& message,const char* filename,int line)
66{
67 return new LogRecord(name,level,message,filename,line);
68}
69
71{
72 _records.push_back(record);
73}
74
76{
77 std::vector<LogRecord*>::iterator it;
78 for( it = _records.begin(); it != _records.end(); it++)
79 {
80 delete (*it);
81 }
82 _records.clear();
83}
84
85std::string Logger::getStr()
86{
87 std::vector<LogRecord*>::iterator it;
88 std::string msg;
89 for( it = _records.begin(); it != _records.end(); it++)
90 {
91 msg=msg + (*it)->getStr() + '\n';
92 }
93 return msg;
94}
95
97{
98 return _records.size() == 0;
99}
100
102{
103 bool ret=false;
104 std::vector<LogRecord*>::iterator it;
105 for( it = _records.begin(); it != _records.end(); it++)
106 {
107 if((*it)->_level > LogRecord::WARNING)
108 {
109 ret=true;
110 break;
111 }
112 }
113 return ret;
114}
Class for logging record.
Definition: LogRecord.hxx:33
static const LogLevel FATAL
Definition: LogRecord.hxx:36
static const LogLevel WARNING
Definition: LogRecord.hxx:38
static const LogLevel ERROR
Definition: LogRecord.hxx:37
virtual void error(const std::string &message, const char *filename, int line)
Definition: Logger.cxx:50
virtual bool hasErrors()
Definition: Logger.cxx:101
std::vector< LogRecord * > _records
Definition: Logger.hxx:55
virtual void handle(LogRecord *record)
Definition: Logger.cxx:70
virtual void reset()
Definition: Logger.cxx:75
virtual bool isEmpty()
Definition: Logger.cxx:96
std::string _name
Definition: Logger.hxx:54
virtual const std::string & getName()
Definition: Logger.cxx:39
virtual std::string getStr()
Definition: Logger.cxx:85
virtual LogRecord * makeRecord(const std::string &name, int level, const std::string &message, const char *filename, int line)
Definition: Logger.cxx:65
virtual ~Logger()
Definition: Logger.cxx:34
virtual void fatal(const std::string &message, const char *filename, int line)
Definition: Logger.cxx:55
virtual void warning(const std::string &message, const char *filename, int line)
Definition: Logger.cxx:60
virtual void log(int level, const std::string &message, const char *filename, int line)
Definition: Logger.cxx:44