.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx Namespace Reference

Namespaces

namespace  answerers
 
namespace  autocomplete
 
namespace  babel_extract
 
namespace  botdetection
 
namespace  compat
 
namespace  data
 
namespace  enginelib
 
namespace  engines
 ::1337x
 
namespace  exceptions
 
namespace  extended_types
 
namespace  external_bang
 
namespace  external_urls
 
namespace  favicons
 
namespace  flaskfix
 
namespace  infopage
 
namespace  limiter
 
namespace  locales
 
namespace  metrics
 
namespace  network
 
namespace  openmetrics
 
namespace  plugins
 
namespace  preferences
 
namespace  query
 
namespace  redisdb
 
namespace  redislib
 
namespace  result_types
 
namespace  results
 
namespace  search
 
namespace  settings_defaults
 
namespace  settings_loader
 
namespace  sqlitedb
 
namespace  sxng_locales
 
namespace  unixthreadname
 
namespace  utils
 
namespace  version
 
namespace  webadapter
 
namespace  webapp
 
namespace  webutils
 

Functions

 init_settings ()
 
 get_setting (name, default=_unset)
 
 _is_color_terminal ()
 
 _logging_config_debug ()
 

Variables

str LOG_FORMAT_DEBUG = '%(levelname)-7s %(name)-30.30s: %(message)s'
 
str LOG_FORMAT_PROD = '%(asctime)-15s %(levelname)s:%(name)s: %(message)s'
 
 LOG_LEVEL_PROD = logging.WARNING
 
 searx_dir = abspath(dirname(__file__))
 
 searx_parent_dir = abspath(dirname(dirname(__file__)))
 
dict settings = {}
 
bool searx_debug = False
 
 logger = logging.getLogger('searx')
 
 _unset = object()
 

Function Documentation

◆ _is_color_terminal()

searx._is_color_terminal ( )
protected

Definition at line 90 of file __init__.py.

90def _is_color_terminal():
91 if os.getenv('TERM') in ('dumb', 'unknown'):
92 return False
93 return sys.stdout.isatty()
94
95

Referenced by _logging_config_debug().

+ Here is the caller graph for this function:

◆ _logging_config_debug()

searx._logging_config_debug ( )
protected

Definition at line 96 of file __init__.py.

96def _logging_config_debug():
97 try:
98 import coloredlogs # pylint: disable=import-outside-toplevel
99 except ImportError:
100 coloredlogs = None
101
102 log_level = os.environ.get('SEARXNG_DEBUG_LOG_LEVEL', 'DEBUG')
103 if coloredlogs and _is_color_terminal():
104 level_styles = {
105 'spam': {'color': 'green', 'faint': True},
106 'debug': {},
107 'notice': {'color': 'magenta'},
108 'success': {'bold': True, 'color': 'green'},
109 'info': {'bold': True, 'color': 'cyan'},
110 'warning': {'color': 'yellow'},
111 'error': {'color': 'red'},
112 'critical': {'bold': True, 'color': 'red'},
113 }
114 field_styles = {
115 'asctime': {'color': 'green'},
116 'hostname': {'color': 'magenta'},
117 'levelname': {'color': 8},
118 'name': {'color': 8},
119 'programname': {'color': 'cyan'},
120 'username': {'color': 'yellow'},
121 }
122 coloredlogs.install(level=log_level, level_styles=level_styles, field_styles=field_styles, fmt=LOG_FORMAT_DEBUG)
123 else:
124 logging.basicConfig(level=logging.getLevelName(log_level), format=LOG_FORMAT_DEBUG)
125
126

References _is_color_terminal(), and init_settings().

Referenced by init_settings().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_setting()

searx.get_setting ( name,
default = _unset )
Returns the value to which ``name`` point.  If there is no such name in the
settings and the ``default`` is unset, a :py:obj:`KeyError` is raised.

Definition at line 69 of file __init__.py.

