Skip to content

Commit

Permalink
Merge pull request #7983 from liewegas/wip-14616
Browse files Browse the repository at this point in the history
log: do not repeat errors to stderr

Reviewed-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
liewegas committed Mar 11, 2016
2 parents c912454 + d9ac047 commit 4ab0fc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/log/Log.cc
Expand Up @@ -53,6 +53,7 @@ Log::Log(SubsystemMap *s)
m_fd(-1),
m_uid(0),
m_gid(0),
m_fd_last_error(0),
m_syslog_log(-2), m_syslog_crash(-2),
m_stderr_log(1), m_stderr_crash(-1),
m_graylog_log(-3), m_graylog_crash(-3),
Expand Down Expand Up @@ -337,9 +338,13 @@ void Log::_flush(EntryQueue *t, EntryQueue *requeue, bool crash)
if (do_fd) {
buf[buflen] = '\n';
int r = safe_write(m_fd, buf, buflen+1);
if (r < 0)
cerr << "problem writing to " << m_log_file << ": " << cpp_strerror(r)
<< std::endl;
if (r != m_fd_last_error) {
if (r < 0)
cerr << "problem writing to " << m_log_file
<< ": " << cpp_strerror(r)
<< std::endl;
m_fd_last_error = r;
}
}
if (need_dynamic)
delete[] buf;
Expand Down
2 changes: 2 additions & 0 deletions src/log/Log.h
Expand Up @@ -39,6 +39,8 @@ class Log : private Thread
uid_t m_uid;
gid_t m_gid;

int m_fd_last_error; ///< last error we say writing to fd (if any)

int m_syslog_log, m_syslog_crash;
int m_stderr_log, m_stderr_crash;
int m_graylog_log, m_graylog_crash;
Expand Down

0 comments on commit 4ab0fc5

Please sign in to comment.