Salome HOME
02cb844957d84790ef12994b229cbacf0a0098c1
[modules/yacs.git] / src / engine / LogRecord.cxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
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.
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 #include "LogRecord.hxx"
20
21 #include <sstream>
22 #include <iostream>
23
24 //#define _DEVDEBUG_
25 #include "YacsTrace.hxx"
26
27 using namespace YACS::ENGINE;
28
29 LogRecord::LogRecord(const std::string& name,int level,const std::string& message, const char* file, int line)
30         :_loggerName(name),_level(level),_message(message),_fileName((char*)file),_line(line)
31 {
32 }
33
34 LogRecord::~LogRecord()
35 {
36 }
37
38 std::string LogRecord::getLevelName(int level)
39 {
40   switch(level)
41     {
42     case FATAL:
43       return "FATAL";
44     case ERROR:
45       return "ERROR";
46     case WARNING:
47       return "WARNING";
48     case INFO:
49       return "INFO";
50     case DEBUG:
51       return "DEBUG";
52     default:
53       return "NOTSET";
54     }
55 }
56
57 std::string LogRecord::getStr()
58 {
59   std::stringstream msg;
60   msg << "LogRecord: " << _loggerName << ":" << getLevelName(_level) << ":" << _message;
61   if(_fileName != "")
62     msg << " (" << _fileName << ":" << _line << ")";
63   return msg.str();
64 }
65