Changes have been pushed for the repository "fawkes.git".
(Fawkes Robotics Software Framework)

Clone:  g...@git.fawkesrobotics.org:fawkes.git
Gitweb: http://git.fawkesrobotics.org/fawkes.git
Trac:   http://trac.fawkesrobotics.org

The branch, thofmann/debug-log-symlink-latest has been created
        at  b1d5583397e661525f2604eedb18860471fec226 (commit)

http://git.fawkesrobotics.org/fawkes.git/thofmann/debug-log-symlink-latest

- *Log* ---------------------------------------------------------------
commit b1d5583397e661525f2604eedb18860471fec226
Author:     Till Hofmann <hofm...@kbsg.rwth-aachen.de>
AuthorDate: Fri Dec 15 12:58:59 2017 +0100
Commit:     Till Hofmann <hofm...@kbsg.rwth-aachen.de>
CommitDate: Fri Dec 15 12:58:59 2017 +0100

    logging: create a symlink for the latest log file
    
    If we use log files with timestamps, always create/update a symlink to
    the latest log file. The name of the symlink is the same as the log
    file, but the time replaced with "latest".

http://git.fawkesrobotics.org/fawkes.git/commit/b1d5583
http://trac.fawkesrobotics.org/changeset/b1d5583

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- *Summary* -----------------------------------------------------------


- *Diffs* -------------------------------------------------------------

- *commit* b1d5583397e661525f2604eedb18860471fec226 - - - - - - - - - -
Author:  Till Hofmann <hofm...@kbsg.rwth-aachen.de>
Date:    Fri Dec 15 12:58:59 2017 +0100
Subject: logging: create a symlink for the latest log file

 src/libs/logging/file.cpp |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

_Diff for modified files_:
diff --git a/src/libs/logging/file.cpp b/src/libs/logging/file.cpp
index 6d60896..23eca17 100644
--- a/src/libs/logging/file.cpp
+++ b/src/libs/logging/file.cpp
@@ -34,6 +34,7 @@
 #include <fcntl.h>
 #include <cerrno>
 #include <stdio.h>
+#include <unistd.h>
 
 #include <string>
 
@@ -83,6 +84,30 @@ FileLogger::FileLogger(const char* filename_pattern, 
LogLevel log_level)
   // make buffer line-buffered
   setvbuf(log_file, NULL, _IOLBF, 0);
 
+  // create a symlink for the latest log if the filename has a time stamp
+  if (pos != std::string::npos) {
+    std::string latest_filename(filename_pattern);
+    latest_filename.replace(pos, time_var.length(), "latest");
+    int link_res = symlink(filename, latest_filename.c_str());
+    if (link_res == -1) {
+      if (errno == EEXIST) {
+        int unlink_res = unlink(latest_filename.c_str());
+        if (unlink_res == -1) {
+          throw Exception(errno, "Failed to update symlink at %s",
+              latest_filename.c_str());
+        }
+        link_res = symlink(filename, latest_filename.c_str());
+        if (link_res == -1) {
+          throw Exception(errno, "Failed ot create symlink from %s to %s",
+              filename, latest_filename.c_str());
+        }
+      } else {
+          throw Exception(errno, "Failed ot create symlink from %s to %s",
+              filename, latest_filename.c_str());
+      }
+    }
+  }
+
   mutex = new Mutex();
 }
 




-- 
Fawkes Robotics Framework                 http://www.fawkesrobotics.org
_______________________________________________
fawkes-commits mailing list
fawkes-commits@lists.kbsg.rwth-aachen.de
https://lists.kbsg.rwth-aachen.de/listinfo/fawkes-commits

Reply via email to