69def get_setting(name, default=_unset):
70 """Returns the value to which ``name`` point. If there is no such name in the
71 settings and the ``default`` is unset, a :py:obj:`KeyError` is raised.
72
73 """
74 value = settings
75 for a in name.split('.'):
76 if isinstance(value, dict):
77 value = value.get(a, _unset)
78 else:
79 value = _unset
80
81 if value is _unset:
82 if default is _unset:
83 raise KeyError(name)
84 value = default
85 break
86
87 return value
88
89

Referenced by searx.favicons.proxy._initial_resolver_map(), searx.webapp.config(), searx.webapp.custom_url_for(), searx.webapp.get_client_settings(), searx.plugins.ahmia_filter.init(), searx.redisdb.initialize(), searx.favicons.is_active(), searx.plugins._core.PluginStorage.load_builtins(), searx.webapp.preferences(), searx.network.raise_for_httperror.raise_for_cloudflare_captcha(), searx.network.raise_for_httperror.raise_for_recaptcha(), searx.webapp.render(), and searx.redislib.secret_hash().

+ Here is the caller graph for this function:

◆ init_settings()

searx.init_settings ( )
Initialize global ``settings`` and ``searx_debug`` variables and
``logger`` from ``SEARXNG_SETTINGS_PATH``.

Definition at line 31 of file __init__.py.

31def init_settings():
32 """Initialize global ``settings`` and ``searx_debug`` variables and
33 ``logger`` from ``SEARXNG_SETTINGS_PATH``.
34 """
35
36 global settings, searx_debug # pylint: disable=global-variable-not-assigned
37
38 cfg, msg = searx.settings_loader.load_settings(load_user_settings=True)
39 cfg = cfg or {}
40 apply_schema(cfg, SCHEMA, [])
41
42 settings.clear()
43 settings.update(cfg)
44
45 searx_debug = settings['general']['debug']
46 if searx_debug:
47 _logging_config_debug()
48 else:
49 logging.basicConfig(level=LOG_LEVEL_PROD, format=LOG_FORMAT_PROD)
50 logging.root.setLevel(level=LOG_LEVEL_PROD)
51 logging.getLogger('werkzeug').setLevel(level=LOG_LEVEL_PROD)
52 logger.info(msg)
53
54 # log max_request_timeout
55 max_request_timeout = settings['outgoing']['max_request_timeout']
56 if max_request_timeout is None:
57 logger.info('max_request_timeout=%s', repr(max_request_timeout))
58 else:
59 logger.info('max_request_timeout=%i second(s)', max_request_timeout)
60
61 if settings['server']['public_instance']:
62 logger.warning(
63 "Be aware you have activated features intended only for public instances. "
64 "This force the usage of the limiter and link_token / "
65 "see https://docs.searxng.org/admin/searx.limiter.html"
66 )
67
68
tuple[dict, str] load_settings(load_user_settings=True)

References _logging_config_debug(), and searx.settings_loader.load_settings().

Referenced by _logging_config_debug().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ _unset

searx._unset = object()
protected

Definition at line 28 of file __init__.py.

◆ LOG_FORMAT_DEBUG

str searx.LOG_FORMAT_DEBUG = '%(levelname)-7s %(name)-30.30s: %(message)s'

Definition at line 15 of file __init__.py.

◆ LOG_FORMAT_PROD

str searx.LOG_FORMAT_PROD = '%(asctime)-15s %(levelname)s:%(name)s: %(message)s'

Definition at line 18 of file __init__.py.

◆ LOG_LEVEL_PROD

searx.LOG_LEVEL_PROD = logging.WARNING

Definition at line 19 of file __init__.py.

◆ logger

searx.logger = logging.getLogger('searx')

Definition at line 26 of file __init__.py.

◆ searx_debug

bool searx.searx_debug = False

Definition at line 25 of file __init__.py.

◆ searx_dir

searx.searx_dir = abspath(dirname(__file__))

Definition at line 21 of file __init__.py.

◆ searx_parent_dir

searx.searx_parent_dir = abspath(dirname(dirname(__file__)))

Definition at line 22 of file __init__.py.

◆ settings

dict searx.settings = {}

Definition at line 24 of file __init__.py.