Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <cstdio>
00029 #include "ros/file_log.h"
00030 #include "ros/this_node.h"
00031
00032 #include "log4cxx/rollingfileappender.h"
00033 #include "log4cxx/patternlayout.h"
00034 #include <ros/io.h>
00035 #include <ros/console.h>
00036
00037 #include <boost/filesystem.hpp>
00038
00039 #ifdef _MSC_VER
00040 #ifdef snprintf
00041 #undef snprintf
00042 #endif
00043 #define snprintf _snprintf_s
00044 #endif
00045
00046
00047 namespace fs = boost::filesystem;
00048
00049 namespace ros
00050 {
00051
00052 namespace file_log
00053 {
00054
00055 std::string g_log_directory;
00056 log4cxx::LoggerPtr g_file_only_logger;
00057
00058 const std::string& getLogDirectory()
00059 {
00060 return g_log_directory;
00061 }
00062
00063 void init(const M_string& remappings)
00064 {
00065 std::string log_file_name;
00066 M_string::const_iterator it = remappings.find("__log");
00067 if (it != remappings.end())
00068 {
00069 log_file_name = it->second;
00070 }
00071
00072 {
00073
00074
00075 if (log_file_name.empty())
00076 {
00077
00078
00079 pid_t pid = getpid();
00080 std::string ros_log_env;
00081 if ( get_environment_variable(ros_log_env, "ROS_LOG_DIR"))
00082 {
00083 log_file_name = ros_log_env + std::string("/");
00084 }
00085 else
00086 {
00087 if ( get_environment_variable(ros_log_env, "ROS_HOME"))
00088 {
00089 log_file_name = ros_log_env + std::string("/log/");
00090 }
00091 else
00092 {
00093
00094 if( get_environment_variable(ros_log_env, "HOME") )
00095 {
00096 std::string dotros = ros_log_env + std::string("/.ros/");
00097 fs::create_directory(dotros);
00098 log_file_name = dotros + "log/";
00099 fs::create_directory(log_file_name);
00100 }
00101 }
00102 }
00103
00104
00105 for (size_t i = 1; i < this_node::getName().length(); i++)
00106 {
00107 if (!isalnum(this_node::getName()[i]))
00108 {
00109 log_file_name += '_';
00110 }
00111 else
00112 {
00113 log_file_name += this_node::getName()[i];
00114 }
00115 }
00116
00117 char pid_str[100];
00118 snprintf(pid_str, sizeof(pid_str), "%d", pid);
00119 log_file_name += std::string("_") + std::string(pid_str) + std::string(".log");
00120 }
00121
00122 log_file_name = fs::system_complete(log_file_name).string();
00123 g_log_directory = fs::path(log_file_name).parent_path().string();
00124 }
00125 }
00126
00127 }
00128
00129 }
roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Mon Oct 6 2014 11:46:44