3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 Logging configuration for rpm builder
22 def configure_logging(verbose=False, debugfile="debug.log"):
23 """ Logging to screen(console) and file """
25 debugfile_dirname = os.path.dirname(debugfile)
26 if not os.path.isdir(debugfile_dirname):
27 os.mkdir(debugfile_dirname)
29 logging.basicConfig(level=logging.DEBUG,
30 format='%(asctime)s %(levelname)s: %(message)s',
33 # define a Handler which writes INFO messages or higher to the sys.stderr
34 console = logging.StreamHandler(stream=sys.stdout)
36 console.setLevel(logging.DEBUG)
38 console.setLevel(logging.INFO)
39 # set a format which is simpler for console use
40 formatter = logging.Formatter('%(levelname)s: %(message)s')
41 # tell the handler to use this format
42 console.setFormatter(formatter)
43 # add the handler to the root log
44 logging.getLogger('').addHandler(console)