Skip to content

Commit

Permalink
Optimize log line prefix generation based on display criteria (elasti…
Browse files Browse the repository at this point in the history
  • Loading branch information
intuibase committed Sep 25, 2023
1 parent b80bba4 commit ef85a4f
Showing 1 changed file with 16 additions and 1 deletion.
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

0 comments on commit ef85a4f

Please sign in to comment.