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