1# Copyright (c) 2017-2021 Cedric Bellegarde <cedric.bellegarde@adishatz.org> 2# Copyright (c) 2017 Bilal Elmoussaoui <bil.elmoussaoui@gmail.com> 3# This program is free software: you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation, either version 3 of the License, or 6# (at your option) any later version. 7# This program is distributed in the hope that it will be useful, 8# but WITHOUT ANY WARRANTY; without even the implied warranty of 9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10# GNU General Public License for more details. 11# You should have received a copy of the GNU General Public License 12# along with this program. If not, see <http://www.gnu.org/licenses/>. 13 14import logging 15import sys 16 17from eolie.define import App 18 19 20class Logger: 21 """ 22 Logger class. 23 """ 24 FORMAT = "[%(levelname)-s] %(asctime)s %(message)s" 25 DATE = "%Y-%m-%d %H:%M:%S" 26 __log = None 27 APP = "org.gnome.Eolie" 28 29 @staticmethod 30 def get_default(): 31 """ 32 Return default instance of Logger 33 @return Logger 34 """ 35 if Logger.__log is None: 36 logger = logging.getLogger(Logger.APP) 37 38 handler = logging.StreamHandler(sys.stdout) 39 formater = logging.Formatter(Logger.FORMAT, Logger.DATE) 40 handler.setFormatter(formater) 41 logger.addHandler(handler) 42 logger.setLevel(logging.DEBUG) 43 44 Logger.__log = logging.getLogger(Logger.APP) 45 return Logger.__log 46 47 @staticmethod 48 def warning(msg, *args): 49 """ 50 Log warning message 51 @parma msg as str 52 """ 53 Logger.get_default().warning(msg, *args) 54 55 @staticmethod 56 def debug(msg, *args): 57 """ 58 Log debug message 59 @parma msg as str 60 """ 61 if App().settings.get_value("debug"): 62 Logger.get_default().debug(msg, *args) 63 64 @staticmethod 65 def sync_debug(msg, *args): 66 """ 67 Log debug sync message 68 @parma msg as str 69 """ 70 if App().settings.get_value("debug-sync"): 71 Logger.get_default().debug(msg, *args) 72 73 @staticmethod 74 def info(msg, *args): 75 """ 76 Log info message 77 @parma msg as str 78 """ 79 Logger.get_default().info(msg, *args) 80 81 @staticmethod 82 def error(msg, *args): 83 """ 84 Log error message 85 @parma msg as str 86 """ 87 Logger.get_default().error(msg, *args) 88