[X2Go-Commits] [nx-libs] 03/06: nxcomp/src/Log.{cpp, h}: provide infrastructure for appending to already existing log lines.
git-admin at x2go.org
git-admin at x2go.org
Mon Dec 25 02:25:42 CET 2017
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch 3.6.x-rpm-debug
in repository nx-libs.
commit 7c36d20c40ac730de1a764cc718373fb4a0af68b
Author: Mihai Moldovan <ionic at ionic.de>
Date: Sun Dec 24 22:16:38 2017 +0100
nxcomp/src/Log.{cpp,h}: provide infrastructure for appending to already existing log lines.
---
nxcomp/src/Log.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++--------
nxcomp/src/Log.h | 16 ++++++++++++++--
2 files changed, 59 insertions(+), 10 deletions(-)
diff --git a/nxcomp/src/Log.cpp b/nxcomp/src/Log.cpp
index 24f6605..05de09e 100644
--- a/nxcomp/src/Log.cpp
+++ b/nxcomp/src/Log.cpp
@@ -106,16 +106,53 @@ std::string NXLog::stamp_to_string(const NXLogStamp& stamp) const
NXLog& operator<< (NXLog& out, const NXLogStamp& value)
{
- out.current_level( value.level() );
- out.current_file( value.file() );
+ /*
+ * If appending, the file and function names must be empty and
+ * the line set to zero.
+ */
+ const bool looks_like_append = ((value.file().empty()) || (value.function().empty()) || (0 == value.line()));
+ const bool append = ((looks_like_append) && ((value.file().empty()) && (value.function().empty()) && (0 == value.line())));
+
+ if ((looks_like_append) && (!append))
+ {
+ std::cerr << "WARNING: At least one element in logstamp invalid, but this is not supposed to be an append operation."
+ << "Internal state error!\n" << "Log line will be discarded!" << std::endl;
+ }
+ else if (append)
+ {
+ /* Appending means that the log object's internal level and the message level must match. */
+ if (out.current_level() == value.level())
+ {
+ /* And the buffer must of course be non-empty. */
+ if (out.has_buffer())
+ {
+ out << "(cont.) ";
+ }
+ else
+ {
+ std::cerr << "WARNING: Append operation requested, but no queued data available."
+ << "Internal state error!\n" << "Log line will be discarded!" << std::endl;
+ }
+ }
+ else
+ {
+ std::cerr << "WARNING: Append operation requested, but internal log level not matching line level."
+ << "Internal state error!\n" << "Log line will be discarded!" << std::endl;
+ }
+ }
+ else
+ {
+ out.current_level( value.level() );
+ out.current_file( value.file() );
- // Writing an NXLogStamp to the stream indicates the start of a new entry.
- // If there's any content in the buffer and we actually intend to keep that line,
- // create a new entry in the output queue.
- if ( out.synchronized() && out.will_log() )
- out.new_stack_entry();
+ // Writing an NXLogStamp to the stream indicates the start of a new entry.
+ // If there's any content in the buffer and we actually intend to keep that line,
+ // create a new entry in the output queue.
+ if ( out.synchronized() && out.will_log() )
+ out.new_stack_entry();
- out << out.stamp_to_string(value);
+ out << out.stamp_to_string(value);
+ }
return out;
}
diff --git a/nxcomp/src/Log.h b/nxcomp/src/Log.h
index 6c4370c..a9410f2 100644
--- a/nxcomp/src/Log.h
+++ b/nxcomp/src/Log.h
@@ -105,7 +105,7 @@ class NXLogStamp
}
- NXLogStamp(const char *file, const char *function, size_t line, NXLogLevel level) : file_(file), function_(function), line_(line), level_(level)
+ NXLogStamp(const char *file = NULL, const char *function = NULL, size_t line = 0, NXLogLevel level) : file_(file), function_(function), line_(line), level_(level)
{
gettimeofday(×tamp_, NULL);
}
@@ -432,6 +432,11 @@ class NXLog
*/
bool will_log() const;
+ bool has_buffer() const
+ {
+ return (!(get_data()->buffer.empty ()));
+ }
+
/**
* This catches std::flush
@@ -466,7 +471,8 @@ class NXLog
extern NXLog nx_log;
-#define nxstamp(l) NXLogStamp(__FILE__, __func__, __LINE__, l)
+#define nxstamp(l) NXLogStamp(__FILE__, __func__, __LINE__, l)
+#define nxstamp_append(l) NXLogStamp(l)
#define nxdbg nx_log << nxstamp(NXDEBUG)
@@ -475,6 +481,12 @@ extern NXLog nx_log;
#define nxerr nx_log << nxstamp(NXERROR)
#define nxfatal nx_log << nxstamp(NXFATAL)
+/* Append data to already existing (i.e., same-level) line. */
+#define nxdbg_append nx_log << nxstamp_append(NXDEBUG)
+#define nxinfo_append nx_log << nxstamp_append(NXINFO)
+#define nxwarn_append nx_log << nxstamp_append(NXWARNING)
+#define nxerr_append nx_log << nxstamp_append(NXERROR)
+#define nxfatal_append nx_log << nxstamp_append(NXFATAL)
NXLog& operator<< (NXLog& out, const NXLogStamp& value);
--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/nx-libs.git
More information about the x2go-commits
mailing list