Package pyrobase :: Module logutil
[hide private]
[frames] | no frames]

Source Code for Module pyrobase.logutil

 1  # -*- coding: utf-8 -*- 
 2  """ Logging Support. 
 3   
 4      Copyright (c) 2011 The PyroScope Project <pyroscope.project@gmail.com> 
 5  """ 
 6  # This program 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 2 of the License, or 
 9  # (at your option) any later version. 
10  # 
11  # This program 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. 
15  # 
16  # You should have received a copy of the GNU General Public License along 
17  # with this program; if not, write to the Free Software Foundation, Inc., 
18  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
19  import logging 
20   
21  # Maximum length of object representations 
22  MAX_DISPLAY_LEN = 99 
23   
24   
25 -def shorten(text):
26 """ Reduce text length for displaying / logging purposes. 27 """ 28 if len(text) >= MAX_DISPLAY_LEN: 29 text = text[:MAX_DISPLAY_LEN//2]+"..."+text[-MAX_DISPLAY_LEN//2:] 30 return text
31 32
33 -def get_logfile(logger=None):
34 """ Return log file of first file handler associated with the (root) logger. 35 None if no such handler is found. 36 """ 37 logger = logger or logging.getLogger() 38 handlers = [i for i in logger.handlers if isinstance(i, logging.FileHandler)] 39 return handlers[0].baseFilename if handlers else None
40