提交 14f4152e 编写于 作者: L Lukáš Doktor

output: Define LOG_UI and LOG_JOB

On many places we are directly getting "avocado.app" and "avocado.test"
loggers and interacting with them. This can become an issue when we try
to replace or modify our logging streams in the future as well as it
requires some hidden knowledge. Let's define LOG_UI and LOG_JOB in
`avocado.core.output` to be available for Avocado core (and silently
also for plugin) developers.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 bc4eb2f8
......@@ -32,6 +32,11 @@ else:
NULL_HANDLER = logutils.NullHandler
#: Pre-defined Avocado human UI logger
LOG_UI = logging.getLogger("avocado.app")
#: Pre-defined Avocado job/test logger
LOG_JOB = logging.getLogger("avocado.test")
#: Builtin special keywords to enable set of logging streams
BUILTIN_STREAMS = {'app': 'application output',
'test': 'test output',
......
......@@ -44,6 +44,7 @@ Code example
Let's say you want to write a plugin that adds a new subcommand to the test
runner, ``hello``. This is how you'd do it::
from avocado.core.output import LOG_JOB
from avocado.core.plugin_interfaces import CLICmd
......@@ -53,13 +54,17 @@ runner, ``hello``. This is how you'd do it::
description = 'The classical Hello World! plugin example.'
def run(self, args):
print(self.description)
LOG_JOB.info(self.description)
As you can see, this plugins inherits from :class:`avocado.core.plugin_interfaces.CLICmd`.
This specific base class allows for the creation of new commands for the Avocado
CLI tool. The only mandatory method to be implemented is :func:`run
<avocado.core.plugin_interfaces.CLICmd.run>` and it's the plugin main entry point.
In this code example it will simply print the plugin's description.
This plugin uses :py:data:`avocado.core.output.LOG_JOB` to produce the hello
world output in the Job log. One can also use
:py:data:`avocado.core.output.LOG_UI` to produce output in the human readable
output.
Registering Plugins
~~~~~~~~~~~~~~~~~~~
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册