[ckan-dev] Logging in commands question

William Waites ww at styx.org
Wed Apr 6 14:37:04 UTC 2011


I don't know the exact answer. It probably has something to do with
the fact that paste.Command (of which CkanCommand is a subclass)
initialised logging according to the config file. If the logger
reference obtained before the logging is initialised I think it may
just log into the bit bucket.

Evils of global variables which the whole paste/pylons stack is
riddled with.

Cheers,
-w

* [2011-04-06 15:31:29 +0100] Adrià Mercader <amercadero at gmail.com> écrit:

] 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à
] 
] _______________________________________________
] ckan-dev mailing list
] ckan-dev at lists.okfn.org
] http://lists.okfn.org/mailman/listinfo/ckan-dev

-- 
William Waites                <mailto:ww at styx.org>
http://river.styx.org/ww/        <sip:ww at styx.org>
F4B3 39BF E775 CF42 0BAB  3DF0 BE40 A6DF B06F FD45




More information about the ckan-dev mailing list