1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2008 Thomas Perl and the gPodder Team
6 # gPodder is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # liblogger.py -- gPodder logging facility
22 # Thomas Perl <thp perli net> 20061117
29 write_to_stdout
= False
33 global write_to_stdout
34 write_to_stdout
= True
36 first_time
= time
.time()
39 def log( message
, *args
, **kwargs
):
42 if 'sender' in kwargs
:
43 message
= '(%s) %s' % ( kwargs
['sender'].__class
__.__name
__, message
)
44 if 'bench_start' in kwargs
:
45 last_times
.append(time
.time())
46 if 'bench_end' in kwargs
and len(last_times
) > 0:
47 message
+= (' (benchmark: %.4f seconds)' % (time
.time()-(last_times
.pop())))
49 print (('[%8.3f] ' % (time
.time()-first_time
)) + message
) % args
50 if kwargs
.get( 'traceback', False):
51 error
= traceback
.format_exc()
52 if error
.strip() != 'None':
56 def msg( type, message
, *args
):
58 print '%c\t%s' % ( type[0].upper(), s
)