Debugging Your Code

Logging Namespace Train Wrecks

The class name you pass to the Kernel logging functions should be unique. If every wizard has a "test.py", and each one publishes its logs messages to "test.py", then everyone will see everyone else's log messages. It would be annoying, to say the least.

Instead, you should use the relative path to your python class, such as wiz/rhialto/python/scratch.py. For Java classes, you should use the fully-qualified classname, such as "wyvern.wiz.rhialto.java.Thingy". In the game Java classes, we usually define this at the top of the file:

private static final String MYCLASS = "wyvern.wiz.rhialto.java.Thingy";

Then all the logging statements in the file look like this:

Kernel.finer ( MYCLASS, "myMethod", "howdy howdy" );

Here's a fixed-up version of scratch.py, which sets the pathname in the initialize() method, and passes that to all the logging functions:

<span class='string'>"""</span><br><span class='keyword'></span>scratch<span class='keyword'></span>.<span class='keyword'></span>py<span class='keyword'></span><br><br><span class='keyword'></span>An<span class='keyword'></span> <span class='keyword'></span>example<span class='keyword'></span> <span class='keyword'></span>spell<span class='keyword'></span>, <span class='keyword'></span>for<span class='keyword'></span> <span class='keyword'></span>demonstrating<span class='keyword'></span> <span class='keyword'></span>logging<span class='keyword'></span>.  <span class='keyword'></span>There<span class='keyword'></span> <span class='keyword'></span>is<span class='keyword'></span><br><span class='keyword'></span>a<span class='keyword'></span> <span class='keyword'></span>bunch<span class='keyword'></span> <span class='keyword'></span>of<span class='keyword'></span> <span class='keyword'></span>logging<span class='keyword'></span> <span class='keyword'></span>code<span class='keyword'></span> <span class='keyword'></span>in<span class='keyword'></span> <span class='keyword'></span>this<span class='keyword'></span> <span class='keyword'></span>version<span class='keyword'></span> <span class='keyword'></span>of<span class='keyword'></span> <span class='keyword'></span>the<span class='keyword'></span> <span class='keyword'></span>spell<span class='keyword'></span>.  <span class='keyword'></span>The<span class='keyword'></span> <span class='keyword'></span>class<span class='keyword'></span><br><span class='keyword'></span>passes<span class='keyword'></span> <span class='keyword'></span>a<span class='keyword'></span> <span class='keyword'></span>unique<span class='keyword'></span> <span class='keyword'></span>path<span class='keyword'></span> <span class='keyword'></span>to<span class='keyword'></span> <span class='keyword'></span>all<span class='keyword'></span> <span class='keyword'></span>the<span class='keyword'></span> <span class='keyword'></span>logging<span class='keyword'></span> <span class='keyword'></span>functions<span class='keyword'></span>, <span class='keyword'></span>to<span class='keyword'></span> <span class='keyword'></span>avoid<span class='keyword'></span><br><span class='keyword'></span>namespace<span class='keyword'></span> <span class='keyword'></span>collisions<span class='keyword'></span> <span class='keyword'></span>with<span class='keyword'></span> <span class='keyword'></span>other<span class='keyword'></span> <span class='keyword'></span>Wizard<span class='keyword'></span> <span class='keyword'></span>code<span class='keyword'></span>. <<span class='keyword'></span>p<span class='keyword'></span>><br><br><span class='keyword'></span>Copyright<span class='keyword'></span> <span class='keyword'></span>2003<span class='keyword'></span> <span class='keyword'></span>Cabochon<span class='keyword'></span> <span class='keyword'></span>Technologies<span class='keyword'></span>, <span class='keyword'></span>Inc<span class='keyword'></span>.<br><span class='keyword'></span>Author<span class='keyword'></span>: <span class='keyword'></span>Steve<span class='keyword'></span> <span class='keyword'></span>Yegge<span class='keyword'></span><br><span class='string'>"""</span><br><br><span class='keyword'></span>from<span class='keyword'></span> <span class='keyword'></span>java<span class='keyword'></span>.<span class='keyword'></span>lang<span class='keyword'></span> <span class='keyword'></span>import<span class='keyword'></span> <span class='keyword'></span>String<span class='keyword'></span><br><span class='keyword'></span>from<span class='keyword'></span> <span class='keyword'></span>wyvern<span class='keyword'></span>.<span class='keyword'></span>lib<span class='keyword'></span> <span class='keyword'></span>import<span class='keyword'></span> <span class='keyword'></span>Timed<span class='keyword'></span>, <span class='keyword'></span>Range<span class='keyword'></span>, <span class='keyword'></span>Kernel<span class='keyword'></span><br><span class='keyword'></span>from<span class='keyword'></span> <span class='keyword'></span>wyvern<span class='keyword'></span>.<span class='keyword'></span>lib<span class='keyword'></span>.<span class='keyword'></span>classes<span class='keyword'></span>.<span class='keyword'></span>magic<span class='keyword'></span> <span class='keyword'></span>import<span class='keyword'></span> <span class='keyword'></span>Spell<span class='keyword'></span><br><br><span class='keyword'>class</span> <span class='function'>scratch</span>(Spell, Timed):<br><br>    <span class='keyword'>def</span> <span class='function'>initialize</span>(self):<br><br><span class='comment'>        # we initialize self.logname to our unique path</span><br>        <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span> = '<span class='keyword'></span>wiz<span class='keyword'></span>/<span class='keyword'></span>rhialto<span class='keyword'></span>/<span class='keyword'></span>python<span class='keyword'></span>/<span class='keyword'></span>scratchlog<span class='keyword'></span>.<span class='keyword'></span>py<span class='keyword'></span>'<br><br>        <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>finest<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>initialize<span class='keyword'></span>', '<span class='keyword'></span>calling<span class='keyword'></span> <span class='keyword'></span>superclass<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>        <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>super__initialize<span class='keyword'></span>()<br>        <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>setIntProperty<span class='keyword'></span>('<span class='keyword'></span>lore<span class='keyword'></span>', <span class='keyword'></span>1<span class='keyword'></span>)<br>        <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>setProperty<span class='keyword'></span>('<span class='keyword'></span>short<span class='keyword'></span>', '<span class='keyword'></span>scratch<span class='keyword'></span>')<br>        <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>finest<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>initialize<span class='keyword'></span>', '<span class='keyword'></span>done<span class='keyword'></span> <span class='keyword'></span>initializing<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br><br>    <span class='keyword'>def</span> <span class='function'>getArt</span>(self):<br>        <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>entering<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>getArt<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>        <span class='keyword'></span>return<span class='keyword'></span> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>INCANTATION<span class='keyword'></span><br><br>    <span class='keyword'>def</span> <span class='function'>getElement</span>(self):<br>        <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>entering<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>getElement<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>        <span class='keyword'></span>return<span class='keyword'></span> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>SPIRIT<span class='keyword'></span><br><br>    <span class='keyword'>def</span> <span class='function'>start</span>(self):<br><br>        <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>fine<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>start<span class='keyword'></span>', '<span class='keyword'></span>looking<span class='keyword'></span> <span class='keyword'></span>for<span class='keyword'></span> <span class='keyword'></span>target<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br><span class='comment'>        # look for target, or use caster if there isn't one</span><br>        <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>target<span class='keyword'></span> = <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>findTargetObject<span class='keyword'></span>(<span class='keyword'></span>1<span class='keyword'></span>)<br>        <span class='keyword'></span>if<span class='keyword'></span> <span class='keyword'></span>not<span class='keyword'></span> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>target<span class='keyword'></span>:<br>            <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>fine<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>start<span class='keyword'></span>', '<span class='keyword'></span>no<span class='keyword'></span> <span class='keyword'></span>target<span class='keyword'></span> <span class='keyword'></span>found<span class='keyword'></span>!')</<span class='keyword'></span>em<span class='keyword'></span>><br>            <span class='keyword'></span>return<span class='keyword'></span><br><br>        <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>fine<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>start<span class='keyword'></span>', '<span class='keyword'></span>setting<span class='keyword'></span> <span class='keyword'></span>timer<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>        <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>timer<span class='keyword'></span> = <span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>setRepeatingTimer<span class='keyword'></span> ( <span class='keyword'></span>20000<span class='keyword'></span>, <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span> )<br><br>        <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>fine<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>start<span class='keyword'></span>', '<span class='keyword'></span>making<span class='keyword'></span> <span class='keyword'></span>dispellable<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>        <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>makeDispellable<span class='keyword'></span>()<br><br>        <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>getAgent<span class='keyword'></span>().<span class='keyword'></span>message<span class='keyword'></span>('<span class='keyword'></span>You<span class='keyword'></span> <span class='keyword'></span>cast<span class='keyword'></span> <span class='keyword'></span>scratch<span class='keyword'></span> <span class='keyword'></span>on<span class='keyword'></span> ' + <span class='keyword'></span>str<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>target<span class='keyword'></span>))<br><br>    <span class='keyword'>def</span> <span class='function'>timerExpired</span>(self):<br>        <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>fine<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>timerExpired<span class='keyword'></span>', '<span class='keyword'></span>entering<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>        <span class='keyword'></span>target<span class='keyword'></span> = <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>target<span class='keyword'></span><br>        <span class='keyword'></span>roll<span class='keyword'></span> = <span class='keyword'></span>Range<span class='keyword'></span>.<span class='keyword'></span>percent<span class='keyword'></span>()<br>        <span class='keyword'></span>pronoun<span class='keyword'></span> = <span class='keyword'></span>target<span class='keyword'></span>.<span class='keyword'></span>getGenderString<span class='keyword'></span>()<br>        <span class='keyword'></span>name<span class='keyword'></span> = <span class='keyword'></span>target<span class='keyword'></span>.<span class='keyword'></span>getName<span class='keyword'></span>()<br><br>        <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>finer<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>timerExpired<span class='keyword'></span>', '<span class='keyword'></span>name<span class='keyword'></span>: ' + <span class='keyword'></span>name<span class='keyword'></span>)</<span class='keyword'></span>em<span class='keyword'></span>><br>        <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>finer<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>timerExpired<span class='keyword'></span>', '<span class='keyword'></span>rolled<span class='keyword'></span> ' + <span class='keyword'></span>str<span class='keyword'></span>(<span class='keyword'></span>roll<span class='keyword'></span>))</<span class='keyword'></span>em<span class='keyword'></span>><br><br>        <span class='keyword'></span>if<span class='keyword'></span> <span class='keyword'></span>roll<span class='keyword'></span> < <span class='keyword'></span>20<span class='keyword'></span>:<br>            <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>finest<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>timerExpired<span class='keyword'></span>', '<span class='keyword'></span>scratching<span class='keyword'></span> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>            <span class='keyword'></span>target<span class='keyword'></span>.<span class='keyword'></span>message<span class='keyword'></span> ( <span class='string'>"<span class='keyword'></span>You<span class='keyword'></span> <span class='keyword'></span>scratch<span class='keyword'></span> <span class='keyword'></span>yourself<span class='keyword'></span>."</span> )<br>            <span class='keyword'></span>target<span class='keyword'></span>.<span class='keyword'></span>broadcast<span class='keyword'></span> ( <span class='keyword'></span>name<span class='keyword'></span> + <span class='string'>" <span class='keyword'></span>scratches<span class='keyword'></span> "</span> +<br>                               <span class='keyword'></span>pronoun<span class='keyword'></span> + <span class='string'>"<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span> <span class='keyword'></span>vigorously<span class='keyword'></span>."</span> )<br>        <span class='keyword'></span>elif<span class='keyword'></span> <span class='keyword'></span>roll<span class='keyword'></span> < <span class='keyword'></span>40<span class='keyword'></span>:<br>            <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>finest<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>timerExpired<span class='keyword'></span>', '<span class='keyword'></span>scratching<span class='keyword'></span> <span class='keyword'></span>nose<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>            <span class='keyword'></span>target<span class='keyword'></span>.<span class='keyword'></span>message<span class='keyword'></span> ( <span class='string'>"<span class='keyword'></span>You<span class='keyword'></span> <span class='keyword'></span>rub<span class='keyword'></span> <span class='keyword'></span>your<span class='keyword'></span> <span class='keyword'></span>nose<span class='keyword'></span>."</span> )<br>            <span class='keyword'></span>target<span class='keyword'></span>.<span class='keyword'></span>broadcast<span class='keyword'></span> ( <span class='keyword'></span>name<span class='keyword'></span> + <span class='string'>" <span class='keyword'></span>rubs<span class='keyword'></span> "</span> +<br>                               <span class='keyword'></span>pronoun<span class='keyword'></span> + <span class='string'>" <span class='keyword'></span>nose<span class='keyword'></span> <span class='keyword'></span>for<span class='keyword'></span> <span class='keyword'></span>a<span class='keyword'></span> <span class='keyword'></span>long<span class='keyword'></span> <span class='keyword'></span>while<span class='keyword'></span>."</span> )<br>        <span class='keyword'></span>elif<span class='keyword'></span> <span class='keyword'></span>roll<span class='keyword'></span> < <span class='keyword'></span>60<span class='keyword'></span>:<br>            <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>finest<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>timerExpired<span class='keyword'></span>', '<span class='keyword'></span>scratching<span class='keyword'></span> <span class='keyword'></span>ear<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>            <span class='keyword'></span>target<span class='keyword'></span>.<span class='keyword'></span>message<span class='keyword'></span> ( <span class='string'>"<span class='keyword'></span>You<span class='keyword'></span> <span class='keyword'></span>scratch<span class='keyword'></span> <span class='keyword'></span>your<span class='keyword'></span> <span class='keyword'></span>ear<span class='keyword'></span>."</span> )<br>            <span class='keyword'></span>target<span class='keyword'></span>.<span class='keyword'></span>broadcast<span class='keyword'></span> ( <span class='keyword'></span>name<span class='keyword'></span> + <span class='string'>" <span class='keyword'></span>sticks<span class='keyword'></span> "</span> +<br>                               <span class='keyword'></span>pronoun<span class='keyword'></span> + <span class='string'>" <span class='keyword'></span>finger<span class='keyword'></span> <span class='keyword'></span>in<span class='keyword'></span> "</span> + <span class='keyword'></span>pronoun<span class='keyword'></span> +<br>                               <span class='string'>" <span class='keyword'></span>ear<span class='keyword'></span> <span class='keyword'></span>and<span class='keyword'></span> <span class='keyword'></span>scratches<span class='keyword'></span> <span class='keyword'></span>an<span class='keyword'></span> <span class='keyword'></span>itch<span class='keyword'></span>."</span> )<br>        <span class='keyword'></span>elif<span class='keyword'></span> <span class='keyword'></span>roll<span class='keyword'></span> < <span class='keyword'></span>80<span class='keyword'></span>:<br>            <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>finest<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>timerExpired<span class='keyword'></span>', '<span class='keyword'></span>belching<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>            <span class='keyword'></span>target<span class='keyword'></span>.<span class='keyword'></span>message<span class='keyword'></span> ( <span class='string'>"<span class='keyword'></span>You<span class='keyword'></span> <span class='keyword'></span>suddenly<span class='keyword'></span> <span class='keyword'></span>belch<span class='keyword'></span>."</span> )<br>            <span class='keyword'></span>target<span class='keyword'></span>.<span class='keyword'></span>broadcast<span class='keyword'></span> ( <span class='keyword'></span>name<span class='keyword'></span> + <span class='string'>" <span class='keyword'></span>belches<span class='keyword'></span> <span class='keyword'></span>loudly<span class='keyword'></span>, "</span> +<br>                               <span class='string'>"<span class='keyword'></span>and<span class='keyword'></span> <span class='keyword'></span>looks<span class='keyword'></span> <span class='keyword'></span>very<span class='keyword'></span> <span class='keyword'></span>embarrassed<span class='keyword'></span> <span class='keyword'></span>about<span class='keyword'></span> <span class='keyword'></span>it<span class='keyword'></span>."</span> )<br>        <span class='keyword'></span>else<span class='keyword'></span>:<br>            <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>finest<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>timerExpired<span class='keyword'></span>', '<span class='keyword'></span>smelling<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>            <span class='keyword'></span>target<span class='keyword'></span>.<span class='keyword'></span>broadcast<span class='keyword'></span> ( <span class='keyword'></span>name<span class='keyword'></span> + <span class='string'>" <span class='keyword'></span>smells<span class='keyword'></span> <span class='keyword'></span>terrible<span class='keyword'></span> <span class='keyword'></span>today<span class='keyword'></span>."</span> )<br>            <br>    <span class='keyword'>def</span> <span class='function'>dispel</span>(self):<br>        <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>fine<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>dispel<span class='keyword'></span>', '<span class='keyword'></span>calling<span class='keyword'></span> <span class='keyword'></span>superclass<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>        <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>super__dispel<span class='keyword'></span>()<br><br>        <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>fine<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>dispel<span class='keyword'></span>', '<span class='keyword'></span>killing<span class='keyword'></span> <span class='keyword'></span>timer<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>        <span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>killTimer<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>timer<span class='keyword'></span>)<br>        <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>target<span class='keyword'></span>.<span class='keyword'></span>message<span class='keyword'></span> ( <span class='string'>"<span class='keyword'></span>You<span class='keyword'></span> <span class='keyword'></span>suddenly<span class='keyword'></span> <span class='keyword'></span>feel<span class='keyword'></span> <span class='keyword'></span>more<span class='keyword'></span> <span class='keyword'></span>sophisticated<span class='keyword'></span>."</span> )<br><br>    <span class='keyword'>def</span> <span class='function'>__repr__</span>(self):<br>        <span class='keyword'></span>return<span class='keyword'></span> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>getProperty<span class='keyword'></span>('<span class='keyword'></span>short<span class='keyword'></span>')<br><br>    <span class='keyword'>def</span> <span class='function'>toString</span>(self):<br>        <span class='keyword'></span>return<span class='keyword'></span> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>__repr__<span class='keyword'></span>()<br><br>    <span class='keyword'>def</span> <span class='function'>getSpellDescription</span>(self):<br>        <<span class='keyword'></span>em<span class='keyword'></span>><span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>entering<span class='keyword'></span>(<span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>logname<span class='keyword'></span>, '<span class='keyword'></span>getSpellDescription<span class='keyword'></span>')</<span class='keyword'></span>em<span class='keyword'></span>><br>        <span class='keyword'></span>return<span class='keyword'></span> (<span class='string'>"<span class='keyword'></span>This<span class='keyword'></span> "</span> + <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>getDescString<span class='keyword'></span>() +<br>                <span class='string'>" <span class='keyword'></span>lowers<span class='keyword'></span> <span class='keyword'></span>the<span class='keyword'></span> <span class='keyword'></span>target<span class='keyword'></span> <span class='keyword'></span>several<span class='keyword'></span> <span class='keyword'></span>rungs<span class='keyword'></span> <span class='keyword'></span>on<span class='keyword'></span> <span class='keyword'></span>the<span class='keyword'></span> <span class='keyword'></span>Social<span class='keyword'></span> <span class='keyword'></span>Ladder<span class='keyword'></span>."</span>)

Much better. For starters, we now pass a unique name to the Kernel logging functions, which means other people with 'scratch.py' classes won't stomp on us.

Also, if we change the name of the class, we only need to change the line that sets self.logname — in the old version, we would have had to change every single logging statement!

In the next lesson, we'll cover some performance issues, and then you should be ready to start using logging yourself.

<< Previous Chapter Next Chapter >>