fw4spl
initialisation.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 <fwCore/log/SpyLogger.hpp>
8 
9 #include <boost/filesystem.hpp>
10 
11 #include <ostream>
12 #include <cstdio>
13 
14 namespace fwTest
15 {
16 
17 
19 {
21  {
22  fwCore::log::SpyLogger &logger = fwCore::log::SpyLogger::getSpyLogger();
23 
24  std::string logFile = "fwTest.log";
25 
26  FILE * pFile = fopen(logFile.c_str(), "w");
27  if (pFile==NULL)
28  {
29  ::boost::system::error_code err;
30  ::boost::filesystem::path sysTmp = ::boost::filesystem::temp_directory_path(err);
31  if(err.value() != 0)
32  {
33  // replace log file appender by stream appender: default dir and temp dir unreachable
34  logger.addStreamAppender();
35  }
36  else
37  {
38  // creates SLM.log in temp directory: default dir unreachable
39  sysTmp = sysTmp / logFile;
40  logFile = sysTmp.string();
41  logger.addFileAppender(logFile);
42  }
43  }
44  else
45  {
46  // creates SLM.log in default logFile directory
47  fclose(pFile);
48  logger.addFileAppender(logFile);
49  }
50  }
51 
52 };
53 
54 static LogInitialization init;
55 
56 } //namespace fwTest
57 
Implements the SpyLogger.
Definition: SpyLogger.hpp:27
Definition: Data.hpp:15