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 from logging.handlers import RotatingFileHandler
20 class RestLogger(object):
21 def __init__(self, config):
22 self.logger = logging.getLogger("AM")
23 self.logger.setLevel(config["Logging"]["loglevel"])
24 self.filehandler = self._get_filehandler(config["Logging"]["logdir"]+"/am.log")
25 self.logger.addHandler(self.filehandler)
28 def _get_filehandler(filename):
29 rfh = RotatingFileHandler(filename, mode='a', maxBytes=1000000, backupCount=10, encoding=None, delay=0)
30 formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(name)s:%(pathname)s:%(funcName)s:%(lineno)d:%(message)s')
31 rfh.setFormatter(formatter)
37 def get_handler(self):
38 return self.filehandler
40 def get_logger(config):
43 restlogger = RestLogger(config)
44 return restlogger.get_logger()
46 def get_log_handler(config):
49 restlogger = RestLogger(config)
50 return restlogger.get_handler()