aboutsummaryrefslogtreecommitdiff
path: root/src/logging.cpp
diff options
context:
space:
mode:
authorJim Posen <jimpo@coinbase.com>2018-04-20 01:11:44 -0700
committerJim Posen <jimpo@coinbase.com>2018-04-29 14:37:19 -0700
commit8c2d695c4a45bdd9378c7970b0fcba6e1efc01f9 (patch)
tree43b04976c81df286c18c22e67d077bed78fcd087 /src/logging.cpp
parent8e7b961388920144993d0bd56d93f89e5c60fbff (diff)
downloadbitcoin-8c2d695c4a45bdd9378c7970b0fcba6e1efc01f9.tar.xz
util: Store debug log file path in BCLog::Logger member.
This breaks the cyclic between logging and util.
Diffstat (limited to 'src/logging.cpp')
-rw-r--r--src/logging.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/logging.cpp b/src/logging.cpp
index b7c682c94f..10a3b18958 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -4,7 +4,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <logging.h>
-#include <util.h>
+#include <utiltime.h>
const char * const DEFAULT_DEBUGLOGFILE = "debug.log";
@@ -30,20 +30,14 @@ static int FileWriteStr(const std::string &str, FILE *fp)
return fwrite(str.data(), 1, str.size(), fp);
}
-fs::path BCLog::Logger::GetDebugLogPath() const
-{
- fs::path logfile(gArgs.GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE));
- return AbsPathForConfigVal(logfile);
-}
-
bool BCLog::Logger::OpenDebugLog()
{
std::lock_guard<std::mutex> scoped_lock(m_file_mutex);
assert(m_fileout == nullptr);
- fs::path pathDebug = GetDebugLogPath();
+ assert(!m_file_path.empty());
- m_fileout = fsbridge::fopen(pathDebug, "a");
+ m_fileout = fsbridge::fopen(m_file_path, "a");
if (!m_fileout) {
return false;
}
@@ -228,8 +222,7 @@ int BCLog::Logger::LogPrintStr(const std::string &str)
// reopen the log file, if requested
if (m_reopen_file) {
m_reopen_file = false;
- fs::path pathDebug = GetDebugLogPath();
- if (fsbridge::freopen(pathDebug,"a",m_fileout) != nullptr)
+ if (fsbridge::freopen(m_file_path,"a",m_fileout) != nullptr)
setbuf(m_fileout, nullptr); // unbuffered
}
@@ -243,14 +236,16 @@ void BCLog::Logger::ShrinkDebugFile()
{
// Amount of debug.log to save at end when shrinking (must fit in memory)
constexpr size_t RECENT_DEBUG_HISTORY_SIZE = 10 * 1000000;
+
+ assert(!m_file_path.empty());
+
// Scroll debug.log if it's getting too big
- fs::path pathLog = GetDebugLogPath();
- FILE* file = fsbridge::fopen(pathLog, "r");
+ FILE* file = fsbridge::fopen(m_file_path, "r");
// Special files (e.g. device nodes) may not have a size.
size_t log_size = 0;
try {
- log_size = fs::file_size(pathLog);
+ log_size = fs::file_size(m_file_path);
} catch (boost::filesystem::filesystem_error &) {}
// If debug.log file is more than 10% bigger the RECENT_DEBUG_HISTORY_SIZE
@@ -263,7 +258,7 @@ void BCLog::Logger::ShrinkDebugFile()
int nBytes = fread(vch.data(), 1, vch.size(), file);
fclose(file);
- file = fsbridge::fopen(pathLog, "w");
+ file = fsbridge::fopen(m_file_path, "w");
if (file)
{
fwrite(vch.data(), 1, nBytes, file);