[melbourne-pug] logging in python

Teguh Iskanto tiskanto at gmail.com
Fri Feb 12 05:00:22 CET 2010


Try "logging" , for info : 'pydoc logging'
It comes as a default from python installation and it's a thread-safe module
as I've used this in the production environment

here's a sample that I've used ( I use this as a module to log all the
thread-worker )
-----------------8<-------------------
import logging
import time

# Global Params
log_level       = logging.DEBUG
log_format     = '%(asctime)s.%(msecs)03d : %(module)s - %(threadName)s -
%(message)s'
date_format     = '%a, %Y-%m-%d %H:%M:%S'
file_name       = '/tmp/NOA.log'
file_mode       = 'a'

logging.basicConfig( \
        level           = log_level, \
        format          = log_format, \
        datefmt         = date_format, \
        filename        = file_name, \
        filemode        = file_mode )

-----------------8<-------------------

sample output :

Tue, 2008-11-11 08:49:58.442 : NOA - [JobNum: 327] [ACTION: forking] [fork
index: 0] [status: contacting cma 145.136.50.153]
Tue, 2008-11-11 08:49:58.466 : NOA - [JobNum: 327] [ACTION: forking] [fork
index: 1] [status: contacting cma 145.136.50.154]
Tue, 2008-11-11 08:49:59.340 : NOA - [JobNum: 327] [session:
Thread-5_145.136.50.153_JobNum_327] [status: connected]
Tue, 2008-11-11 08:49:59.392 : NOA - [JobNum: 327] [session:
Thread-6_145.136.50.154_JobNum_327] [status: connected]
Tue, 2008-11-11 08:49:59.392 : NOA - [JobNum: 327] [ACTION:
pre_connection_test] [status: successful]
Tue, 2008-11-11 08:49:59.504 : network - [JobNum: 327] [ACTION: db_edit ->
del] [session: Thread-7_145.136.50.153_JobNum_327_del_networ
k] [obj: cuuuuuustomeeeeeeeeeeeer-net-12.21.12.21-2_FAIL] [result: NOT
successful] [reason: OBJECT NOT FOUND]
Tue, 2008-11-11 08:49:59.504 : network - [JobNum: 327] [ACTION: db_edit ->
del] [session: Thread-8_145.136.50.154_JobNum_327_del_networ
k] [obj: cuuuuuustomeeeeeeeeeeeer-net-12.21.12.21-2_FAIL] [result: NOT
successful] [reason: OBJECT NOT FOUND]
Tue, 2008-11-11 08:50:00.341 : network - [JobNum: 327] [ACTION:
final_del_act] [result: NOT successful]
Tue, 2008-11-11 08:50:00.341 : NOA -
Tue, 2008-11-11 08:50:00.341 : NOA - [JobNum: 332] [ACTION: get_object]
[TNAME:services] [TYPE:other_service] [ACT:del] - cma : [u'145.
136.50.153', u'145.136.50.154']
Tue, 2008-11-11 08:50:00.376 : NOA - [JobNum: 332] [ACTION: forking] [fork
index: 0] [status: contacting cma 145.136.50.153]
Tue, 2008-11-11 08:50:00.410 : NOA - [JobNum: 332] [ACTION: forking] [fork
index: 1] [status: contacting cma 145.136.50.154]
Tue, 2008-11-11 08:50:01.400 : NOA - [JobNum: 332] [session:
Thread-9_145.136.50.153_JobNum_332] [status: connected]
Tue, 2008-11-11 08:50:01.407 : NOA - [JobNum: 332] [session:
Thread-10_145.136.50.154_JobNum_332] [status: connected]
Tue, 2008-11-11 08:50:01.408 : NOA - [JobNum: 332] [ACTION:
pre_connection_test] [status: successful]



Cheers,
Teguh Iskanto



On Tue, Feb 9, 2010 at 7:48 AM, Rory Hart <hartror at gmail.com> wrote:

> I've used Twisted's logging in production with great success.
>
> http://twistedmatrix.com/documents/current/core/howto/logging.html
>
>
> On Sun, Feb 7, 2010 at 8:43 PM, Richard Jones <r1chardj0n3s at gmail.com>wrote:
>
>> No, I only wish I could :)
>>
>>
>>      Richard
>>
>> On 08/02/2010, at 3:30 PM, James Alford wrote:
>>
>> > Richard, have you used this at a production level?
>> >
>> > The readme mentions that it is not stable.
>> >
>> > On Mon, Feb 8, 2010 at 3:24 PM, James Alford <mydnite1 at gmail.com>
>> wrote:
>> >> Excellent.
>> >>
>> >> Thanks mate.
>> >>
>> >> On Mon, Feb 8, 2010 at 2:46 PM, Richard Jones <r1chardj0n3s at gmail.com>
>> wrote:
>> >>> On 08/02/2010, at 2:24 PM, James Alford wrote:
>> >>>> There was a talk at one of the mpug meet ups last year about logging
>> >>>> in python, I happened to be a bit late and only caught the end of it.
>> >>>>
>> >>>> I can't seem to find the talk on the wiki, can someone please point
>> me
>> >>>> in the right direction.  Thanks
>> >>>
>> >>> That was me, blathering on about Lumberjack:
>> >>>
>> >>> http://code.zacharyvoase.com/lumberjack/src/tip/README
>> >>>
>> >>>
>> >>>      Richard
>> >>>
>> >>> _______________________________________________
>> >>> melbourne-pug mailing list
>> >>> melbourne-pug at python.org
>> >>> http://mail.python.org/mailman/listinfo/melbourne-pug
>> >>>
>> >>
>> > _______________________________________________
>> > melbourne-pug mailing list
>> > melbourne-pug at python.org
>> > http://mail.python.org/mailman/listinfo/melbourne-pug
>>
>> _______________________________________________
>> melbourne-pug mailing list
>> melbourne-pug at python.org
>> http://mail.python.org/mailman/listinfo/melbourne-pug
>>
>
>
>
> --
> Rory Hart
> http://www.whatisthescience.com
> http://blog.roryhart.net
>
> _______________________________________________
> melbourne-pug mailing list
> melbourne-pug at python.org
> http://mail.python.org/mailman/listinfo/melbourne-pug
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/melbourne-pug/attachments/20100212/e17abfce/attachment.htm>


More information about the melbourne-pug mailing list