OpenShot Video Editor  2.0.0
logger.py
Go to the documentation of this file.
1 ##
2 #
3 # @file
4 # @brief This file sets the default logging settings
5 # @author Noah Figg <eggmunkee@hotmail.com>
6 # @author Jonathan Thomas <jonathan@openshot.org>
7 #
8 # @section LICENSE
9 #
10 # Copyright (c) 2008-2016 OpenShot Studios, LLC
11 # (http://www.openshotstudios.com). This file is part of
12 # OpenShot Video Editor (http://www.openshot.org), an open-source project
13 # dedicated to delivering high quality video editing and animation solutions
14 # to the world.
15 #
16 # OpenShot Video Editor is free software: you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation, either version 3 of the License, or
19 # (at your option) any later version.
20 #
21 # OpenShot Video Editor is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
28 #
29 
30 import logging
31 import os, sys
32 from logging.handlers import RotatingFileHandler
33 from classes import info
34 
35 
36 ##
37 # Custom class to log all stdout and stderr streams (from libopenshot / and other libraries)
39  def __init__(self, logger, log_level=logging.INFO):
40  self.logger = logger
41  self.log_level = log_level
42  self.linebuf = ''
43 
44  def write(self, buf):
45  for line in buf.rstrip().splitlines():
46  self.logger.log(self.log_level, line.rstrip())
47 
48  def flush(self):
49  pass
50 
51  def errors(self):
52  pass
53 
54 # Initialize logging module, give basic formats and level we want to report
55 logging.basicConfig(format="%(module)12s:%(levelname)s %(message)s",
56  datefmt='%H:%M:%S',
57  level=logging.INFO)
58 
59 # Create a formatter
60 formatter = logging.Formatter('%(module)12s:%(levelname)s %(message)s')
61 
62 # Get logger instance & set level
63 log = logging.getLogger('OpenShot')
64 log.setLevel(logging.INFO)
65 
66 # Add rotation file handler
67 fh = RotatingFileHandler(
68  os.path.join(info.USER_PATH, 'openshot-qt.log'), encoding="utf-8", maxBytes=25*1024*1024, backupCount=3)
69 fh.setFormatter(formatter)
70 log.addHandler(fh)
71 
72 # Route stdout and stderr to logger (custom handler)
73 if not getattr(sys, 'frozen', False):
74  so = StreamToLogger(log, logging.INFO)
75  sys.stdout = so
76 
77  se = StreamToLogger(log, logging.ERROR)
78  sys.stderr = se
79 
def write(self, buf)
Definition: logger.py:44
def errors(self)
Definition: logger.py:51
def __init__(self, logger, log_level=logging.INFO)
Definition: logger.py:39
def flush(self)
Definition: logger.py:48
Custom class to log all stdout and stderr streams (from libopenshot / and other libraries) ...
Definition: logger.py:38