Logging from Robot Framework Extension Libraries

587 views
Skip to first unread message

Martin Taylor

unread,
Jun 8, 2009, 11:57:40 AM6/8/09
to robotframework-devel
I notice in the RF source tree that there are files src\robot\output
\logger.py and src\robot\output\loggerhelper.py. Are the classes and
methods in these files intended to be used by writers of Robot
Framework Extension Libraries? If so, are there any examples of best
practice in doing so?

Pekka Klärck

unread,
Jun 8, 2009, 12:11:13 PM6/8/09
to cmta...@ti.com, robotframework-devel
2009/6/8 Martin Taylor <cmta...@ti.com>:

These modules are used internally. Libraries should just write to
stdout as explained at
http://robotframework.googlecode.com/svn/tags/robotframework-2.1/doc/userguide/RobotFrameworkUserGuide.html#logging-information

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Martin Taylor

unread,
Jun 8, 2009, 12:25:21 PM6/8/09
to robotframework-devel
That's kind of what I thought, but its not very convenient. So
several months back I wrote my own Logger.py class, based on the
logging methods in the Selenium library (_info(), _warn(), etc.).
Some useful extensions to this library are _infoKW() and _debugKW()
that do logging of entry to a keyword method with all its parameters
and does special handling for non-ASCII parameters. I did this
because I was building so many RF extension libraries (to date 16)
that ALL needed to have the same capabilities. I simply derive each
one from this logger class. I put it in a "Utils" folder, along with
some other useful base classes. I use this in my AutoItLibrary that
I'm trying to prepare for Open Source release, like this:

import Utils.Logger
import Utils.Counter

class AutoItLibrary(Utils.Logger.Logger, Utils.Counter.Counter) :

unfortunately this puts a dependency on Utils by AutoItLibrary.
That's why I was wondering if there was any more standard way of doing
this. Obviously the folks that developed SeleniumLibrary thought
methods like this were useful and I completely agree and extended the
idea.

Do you think we could maybe have a new part of Robot Framework where
classes to assist extension library developers could be placed so that
we can all share them and rely on them being present, rather than each
having to invent our own?

On Jun 8, 11:11 am, Pekka Klärck <p...@iki.fi> wrote:
> 2009/6/8 Martin Taylor <cmtay...@ti.com>:
>
>
>
> > I notice in the RF source tree that there are files src\robot\output
> > \logger.py and src\robot\output\loggerhelper.py. Are the classes and
> > methods in these files intended to be used by writers of Robot
> > Framework Extension Libraries? If so, are there any examples of best
> > practice in doing so?
>
> These modules are used internally. Libraries should just write to
> stdout as explained athttp://robotframework.googlecode.com/svn/tags/robotframework-2.1/doc/...

Pekka Klärck

unread,
Jun 9, 2009, 2:27:20 PM6/9/09
to cmta...@ti.com, robotframework-devel
2009/6/8 Martin Taylor <cmta...@ti.com>:

>
> That's kind of what I thought, but its not very convenient.

The main reason for this design is that you don't need to have any
dependency to Robot Framework modules. Additionally the same approach
works from Java code.

> So several months back I wrote my own Logger.py class, based on the
> logging methods in the Selenium library (_info(), _warn(), etc.).
> Some useful extensions to this library are _infoKW() and _debugKW()
> that do logging of entry to a keyword method with all its parameters
> and does special handling for non-ASCII parameters.

Do you need to log parameters always? In that case you might want to
try using '--loglevel trace'. The problem with both approaches is that
the log file can easily grow huge.

>  I did this
> because I was building so many RF extension libraries (to date 16)
> that ALL needed to have the same capabilities.  I simply derive each
> one from this logger class.  I put it in a "Utils" folder, along with
> some other useful base classes.  I use this in my AutoItLibrary that
> I'm trying to prepare for Open Source release, like this:
>
> import Utils.Logger
> import Utils.Counter
>
> class AutoItLibrary(Utils.Logger.Logger, Utils.Counter.Counter) :

This is fine. Personally I'd rather implement at least Logger as a
module so that there would be no need for inheritance. You could do
something like:

import logger

classe MyLibrary:
def some_keyword(self, arg):
logger.info('Got argument: %s' % arg)

> unfortunately this puts a dependency on Utils by AutoItLibrary.
> That's why I was wondering if there was any more standard way of doing
> this.  Obviously the folks that developed SeleniumLibrary thought
> methods like this were useful and I completely agree and extended the
> idea.
>
> Do you think we could maybe have a new part of Robot Framework where
> classes to assist extension library developers could be placed so that
> we can all share them and rely on them being present, rather than each
> having to invent our own?

We've been thinking that it's so easy to implement needed loggers that
there's no need for such a generic module. I'm fine with adding it if
we got a patch with an implementation, some unit tests (this is pretty
simple so no need to many tests), and documentation to add to the user
guide so that others can also use it.

Reply all
Reply to author
Forward
0 new messages