Update the UI more efficiently, make it much faster
[gpodder.git] / src / gpodder / liblogger.py
blobf1eafe812cd0a1cd3cbdcb6f23c0d788bbfd60c9
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
26 import traceback
27 import time
29 write_to_stdout = False
32 def enable_verbose():
33 global write_to_stdout
34 write_to_stdout = True
36 first_time = time.time()
37 last_times = []
39 def log( message, *args, **kwargs):
40 global first_time
41 global last_times
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())))
48 if write_to_stdout:
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':
53 print error
56 def msg( type, message, *args):
57 s = message % args
58 print '%c\t%s' % ( type[0].upper(), s )