fw4spl
ScopedMessage.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include <sstream>
8 
9 #include "fwCore/log/SpyLogger.hpp"
10 #include "fwCore/log/ScopedMessage.hpp"
11 
12 namespace fwCore
13 {
14 namespace log
15 {
16 
17 // Msg Format :
18 // [ENTERING SCOPE] "Timed{'file':m_file, 'line':m_line, 'entermessage':enterMessage}"
19 // [LEAVING SCOPE] "Timed{'file':m_file, 'line':m_line, 'leavemessage':m_leave, 'elapsed':elapsedTime}"
20 
21 //-----------------------------------------------------------------------------
22 
23 ScopedMessage::ScopedMessage( const char * _file, int _line, std::string enterMessage, std::string leaveMessage)
24  : m_file(_file), m_line(_line), m_leave(leaveMessage.empty() ? enterMessage : leaveMessage)
25 {
26  std::stringstream base;
27  base << "Timed{'file':'"<< m_file <<"','line':"<< m_line <<",";
28  m_baseMsg = base.str();
29 
30  std::stringstream oslStr;
31  oslStr << "[ENTERING SCOPE] "<< m_baseMsg << "'entermessage':'" << enterMessage << "'}";
32  ::fwCore::log::SpyLogger::getSpyLogger().trace(oslStr.str(), m_file, m_line);
33  m_timer.start();
34 }
35 
36 //-----------------------------------------------------------------------------
37 
38 ScopedMessage::~ScopedMessage()
39 {
40  std::stringstream oslStr;
41  oslStr << "[LEAVING SCOPE] "<< m_baseMsg << "'leavemessage':'" << m_leave <<"','elapsed':"<<
42  m_timer.getElapsedTimeInMilliSec() << "}";
43  SpyLogger::getSpyLogger().trace(oslStr.str(), m_file, m_line);
44 }
45 
46 } // namespace log
47 } // namespace fwCore
48 
This namespace fwCore provides common foundations for FW4SPL.
Definition: BaseObject.hpp:16