12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- ########################################################################
- # Searx-qt - Lightweight desktop application for SearX.
- # Copyright (C) 2020 CYBERDEViL
- #
- # This file is part of Searx-qt.
- #
- # Searx-qt is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # Searx-qt is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
- #
- ########################################################################
- import sys
- from datetime import datetime
- class LogLevels:
- QUIET = 0
- ERROR = 1 << 1
- WARNING = 1 << 2
- INFO = 1 << 3
- DEBUG = 1 << 4
- LogLevel = LogLevels.QUIET
- def outputMessageFactory(name, level, out=sys.stdout):
- def decorator(func):
- def wrap(msg, cls=None):
- if not (LogLevel & level):
- return
- if cls is None:
- cls = sys._getframe().f_back.f_code.co_name
- else:
- cls = cls.__module__
- print("{0} {1} <{2}>: {3}".format(
- datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
- name,
- cls,
- msg
- ), file=out
- )
- return wrap
- return decorator
- @outputMessageFactory('INFO', LogLevels.INFO, out=sys.stdout)
- def info(msg, cls=None):
- pass
- @outputMessageFactory('ERROR', LogLevels.ERROR, out=sys.stderr)
- def error(msg, cls=None):
- pass
- @outputMessageFactory('WARNING', LogLevels.WARNING, out=sys.stderr)
- def warning(msg, cls=None):
- pass
- @outputMessageFactory('DEBUG', LogLevels.DEBUG, out=sys.stderr)
- def debug(msg, cls=None):
- pass
|