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 <ros/io.h>
00033 #include <ros/console.h>
00034
00035 #include <boost/filesystem.hpp>
00036
00037 #ifdef _MSC_VER
00038 #ifdef snprintf
00039 #undef snprintf
00040 #endif
00041 #define snprintf _snprintf_s
00042 #endif
00043
00044
00045 namespace fs = boost::filesystem;
00046
00047 namespace ros
00048 {
00049
00050 namespace file_log
00051 {
00052
00053 std::string g_log_directory;
00054
00055 const std::string& getLogDirectory()
00056 {
00057 return g_log_directory;
00058 }
00059
00060 void init(const M_string& remappings)
00061 {
00062 std::string log_file_name;
00063 M_string::const_iterator it = remappings.find("__log");
00064 if (it != remappings.end())
00065 {
00066 log_file_name = it->second;
00067 }
00068
00069 {
00070
00071
00072 if (log_file_name.empty())
00073 {
00074
00075
00076 pid_t pid = getpid();
00077 std::string ros_log_env;
00078 if ( get_environment_variable(ros_log_env, "ROS_LOG_DIR"))
00079 {
00080 log_file_name = ros_log_env + std::string("/");
00081 }
00082 else
00083 {
00084 if ( get_environment_variable(ros_log_env, "ROS_HOME"))
00085 {
00086 log_file_name = ros_log_env + std::string("/log/");
00087 }
00088 else
00089 {
00090
00091 if( get_environment_variable(ros_log_env, "HOME") )
00092 {
00093 std::string dotros = ros_log_env + std::string("/.ros/");
00094 fs::create_directory(dotros);
00095 log_file_name = dotros + "log/";
00096 fs::create_directory(log_file_name);
00097 }
00098 }
00099 }
00100
00101
00102 for (size_t i = 1; i < this_node::getName().length(); i++)
00103 {
00104 if (!isalnum(this_node::getName()[i]))
00105 {
00106 log_file_name += '_';
00107 }
00108 else
00109 {
00110 log_file_name += this_node::getName()[i];
00111 }
00112 }
00113
00114 char pid_str[100];
00115 snprintf(pid_str, sizeof(pid_str), "%d", pid);
00116 log_file_name += std::string("_") + std::string(pid_str) + std::string(".log");
00117 }
00118
00119 log_file_name = fs::system_complete(log_file_name).string();
00120 g_log_directory = fs::path(log_file_name).parent_path().string();
00121 }
00122 }
00123
00124 }
00125
00126 }
roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Thu Jun 6 2019 21:10:05