Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize log line prefix generation based on display criteria (#1068) #1069

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion agent/native/ext/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,13 @@ void vLogWithLoggerImpl(
};
char commonPrefixBuffer[commonPrefixBufferSize];

StringView commonPrefix = buildCommonPrefix( statementLevel, category, filePath, lineNumber, funcName, commonPrefixBuffer, commonPrefixBufferSize );
StringView commonPrefix = {nullptr, 0};

if ( isForced || logger->config.levelPerSinkType[ logSink_stderr ] >= statementLevel )
{
if (commonPrefix.begin == nullptr) {
commonPrefix = buildCommonPrefix( statementLevel, category, filePath, lineNumber, funcName, commonPrefixBuffer, commonPrefixBufferSize );
}
// create a separate copy of va_list because functions using it (such as fprintf, etc.) modify it
va_list msgPrintfFmtArgsCopy;
va_copy( /* dst: */ msgPrintfFmtArgsCopy, /* src: */ msgPrintfFmtArgs );
Expand All @@ -563,6 +566,9 @@ void vLogWithLoggerImpl(
#ifndef PHP_WIN32
if ( isForced || logger->config.levelPerSinkType[ logSink_syslog ] >= statementLevel )
{
if (commonPrefix.begin == nullptr) {
commonPrefix = buildCommonPrefix( statementLevel, category, filePath, lineNumber, funcName, commonPrefixBuffer, commonPrefixBufferSize );
}
// create a separate copy of va_list because functions using it (such as fprintf, etc.) modify it
va_list msgPrintfFmtArgsCopy;
va_copy( /* dst: */ msgPrintfFmtArgsCopy, /* src: */ msgPrintfFmtArgs );
Expand All @@ -574,6 +580,9 @@ void vLogWithLoggerImpl(
#ifdef PHP_WIN32
if ( isForced || logger->config.levelPerSinkType[ logSink_winSysDebug ] >= statementLevel )
{
if (commonPrefix.begin == nullptr) {
commonPrefix = buildCommonPrefix( statementLevel, category, filePath, lineNumber, funcName, commonPrefixBuffer, commonPrefixBufferSize );
}
// create a separate copy of va_list because functions using it (such as fprintf, etc.) modify it
va_list msgPrintfFmtArgsCopy;
va_copy( /* dst: */ msgPrintfFmtArgsCopy, /* src: */ msgPrintfFmtArgs );
Expand All @@ -584,6 +593,9 @@ void vLogWithLoggerImpl(

if ( ( isForced || logger->config.levelPerSinkType[ logSink_file ] >= statementLevel ) && isLogFileInGoodState( logger ) )
{
if (commonPrefix.begin == nullptr) {
commonPrefix = buildCommonPrefix( statementLevel, category, filePath, lineNumber, funcName, commonPrefixBuffer, commonPrefixBufferSize );
}
// create a separate copy of va_list because functions using it (such as fprintf, etc.) modify it
va_list msgPrintfFmtArgsCopy;
va_copy( /* dst: */ msgPrintfFmtArgsCopy, /* src: */ msgPrintfFmtArgs );
Expand All @@ -592,6 +604,9 @@ void vLogWithLoggerImpl(
}

#ifdef ELASTIC_APM_LOG_CUSTOM_SINK_FUNC
if (commonPrefix.begin == nullptr) {
commonPrefix = buildCommonPrefix( statementLevel, category, filePath, lineNumber, funcName, commonPrefixBuffer, commonPrefixBufferSize );
}
va_list msgPrintfFmtArgsCopy;
va_copy( /* dst: */ msgPrintfFmtArgsCopy, /* src: */ msgPrintfFmtArgs );
buildFullTextAndWriteToCustomSink( logger, commonPrefix, msgPrintfFmt, msgPrintfFmtArgsCopy );
Expand Down
Loading