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.
17 import logging.handlers
21 class RestfulLogger(object):
23 self.logger = logging.getLogger("Restfulserver")
24 self.logger.setLevel(logging.DEBUG)
25 # werkzug logs out endpoint in DEBUG level, and aaa feature endpoint contains password
26 # in clear text, so log level setting is needed to avoid showing password in journalctl
27 logging.getLogger('werkzeug').setLevel(logging.WARNING)
29 self.sysloghandler = self._get_syslog_handler()
30 self.handlers.append(self.sysloghandler)
34 handlers = self.logger.handlers[:]
35 for handler in handlers:
37 self.logger.removeHandler(handler)
40 def _get_syslog_handler():
41 sh = logging.handlers.SysLogHandler(address='/dev/log')
42 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
43 sh.setFormatter(formatter)
44 sh.setLevel(logging.NOTSET)
47 def _add_handlers(self):
48 for handler in self.handlers:
49 self.logger.addHandler(handler)
51 def get_handlers(self):
60 restlogger = RestfulLogger()
61 return restlogger.get_logger()
63 def get_log_handlers():
66 restlogger = RestfulLogger()
67 return restlogger.get_handlers()