-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[Linux] Add mechanism to redirect CHIP log other than stdout #33338
Conversation
PR #33338: Size comparison from 242accd to 664b050 Increases (12 builds for linux)
Decreases (11 builds for efr32, linux)
Full report (77 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, mbed, nrfconnect, nxp, psoc6, qpg, stm32, telink)
|
logFile = fopen(filePath, "a"); | ||
if (logFile == nullptr) | ||
{ | ||
perror("Failed to open log file"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must VerifyOrDie.
void OpenLogFile(const char * filePath); | ||
|
||
/** | ||
* Close the log file if it is open. This function should be called | ||
* at the end of the application to ensure that all log messages are | ||
* flushed to disk and the file is properly closed. | ||
*/ | ||
void CloseLogFile(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are these called?
* exist, it will be created. If it exists, log | ||
* messages will be appended to it. | ||
*/ | ||
void OpenLogFile(const char * filePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a list of log sinks (one of which is stdout by default) rather than assume a single place where logs go. Otherwise it is impossible to have stdout + output to file logs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do currently allow setting one log sink (the logging redirector setup), which can then be used to multiplex as desired without changing any platform implementations....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/project-chip/connectedhomeip/blob/master/src/lib/support/logging/TextOnlyLogging.h#L359 contains a SetLogRedirectCallback
where you can move your logging to go anywhere. This is what python uses to redirect to python logging instead of just console.
Could we use this for the CLI bits instead? One could even imagine some term-linke thing where you can both do cli-shell-interact and view the log in a separate pane...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this method works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Introduce a log sink interface (base class) with LogV. Concrete implementations can have their own init, and are responsiblity of the owner/caller
- Make stdout a default log sink for linux
- Do not add new file methods to src/platform/logging --> not portable or relevant everywhere. AddLogSink/RemoveLogSink should be enough
- Ensure >1 log sink can be set, at least on Linux, so that when we update chip-tool interactive we have a way to not lose the logs, even on interactive, if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this Linux-specific?
Close this PR since we already have the mechanism to redirect the logging. |
Currently, both shell command and CHIP logs are printed out to the same console on Linux, make it very difficult to interact with the example app via shell CLI.
Event though I can turn off those logs, but it is better to have a way to redirect logging to another place so that I can only see CLI message in console and check CHIP log in another place