6from os.path
import dirname, abspath
16LOG_FORMAT_DEBUG =
'%(levelname)-7s %(name)-30.30s: %(message)s'
19LOG_FORMAT_PROD =
'%(asctime)-15s %(levelname)s:%(name)s: %(message)s'
20LOG_LEVEL_PROD = logging.WARNING
22searx_dir = abspath(dirname(__file__))
23searx_parent_dir = abspath(dirname(dirname(__file__)))
26if settings
is not None:
27 settings = settings_set_defaults(settings)
33 """Returns the value to which ``name`` point. If there is no such name in the
34 settings and the ``default`` is unset, a :py:obj:`KeyError` is raised.
38 for a
in name.split(
'.'):
39 if isinstance(value, dict):
40 value = value.get(a, _unset)
54 if os.getenv(
'TERM')
in (
'dumb',
'unknown'):
56 return sys.stdout.isatty()
65 log_level = os.environ.get(
'SEARXNG_DEBUG_LOG_LEVEL',
'DEBUG')
68 'spam': {
'color':
'green',
'faint':
True},
70 'notice': {
'color':
'magenta'},
71 'success': {
'bold':
True,
'color':
'green'},
72 'info': {
'bold':
True,
'color':
'cyan'},
73 'warning': {
'color':
'yellow'},
74 'error': {
'color':
'red'},
75 'critical': {
'bold':
True,
'color':
'red'},
78 'asctime': {
'color':
'green'},
79 'hostname': {
'color':
'magenta'},
80 'levelname': {
'color': 8},
82 'programname': {
'color':
'cyan'},
83 'username': {
'color':
'yellow'},
85 coloredlogs.install(level=log_level, level_styles=level_styles, field_styles=field_styles, fmt=LOG_FORMAT_DEBUG)
87 logging.basicConfig(level=logging.getLevelName(log_level), format=LOG_FORMAT_DEBUG)
90searx_debug = settings[
'general'][
'debug']
94 logging.basicConfig(level=LOG_LEVEL_PROD, format=LOG_FORMAT_PROD)
95 logging.root.setLevel(level=LOG_LEVEL_PROD)
96 logging.getLogger(
'werkzeug').setLevel(level=LOG_LEVEL_PROD)
97logger = logging.getLogger(
'searx')
98logger.info(settings_load_message)
101max_request_timeout = settings[
'outgoing'][
'max_request_timeout']
102if max_request_timeout
is None:
103 logger.info(
'max_request_timeout=%s', repr(max_request_timeout))
105 logger.info(
'max_request_timeout=%i second(s)', max_request_timeout)
107if settings[
'server'][
'public_instance']:
109 "Be aware you have activated features intended only for public instances. "
110 "This force the usage of the limiter and link_token / "
111 "see https://docs.searxng.org/admin/searx.limiter.html"
tuple[dict, str] load_settings(load_user_settings=True)
get_setting(name, default=_unset)