<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mFabrik - mobile sites, apps, HTML5 and CMS software development &#187; logging</title>
	<atom:link href="http://blog.mfabrik.com/tag/logging/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mfabrik.com</link>
	<description>Freedom delivered.</description>
	<lastBuildDate>Wed, 03 Aug 2011 09:47:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Ghetto logging for PHP</title>
		<link>http://blog.mfabrik.com/2011/03/03/ghetto-logging-for-php/</link>
		<comments>http://blog.mfabrik.com/2011/03/03/ghetto-logging-for-php/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 12:49:55 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[file_put_contents]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=1051</guid>
		<description><![CDATA[In the case you need to quickly see if certain code path is executed on a production server for which config cannot be changed. file_put_contents("/tmp/log.txt", "this is a test entry\n"); The proper method would be Configure error log in php.ini Use error_log() &#8230;. or use logging facility of your PHP framework Get developers  Subscribe mFabrik [...]]]></description>
			<content:encoded><![CDATA[<p>In the case you need to quickly see if certain code path is executed on a production server for which config cannot be changed.</p>
<pre>file_put_contents("/tmp/log.txt", "this is a test entry\n");</pre>
<p>The proper method would be</p>
<ul>
<li>Configure error log in php.ini</li>
<li>Use error_log()</li>
<li>&#8230;. or use logging facility of your PHP framework</li>
</ul>
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2011/03/03/ghetto-logging-for-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temporarily capturing Python logging output to a string buffer</title>
		<link>http://blog.mfabrik.com/2011/02/23/temporarily-capturing-python-logging-output-to-a-string-buffer/</link>
		<comments>http://blog.mfabrik.com/2011/02/23/temporarily-capturing-python-logging-output-to-a-string-buffer/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 17:16:56 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[plone]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[buffer]]></category>
		<category><![CDATA[grok]]></category>
		<category><![CDATA[handler]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[setLevel]]></category>
		<category><![CDATA[stringio]]></category>
		<category><![CDATA[zope]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=1009</guid>
		<description><![CDATA[You can capture Python logging output temporarily to a string buffer. This is useful if you want to use logging module to record the status of long running operations and later show the resulting log to the end user, who does not have access to file system logs. Below is an Grok framework view code [...]]]></description>
			<content:encoded><![CDATA[<p>You can capture Python logging output temporarily to a string buffer. This is useful if you want to use logging module to record<br />
the status of long running operations and later show the resulting log to the end user, who does not have access to file system logs.</p>
<p>Below is an <a href="http://grok.zope.org/">Grok</a> framework view code example for <a href="http://plone.org">Plone</a> CMS.</p>
<p>View code:</p>
<pre>
import logging
from StringIO import StringIO

from five import grok

from xxx.objects.interfaces import IXXXResearcher
from Products.CMFCore.interfaces import ISiteRoot
from Products.statusmessages.interfaces import IStatusMessage

from xxx.objects.sync import sync_with_xxx

grok.templatedir("templates")

logger = logging.getLogger("XXX sync")

class SyncAll(grok.View):
    """
    Update all researcher data on the site from XXX (admin action)
    """

    grok.context(ISiteRoot)

    def sync(self):
        """
        Search all objects of certain type on the site and
        sync them with a remote site.
        """

        brains =  self.context.portal_catalog(object_provides=IXXXResearcher.__identifier__)
        for brain in brains:
            object = brain.getObject()
            sync_with_xxx(object, force=True)

    def startCapture(self, newLogLevel = None):
        """ Start capturing log output to a string buffer.

http://docs.python.org/release/2.6/library/logging.html

        @param newLogLevel: Optionally change the global logging level, e.g. logging.DEBUG
        """
        self.buffer = StringIO()

        print >> self.buffer, "Log output"

        rootLogger = logging.getLogger()

        if newLogLevel:
            self.oldLogLevel = rootLogger.getEffectiveLevel()
            rootLogger.setLevel(newLogLevel)
        else:
            self.oldLogLevel = None

        self.logHandler = logging.StreamHandler(self.buffer)
        formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
        self.logHandler.setFormatter(formatter)
        rootLogger.addHandler(self.logHandler)    

    def stopCapture(self):
        """ Stop capturing log output.

        @return: Collected log output as string
        """

        # Remove our handler
        rootLogger = logging.getLogger()        

        # Restore logging level (if any)
        if self.oldLogLevel:
            rootLogger.setLevel(self.oldLogLevel)

        rootLogger.removeHandler(self.logHandler)

        self.logHandler.flush()
        self.buffer.flush()

        return self.buffer.getvalue()

    def update(self):
        """ Process the form.

        Process the form, log the output and show the output to the user.
        """

        self.logs = None

        if "sync-now" in self.request.form:
            # Form button was pressed

            # Open Plone status messages interface for this request
            messages = IStatusMessage(self.request)

            try:
                self.startCapture(logging.DEBUG)

                logger.info("Starting full site synchronization")

                # Do the long running,
                # lots of logging stuff
                self.sync()    

                logger.info("Succesfully done")

                # It worked! Trolololo.
                messages.addStatusMessage("Sync done")

            except Exception, e:
                # Show friendly error message
                logger.exception(e)
                messages.addStatusMessage(u"It did not work out:" + unicode(e)) 

            finally:
                # Put log output for the page template access
                self.logs = self.stopCapture()
</pre>
<p>Related Zope page template:</p>
<pre>&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
 lang="en"
 metal:use-macro="here/main_template/macros/master"
 i18n:domain="xxx.objects"&gt;

 &lt;body&gt;
 &lt;div metal:fill-slot="main"&gt;
 &lt;tal:main-macro metal:define-macro="main"&gt;

 &lt;h1&gt;
 XXX site update
 &lt;/h1&gt;    

 &lt;p&gt;
 Update all researches from XXX
 &lt;/p&gt;

 &lt;div tal:condition="view/logs"&gt;
   &lt;p&gt;Sync results:&lt;/p&gt;
   &lt;pre tal:content="view/logs" /&gt;                 
 &lt;/div&gt;

 &lt;form action="@@syncall" method="POST"&gt;
   &lt;button type="submit" name="sync-now"&gt;
     Sync now
   &lt;/button&gt;
 &lt;/form&gt;         

 &lt;/tal:main-macro&gt;
 &lt;/div&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre>
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2011/02/23/temporarily-capturing-python-logging-output-to-a-string-buffer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Enhanced Apache logging: request duration, balancer member, transferred bytes</title>
		<link>http://blog.mfabrik.com/2010/12/21/enhanced-apache-logging-request-duration-balancer-member-transferred-bytes/</link>
		<comments>http://blog.mfabrik.com/2010/12/21/enhanced-apache-logging-request-duration-balancer-member-transferred-bytes/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 18:24:02 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[balancer]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=886</guid>
		<description><![CDATA[This helps you to diagnose problems on the production environment if you are running Apache or Apache mod_balancer. Put to your &#60;virtualhost&#62; # timestamp referer useragent, server time seconds/microseconds, transfered bytes input/output, which balancer was used LogFormat "%h %l %u %t \"%r\" %&#62;s %b \"%{Referer}i\" \"%{User-Agent}i\" duration:%T/%D io:%I/%O balancer:%{BALANCER_WORKER_NAME}e" TransferLog     /var/log/apache2/yoursite.log More info [...]]]></description>
			<content:encoded><![CDATA[<p>This helps you to diagnose problems on the production environment if you are running Apache or Apache mod_balancer. Put to your &lt;virtualhost&gt;</p>
<pre>
<div id="_mcePaste"># timestamp referer useragent, server time seconds/microseconds, transfered bytes input/output, which balancer was used</div>
<div id="_mcePaste">LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\" duration:%T/%D io:%I/%O balancer:%{BALANCER_WORKER_NAME}e"</div>
<div id="_mcePaste">TransferLog     /var/log/apache2/yoursite.log</div>

<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">More info</span></pre>
<ul>
<li><a href="http://www.ducea.com/2008/02/06/apache-logs-how-long-does-it-take-to-serve-a-request/">http://www.ducea.com/2008/02/06/apache-logs-how-long-does-it-take-to-serve-a-request/</a></li>
</ul>
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2010/12/21/enhanced-apache-logging-request-duration-balancer-member-transferred-bytes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logging with LogMan</title>
		<link>http://blog.mfabrik.com/2008/06/23/logging-with-logman/</link>
		<comments>http://blog.mfabrik.com/2008/06/23/logging-with-logman/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 14:55:58 +0000</pubDate>
		<dc:creator>Jussi Toivola</dc:creator>
				<category><![CDATA[development tools]]></category>
		<category><![CDATA[pys60]]></category>
		<category><![CDATA[symbian]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[logman]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rdebug]]></category>
		<category><![CDATA[s60]]></category>
		<category><![CDATA[serial]]></category>
		<category><![CDATA[series 60]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://blog.redinnovation.com/?p=48</guid>
		<description><![CDATA[This is my first post on our company blog and I thought I&#8217;d tell you something about LogMan, which is developer&#8217;s utility for getting logging messages from Symbian device over a USB cable. It is written by me and mostly on my own time. I started the project because I had to do a Symbian [...]]]></description>
			<content:encoded><![CDATA[<p>This is my first post on our company blog and I thought I&#8217;d tell you something about <a href="http://code.google.com/p/logman-for-symbian/">LogMan</a>, which is developer&#8217;s utility for getting logging messages from Symbian device over a USB cable. It is written by me and mostly on my own time. I started the project because I had to do a Symbian excercise for university course and I thought I&#8217;d do something useful instead of quickly tinkering something small and easy.</p>
<p>LogMan supports both C++ and Python. With LogMan, you can send data to the same location from Python and C++ in real-time instead of using log file(s). Browsing through multiple log files can be tedious and you can&#8217;t see the debug output while using your application, because on Symbian you must read the file after the debugging session &#8211; Symbian cannot share opened files between applications. It is also possible that you create too much log and you run out of Phone internal memory. LogMan helps by removing the use of log files and you never run out of disk space because messages can be stored directly to PC. On simulator, the messages are also sent to <a href="http://wiki.forum.nokia.com/index.php/How_to_use_RDebug">RDebug</a> (%TEMP%\epocwind.out). Surprisingly I have not seen a Python module, which would enable use of RDebug. Even though it is very easy to implement. With RDebug, there is no need to open a serial port on simulator for reading the logging messages.</p>
<p>Of course, I tried to use RDebug on device first, but I never got it working. I also tried <a href="http://www.forum.nokia.com/document/CDL_Extension_S60_3rd_Ed_FP2/GUID-C89505CF-D5FE-4C89-95D4-692443563021/html/classREcmt.html">REcmt</a>, which is supported on S60 only and the service just kept on crashing on my phone. This is why I decided to write LogMan. Plus both are closed software, which effectively prevented me from fixing the problems.</p>
<p>Just wondering what kind of benefit Symbian or Nokia gets from keeping development tools such as these closed? What is there so secret about them? It didn&#8217;t take me very long to write the first working version. *sigh*</p>
<p>The use of LogMan is similar to RDebug. There are static class methods, which are a bit slower but easier, and instance methods. Check the project&#8217;s <a href="http://code.google.com/p/logman-for-symbian/">homepage </a> for more examples.</p>
<p><code><br />
#include "LogMan.h" //RLogMan<br />
RLogMan::Log( _L("Hello world ") );<br />
</code></p>
<p>I recently added a new feature for LogMan, which allows you to log stack and heap usage of the current thread with one function. When you are unsure about your heap or stack usage, these might come handy. Of course there is some memory used when calling these so take that into consideration. Python can access MemoryInfo only, which logs both stack and heap (Well, I got a bit lazy at that point). There are equivalent macros for these, so check them out from &#8220;logmanutils.h&#8221;.</p>
<p><code><br />
// Store this as a member of your class, for example<br />
RLogMan logman;</code></p>
<p>logman.HeapInfo();<br />
logman.StackInfo();<br />
logman.MemoryInfo(); // Both stack and heap<br />
logman.Close();</p>
<p>The output from MemoryInfo is something like this:<br />
<code><br />
StackInfo<br />
Free:1039000, Used:9576, Size:1048576<br />
HeapInfo<br />
Free:25856, Used:101004, Size:126860<br />
</code></p>
<h2>Browser for PyS60</h2>
<p>I have been trying, unsuccessfully, to get Browser Control working on PyS60. In a nutshell, <a href="http://www.forum.nokia.com/document/Cpp_Developers_Library/GUID-96C272CA-2BED-4352-AE7C-E692B193EC06/html/classCBrCtlInterface.html">CBrCtlInterface</a> wrapper for Python. I have developed it against <a href="https://code.launchpad.net/~jussi-toivola/pys60community/browserbranch">PyS60Community</a> version in Launchpad. See /src/appui/appuifw/. I have used LogMan extensively to debug the extension so if you want a real example, check out &#8220;browsercontrol.cpp&#8221;.</p>
<p>Browser Control would allow one to embed a browser into his PyS60 application, which would be quite cool. No need to do user interfaces with &#8220;appuifw&#8221;, which is not very portable. With Browser Control, one could create his user interface with html and javascript, which are a lot more portable indeed. Less work leads to more time. And what is time?&#8230; it&#8217;s money. Or so I have heard. And being able to handle events with Python instead of C++ is another bonus.</p>
<p>Unfortunately, the API is not very stable as you can see by searching for &#8220;CBrCtlInterface&#8221; at Forum Nokia. The browser worked fine on the simulator with small pages such as &#8220;www.google.com&#8221;, but it crashed miserably with larger pages. The crash happens in browsercontrol.dll when calling e32.Ao_sleep() in Python. On device it was unable to open any page and crashed instantly when trying to load one. With LogMan, I was able to verify that the crash happened in e32.Ao_sleep() on device also. This reminds me to test on device all the time, which I didn&#8217;t do for the first versions. But this is why I added the memory logging feature to LogMan, but it only revealed that I was not out of stack or heap. At least not before the browser started to mess around.</p>
<p>I tried to compile the WebKit myself to see what is going on, but the build instructions didn&#8217;t work and the build scripts are written in Perl(my eyes started to hurt). What a mess. I don&#8217;t wonder anymore if there are bugs in browsercontrol.dll. I finally gave up because my idea pool dried up. Any help getting the wrapper working would be very much appreciated.</p>
<h2>Plans for LogMan</h2>
<p>I&#8217;m planning to add remote shell interface so that you could control your phone from PC. I want access to the file system first. Transfer files, list folders and such. If you have TCB rights ( or hacked phone ) you can speed up development remarkably by simply replacing your binaries in \sys\bin or your Python files with new versions. No need to install sis files and fiddle with certificates and play with memory cards. It would be so nice&#8230; I can use 1 day in a week for a personal project so this may happen in near future <img src='http://blog.mfabrik.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2008/06/23/logging-with-logman/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

