SimpleJsonLogger.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5  * Karlsruhe Institute of Technology (KIT), all rights reserved.
6  *
7  * ArmarX is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * ArmarX is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu)
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #include "SimpleJsonLogger.h"
25 
26 namespace armarx
27 {
28  SimpleJsonLogger::SimpleJsonLogger(const std::string& filename, bool append)
29  : autoflush(true)
30  {
31  file.open(filename.c_str(), append ? std::ios_base::app : std::ios_base::out | std::ios_base::trunc);
32  }
33 
35  {
36  file << entry->toJsonString() << "\n";
37  if (autoflush)
38  {
39  file.flush();
40  }
41  }
42 
44  {
45  log(entry.obj);
46  }
47 
49  {
50  log(entry->obj);
51  }
52 
54  {
55  file.flush();
56  file.close();
57  }
58 
60  {
61  if (file.is_open())
62  {
63  file.close();
64  }
65  }
66 }
armarx::SimpleJsonLogger::~SimpleJsonLogger
~SimpleJsonLogger()
Definition: SimpleJsonLogger.cpp:59
SimpleJsonLogger.h
armarx::SimpleJsonLogger::close
void close()
Definition: SimpleJsonLogger.cpp:53
armarx::SimpleJsonLoggerEntry::obj
JsonObjectPtr obj
Definition: SimpleJsonLoggerEntry.h:59
filename
std::string filename
Definition: VisualizationRobot.cpp:84
armarx::SimpleJsonLogger::log
void log(JsonDataPtr entry)
Definition: SimpleJsonLogger.cpp:34
armarx::SimpleJsonLoggerEntryPtr
std::shared_ptr< SimpleJsonLoggerEntry > SimpleJsonLoggerEntryPtr
Definition: SimpleJsonLoggerEntry.h:33
armarx::JsonDataPtr
std::shared_ptr< JsonData > JsonDataPtr
Definition: JsonData.h:31
armarx::SimpleJsonLoggerEntry
Definition: SimpleJsonLoggerEntry.h:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::SimpleJsonLogger::SimpleJsonLogger
SimpleJsonLogger(const std::string &filename, bool append)
Definition: SimpleJsonLogger.cpp:28