[Comgr] Create a Global Logger Class for Comgr#3116
Conversation
MixedMatched
left a comment
There was a problem hiding this comment.
Just a few things. Overall great work!
|
Nit: Title should be updated with prefix |
| static const char *LogLevel = getenv("AMD_COMGR_LOG_LEVEL"); | ||
| return LogLevel ? StringRef(LogLevel) : StringRef(); |
There was a problem hiding this comment.
We probably want to be case-insensitive here ?
There was a problem hiding this comment.
Also, whats the rationale behind using strings over numbers to denote severity ?
I would lean more to using numbers since thats what we currently do in runtime.
Its also easier to think about IMO
There was a problem hiding this comment.
Internally Comgr can map an integer to a severity level. But externally I think we should just expose them as numbers
There was a problem hiding this comment.
There was a problem hiding this comment.
the case insensitivity is handled in comgr-logger.cpp, are you saying to move that the case lower to here?
There was a problem hiding this comment.
I suppose the sensitivity discussion is irrelevant if we're exposing numbers instead
There was a problem hiding this comment.
Oh sorry, when I posted that comment, I didn't see the more recent ones. Personally, I think that these labels make it more clear for both assigning LogLevels to a particular output and for toggling the threshold for what logs a user would like to see.
There was a problem hiding this comment.
I disagree. There's a few reasons:
-
The precedent has already been set by various other projects in the ROCm / HIP ecosystem. See 1, 2, 3 etc. Since Comgr is a member of the ROCm ecosystem we want to play along.
-
Its intuitive to think about "big number = more logging". This way you dont have to worry about the exact number assigned to the level of logging. You can just say
COMGR_LOG_LEVEL = 100and the user gets what they want. Very likely, they are not going to be choosing between these levels. They'd want the maximum possible logging when debugging an error. In fact, I have been usingAMD_LOG_LEVEL=7for runtime and I have no clue what the individual numbers map to. -
Tangential to point 2, you cant really establish an intuitive relationship between the various levels. How are "info" and "warning" related ? Does "error" give me more or less logging than "debug" ? Its confusing.
There was a problem hiding this comment.
That makes sense, thanks for the clarification. I'll do a 0-20 level logging and let the users have autonomy.
There was a problem hiding this comment.
We dont want to do 0-100 exactly. We still want to do 0-4 or 0-5 (depending on the available levels).
However, we do want to perform numeric comparison rather than equality when checking against the parsed value.
| return LogLevel::None; | ||
| if (Requested.equals_insensitive("error")) | ||
| return LogLevel::Error; | ||
| if (Requested.equals_insensitive("warning")) | ||
| return LogLevel::Warning; | ||
| if (Requested.equals_insensitive("info")) | ||
| return LogLevel::Info; | ||
| if (Requested.equals_insensitive("debug")) | ||
| return LogLevel::Debug; | ||
|
|
There was a problem hiding this comment.
Commented out code should be removed
|
Nice, we are starting to get there! Whats the reasoning behind the 0-20? We should just advertise the 4 levels (1-4) and leave everything else to numeric comparison. I'm counting the We should take inspiration from other projects in the ecosystem that I've linked. I'm not a fan of the verbose comment strategy that LLMs have. We should keep them to a minimum unless absolutely necessary. Some other review points (LLM generated, but I think they make sense):
|
| /// Severity of a log message, and the logger's configured threshold, expressed | ||
| /// on a 0-to-4 scale where 0 silences logging and higher values are more | ||
| /// verbose. A message is emitted only when its severity is non-zero and does | ||
| /// not exceed the configured level (see Logger::isEnabled). Callers choose the | ||
| /// numeric severity passed to Logger::emit; larger numbers are reserved for | ||
| /// more detailed diagnostics. |
There was a problem hiding this comment.
Same for the other function definitions in this file.
There was a problem hiding this comment.
+1 need to shorten more. I think this is mostly okay, but could use some concise language
|
Can we use a named enum (None=0, Error=1, Warning=2, Info=3, Debug=4) with the Severity <= Level checks? |
|
Some LLM comments:
|
|
@lamb-j @chinmaydd my last commits just addressed all of your recent comments, please check when you're able to |
| } | ||
|
|
||
| LogLevel resolveLevel() { | ||
| static const char *LogLevel = getenv("AMD_COMGR_LOG_LEVEL"); |
There was a problem hiding this comment.
Can we rename this to something other than LogLevel ?
…opped gating redirect failures on LogLevel not being none
e852447 to
14d74ec
Compare
| return static_cast<LogLevel>(std::min(Numeric, Max)); | ||
| } | ||
|
|
||
| LogLevel resolveLevel() { |
There was a problem hiding this comment.
Maybe resolveLogLevel or getLogLevel (since that is the convention for other functions here) ? But I wont fight you on it.
| // Capture emit() output from this action into LogS (the buffer backing the | ||
| // AMD_COMGR_DATA_KIND_LOG object) so it reaches the caller. |
| // RUN: logger-redirect %s 1.2 %t.debug.returned.log | ||
| // RUN: FileCheck %s < %t.debug.log | ||
| // RUN: FileCheck %s < %t.debug.returned.log | ||
| // CHECK: amd_comgr_do_action: |
There was a problem hiding this comment.
Maybe this test could be stronger -- with the different log levels ? I'd defer to your judgement
chinmaydd
left a comment
There was a problem hiding this comment.
LGTM with nits! Looks great.
@MixedMatched, @lamb-j can you take a look as well ?
Addresses this Jira Issue https://amd-hub.atlassian.net/browse/LCOMPILER-1886