1 #!/usr/bin/python 2 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style license that can be 4 # found in the LICENSE file. 5 6 import logging 7 import sys 8 9 LOG_FORMAT = ' %(name)s - %(filename)s - %(lineno)d- %(message)s' 10 11 12 def SetupCellularLogging(logger_name, format_string=LOG_FORMAT): 13 """ 14 logger_name: The name of the logger. This name can be used across files 15 to access the same logger. 16 format_string: The format of the log message this logger prints. 17 returns: a log object that may be used : 18 log.debug('Print this at the debug level ') 19 """ 20 log = logging.getLogger(logger_name) 21 log.setLevel(logging.DEBUG) 22 ch = logging.StreamHandler(sys.stdout) 23 ch.setLevel(logging.DEBUG) 24 formatter = logging.Formatter(format_string) 25 ch.setFormatter(formatter) 26 log.handlers = [ch] 27 log.propagate = False 28 return log 29