[ckan-dev] Logging in commands question
Adrià Mercader
amercadero at gmail.com
Wed Apr 6 14:31:29 UTC 2011
Hi all,
Sorry if this is a silly question, but I haven't managed to solve it.
When implementing a CLI command from an extension, I'm having problems
to get the log messages to show in the console.
In ckan/myextension/echo.py:
log = __import__("logging").getLogger(__name__)
def echo_log():
log.info("That's a message")
def another_function():
pass
Now, if import the echo function outside the command class, the log
messages don't come up in the command file
from ckan.lib.cli import CkanCommand
from ckan.myextension.echo import echo_log
class TestCommand(CkanCommand)
def command():
echo_log() #Does not output anything in the command line
But if import the function within the function, the log messages are shown:
from ckan.lib.cli import CkanCommand
class TestCommand(CkanCommand)
def command():
from ckan.myextension.echo import echo_log
echo_log() #Does output the log message
And to make matters worse, if I import another function of the same
module outside the command class, messages are not shown
from ckan.lib.cli import CkanCommand
from ckan.myextension.echo import another_function
class TestCommand(CkanCommand)
def command():
from ckan.myextension.echo import echo_log
echo_log() #Does not output anything in the command line
As far as I know, this does not happen with normal python classes so
maybe I'm missing something with CkanCommand?
Thanks,
Adrià
More information about the ckan-dev
mailing list