1 /*
2  *  logging_event.cpp
3  *
4  *  This file is part of NEST.
5  *
6  *  Copyright (C) 2004 The NEST Initiative
7  *
8  *  NEST is free software: you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation, either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  NEST is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #include "logging_event.h"
24 
25 // C++ includes:
26 #include <cassert>
27 #include <ctime>
28 
LoggingEvent(const nest::severity_t s,const std::string & fctn,const std::string & msg,const std::string & file,const size_t line)29 nest::LoggingEvent::LoggingEvent( const nest::severity_t s,
30   const std::string& fctn,
31   const std::string& msg,
32   const std::string& file,
33   const size_t line )
34   : message( msg )
35   , function( fctn )
36   , severity( s )
37   , time_stamp( 0 )
38   , file_name( file )
39   , line_number( line )
40 {
41   assert( severity > M_ALL );
42   assert( severity < M_QUIET );
43   time( const_cast< time_t* >( &time_stamp ) );
44 }
45 
46 namespace nest
47 {
48 
operator <<(std::ostream & out,const LoggingEvent & e)49 std::ostream& operator<<( std::ostream& out, const LoggingEvent& e )
50 {
51   struct tm* ptm = localtime( &e.time_stamp );
52   switch ( e.severity )
53   {
54   case M_ALL:
55     out << "[ALL] ";
56     break;
57   case M_DEBUG:
58     out << "[DEBUG] ";
59     break;
60   case M_STATUS:
61     out << "[STATUS] ";
62     break;
63   case M_INFO:
64     out << "[INFO] ";
65     break;
66   case M_PROGRESS:
67     out << "[PROGRESS] ";
68     break;
69   case M_DEPRECATED:
70     out << "[DEPRECATED] ";
71     break;
72   case M_WARNING:
73     out << "[WARNING] ";
74     break;
75   case M_ERROR:
76     out << "[ERROR] ";
77     break;
78   case M_FATAL:
79     out << "[FATAL] ";
80     break;
81   case M_QUIET:
82     out << "[QUIET] ";
83     break;
84   default:
85     out << "[" << e.severity << "] ";
86     break;
87   }
88   // print time and day
89   out << "[" << ptm->tm_year + 1900 << "." << ptm->tm_mon + 1 << "." << ptm->tm_mday << " " << ptm->tm_hour << ":"
90       << ptm->tm_min << ":" << ptm->tm_sec << " ";
91 
92   out << e.file_name << ":" << e.line_number << " @ " << e.function << "] : " << e.message;
93 
94   return out;
95 }
96 }
97