Skip to content

Commit

Permalink
logging: change default loglevel
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilledheart committed Oct 21, 2024
1 parent 1c1e7ed commit 629995d
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/core/check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class CheckError {
LogMessage* log_message_;
};

#if defined(OFFICIAL_BUILD) && defined(NDEBUG)
#if defined(OFFICIAL_BUILD) && !DCHECK_IS_ON()

// Discard log strings to reduce code bloat.
//
Expand Down
16 changes: 3 additions & 13 deletions src/core/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,6 @@ typedef FILE* FileHandle;
#include <absl/strings/str_split.h>
#include <absl/synchronization/mutex.h>

#if !defined(NDEBUG) || defined(_DEBUG)
#define DEFAULT_LOGBUFLEVEL -1
#define DEFAULT_VERBOSE_LEVEL 1
#define DEFAULT_LOGSTDERRTHRESHOLD LOGGING_WARNING
#else
#define DEFAULT_LOGBUFLEVEL 0
#define DEFAULT_VERBOSE_LEVEL 0
#define DEFAULT_LOGSTDERRTHRESHOLD LOGGING_ERROR
#endif

namespace {
// simple init once flag
std::atomic<bool> g_log_init;
Expand Down Expand Up @@ -302,7 +292,7 @@ ABSL_FLAG(bool,
// when they run a program without having to look in another file.
ABSL_FLAG(int32_t,
stderrthreshold,
DEFAULT_LOGSTDERRTHRESHOLD,
LOGGING_ERROR,
"log messages at or above this level are copied to stderr in "
"addition to logfiles. This flag obsoletes --alsologtostderr.");
ABSL_FLAG(int32_t,
Expand All @@ -312,7 +302,7 @@ ABSL_FLAG(int32_t,
"actually get logged anywhere");
ABSL_FLAG(int32_t,
logbuflevel,
DEFAULT_LOGBUFLEVEL,
0,
"Buffer log messages logged at this level or lower"
" (-1 means don't buffer; 0 means buffer INFO only;"
" ...)");
Expand Down Expand Up @@ -355,7 +345,7 @@ ABSL_FLAG(bool, stop_logging_if_full_disk, false, "Stop attempting to log to dis

ABSL_FLAG(std::string, log_backtrace_at, "", "Emit a backtrace when logging at file:linenum.");

ABSL_FLAG(int32_t, v, DEFAULT_VERBOSE_LEVEL, "verboselevel");
ABSL_FLAG(int32_t, v, 0, "verboselevel");

ABSL_FLAG(std::string,
vmodule,
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/aead_evp_decrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// In debug builds only, log OpenSSL error stack. Then clear OpenSSL error
// stack.
static void DLogOpenSslErrors() {
#ifdef NDEBUG
#if !DCHECK_IS_ON()
ERR_clear_error();
#else
while (uint32_t error = ERR_get_error()) {
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/aead_evp_encrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// In debug builds only, log OpenSSL error stack. Then clear OpenSSL error
// stack.
static void DLogOpenSslErrors() {
#ifdef NDEBUG
#if !DCHECK_IS_ON()
ERR_clear_error();
#else
while (uint32_t error = ERR_get_error()) {
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/aead_sodium_decrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// In debug builds only, log OpenSSL error stack. Then clear OpenSSL error
// stack.
static void DLogOpenSslErrors() {
#ifdef NDEBUG
#if !DCHECK_IS_ON()
ERR_clear_error();
#else
while (uint32_t error = ERR_get_error()) {
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/aead_sodium_encrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// In debug builds only, log OpenSSL error stack. Then clear OpenSSL error
// stack.
static void DLogOpenSslErrors() {
#ifdef NDEBUG
#if !DCHECK_IS_ON()
ERR_clear_error();
#else
while (uint32_t error = ERR_get_error()) {
Expand Down
14 changes: 0 additions & 14 deletions src/net/cipher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ cipher::cipher(const std::string& key,
key_len_ = !key.empty() ? cipher_impl::parse_key(key, key_, key_bitlen_ / 8)
: cipher_impl::derive_key(password, key_, key_bitlen_ / 8);

#ifndef NDEBUG
DumpHex("cipher: KEY", key_, key_len_);
#endif

tag_len_ = impl_->GetTagSize();
}
Expand Down Expand Up @@ -283,9 +281,7 @@ void cipher::decrypt_salt(IOBuf* chunk) {
chunk->trimStart(nonce_len);
chunk->retreat(nonce_len);
set_key_stream(nonce, nonce_len);
#ifndef NDEBUG
DumpHex("DE-NONCE", nonce, nonce_len);
#endif
return;
}
#endif
Expand All @@ -298,9 +294,7 @@ void cipher::decrypt_salt(IOBuf* chunk) {
chunk->retreat(salt_len);
set_key_aead(salt_, salt_len);

#ifndef NDEBUG
DumpHex("DE-SALT", salt_, salt_len);
#endif
}

void cipher::encrypt_salt(IOBuf* chunk) {
Expand All @@ -316,9 +310,7 @@ void cipher::encrypt_salt(IOBuf* chunk) {
chunk->prepend(nonce_len);
memcpy(chunk->mutable_data(), nonce, nonce_len);
set_key_stream(nonce, nonce_len);
#ifndef NDEBUG
DumpHex("EN-NONCE", nonce, nonce_len);
#endif
return;
}
#endif
Expand All @@ -331,9 +323,7 @@ void cipher::encrypt_salt(IOBuf* chunk) {
memcpy(chunk->mutable_data(), salt_, salt_len);
set_key_aead(salt_, salt_len);

#ifndef NDEBUG
DumpHex("EN-SALT", salt_, salt_len);
#endif
}

int cipher::chunk_decrypt_frame(uint64_t* counter, IOBuf* plaintext, IOBuf* ciphertext) const {
Expand Down Expand Up @@ -539,10 +529,8 @@ void cipher::set_key_stream(const uint8_t* nonce, size_t nonce_len) {
LOG(WARNING) << "SetKey Failed";
}

#ifndef NDEBUG
DumpHex("KEY", impl_->GetKey(), impl_->GetKeySize());
DumpHex("IV", impl_->GetIV(), impl_->GetIVSize());
#endif
}

void cipher::set_key_aead(const uint8_t* salt, size_t salt_len) {
Expand All @@ -565,10 +553,8 @@ void cipher::set_key_aead(const uint8_t* salt, size_t salt_len) {
LOG(WARNING) << "SetNoncePrefix Failed";
}

#ifndef NDEBUG
DumpHex("SKEY", impl_->GetKey(), impl_->GetKeySize());
DumpHex("NONCE_PREFIX", impl_->GetNoncePrefix(), impl_->GetNoncePrefixSize());
#endif
}

} // namespace net
6 changes: 3 additions & 3 deletions src/net/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ NextProto NextProtoFromString(std::string_view proto_string);

std::string_view NextProtoToString(NextProto next_proto);

#ifndef NDEBUG
#if DCHECK_IS_ON()
inline void DumpHex_Impl(const char* file, int line, const char* prefix, const uint8_t* data, uint32_t length) {
if (!VLOG_IS_ON(4)) {
return;
Expand Down Expand Up @@ -90,11 +90,11 @@ inline void DumpHex_Impl(const char* file, int line, const char* prefix, const n
uint32_t length = buf->length();
DumpHex_Impl(file, line, prefix, data, length);
}
#endif // NDEBUG
#endif // DCHECK_IS_ON()

} // namespace net

#ifndef NDEBUG
#if DCHECK_IS_ON()
#define DumpHex(...) ::net::DumpHex_Impl(__FILE__, __LINE__, __VA_ARGS__)
#else
#define DumpHex(...)
Expand Down
2 changes: 1 addition & 1 deletion src/net/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ class stream : public RefCountedThreadSafe<stream> {
if (ec) {
VLOG(2) << "data transfer failed with " << endpoint_ << " due to " << ec << " stats: readed "
<< rbytes_transferred_ << " written: " << wbytes_transferred_;
#ifndef NDEBUG
#if DCHECK_IS_ON()
const char* file;
int line;
while (uint32_t error = ERR_get_error_line(&file, &line)) {
Expand Down

0 comments on commit 629995d

Please sign in to comment.