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

Provide unified logging interface #816

Merged
merged 15 commits into from
Jul 23, 2020
Merged

Provide unified logging interface #816

merged 15 commits into from
Jul 23, 2020

Conversation

xkubov
Copy link
Contributor

@xkubov xkubov commented Jul 22, 2020

In this PR I would like to introduce changes to the RetDec decompiler logging system. Before these changes each module controlled output on stdout/stderr on its own.

High-level changes:

  • Added option --silent to turn of logging on stdout.
  • Added option "logFile" to the retdec config.
  • Added option "errFile" to the retdec config.

Changes above are particularly useful for users of the RetDec library. Before this PR there was no easy way to redirect RetDec's output when decompilation was called from retdec::decompiler function.

Logging design:

  • Created interface retdec::utils::io::Log with functions info(), error(), set(...) that control logging objects. More info in documentation.
    • Usage:
      • Log::info() << Log::Color::Yellow << "RetDec module" << std::endl
      • Log::error() << Log::Warning << "Unable to allocate stuff" << std::endl

With these changes, colors on output are managed in RetDec (before we used LLVM library). Logger class implemented to print output uses ANSI encoding for colors. This is supported on all POSIX terminals and Windows terminals following the Anniversary update. Changes were tested on Linux, macOS, and Windows. Colors are automatically disabled when output is not a terminal.

Provides new logging interface that is ment to unify output that
is produced in each part of RetDec decompiler.

The interface is designed to provide eazy management
of logging into files/tty.

Currently each module od decompiler manages logging on its own.
This is not sustainable state as change to logging interface
is rather difficult.
@xkubov
Copy link
Contributor Author

xkubov commented Jul 22, 2020

Let's run TeamCity builds

@xkubov
Copy link
Contributor Author

xkubov commented Jul 22, 2020

Fixed error, let's run TeamCity builds again.

@xkubov xkubov force-pushed the logger branch 2 times, most recently from 0c82d8f to d5898d9 Compare July 22, 2020 10:33
@xkubov xkubov force-pushed the logger branch 2 times, most recently from cf76464 to 8a0fa3a Compare July 22, 2020 11:19
Peter Kubov added 14 commits July 22, 2020 13:43
This module is now obsolete as all logging mechanisms
have been transferred to retdec::io module.
Provides new option [-s|--silent] for retdec-decompiler executable.
This option will force retdec not to output anything on stdout.
Provides way to specify Log/Error files to RetDec.
This is useful for RetDec plugins that might this way
control decompilation output.
Fixes bug provided by fbbff34.
Provides change to log interface. Before this commit
logging was done on global objects. Now the logging
should be made on temporary objects that are returned
from special functions.

The reason for this is for usage of colors on output.
When temporary object is destructed default color is
printed on required interface.
This way we can avoid not intentional usage of the
Log interface.

All functions of Log are ment to be used like:

Log::info()
Log::debug()
Log::error()
Starting Windows aniversary update Windows terminals provide
supprot for ANSI colors. This, however, needs to be enabled
manually.

More about this can be found here:
https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences?redirectedfrom=MSDN
Provides substitution of __has_include macro to OS_WINDOWS defined
in utils/os.h. The reason for this is to maintain a level of
consistency in RetDec source code base.
Copy link
Collaborator

@PeterMatula PeterMatula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice.

@@ -2,6 +2,7 @@

# dev

* Enhancement: Unified logging on stdout/stderr. Added option `--silent`. Printed text is colored only when output is a terminal ([#791](https://github.com/avast/retdec/issues/791).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @s3rvac suggested in some other place, it is better to add these entries after the merge to master. It is then possible to reference the PR.

Copy link
Member

@s3rvac s3rvac Jul 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus the risk of running into conflicts is much lower 🙂

@PeterMatula PeterMatula merged commit b59f811 into master Jul 23, 2020
@PeterMatula PeterMatula deleted the logger branch July 23, 2020 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants