We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
All logging messages produced in ray actors have 'ERROR' level
At this moment, all log messages produced in ray actor came with 'ERROR' level. There are two issues because this:
1. db grow quick.
2. with sqllite as db is many errors related to db lock, especially of start several learn processes.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mindsdb/utilities/log.py`
Content:
```
1 import os
2 import sys
3 import logging
4 import traceback
5 
6 from mindsdb.interfaces.storage.db import session, Log
7 from mindsdb.utilities.config import Config
8 
9 telemtry_enabled = os.getenv('CHECK_FOR_UPDATES', '1').lower() not in ['0', 'false', 'False']
10 global_config = Config().get_all()
11 
12 if telemtry_enabled:
13     import sentry_sdk
14     from sentry_sdk import capture_exception, capture_message, add_breadcrumb
15     sentry_sdk.init(
16         "https://29e64dbdf325404ebf95473d5f4a54d3@o404567.ingest.sentry.io/5633566",
17         traces_sample_rate=0 #Set to `1` to experiment with performance metrics
18     )
19 
20 class LoggerWrapper(object):
21     def __init__(self, writer_arr, default_writer_pos):
22         self._writer_arr = writer_arr
23         self.default_writer_pos = default_writer_pos
24 
25     def write(self, message):
26         if 'DEBUG:' in message:
27             self._writer_arr[0](message)
28         elif 'INFO:' in message:
29             self._writer_arr[1](message)
30         elif 'WARNING:' in message:
31             self._writer_arr[2](message)
32         elif 'ERROR:' in message:
33             self._writer_arr[3](message)
34         else:
35             self._writer_arr[self.default_writer_pos](message)
36 
37     def flush(self):
38         pass
39 
40 class DbHandler(logging.Handler):
41     def __init__(self):
42         logging.Handler.__init__(self)
43         self.company_id = os.environ.get('MINDSDB_COMPANY_ID', None)
44 
45     def emit(self, record):
46         log_type = record.levelname
47         source = f'file: {record.pathname} - line: {record.lineno}'
48         payload = record.msg
49 
50         if telemtry_enabled:
51             pass
52             # @TODO: Enable once we are sure no sensitive info is being outputed in the logs
53             # if log_type in ['INFO']:
54             #    add_breadcrumb(
55             #        category='auth',
56             #        message=str(payload),
57             #        level='info',
58             #    )
59             # Might be too much traffic if we send this for users with slow networks
60             #if log_type in ['DEBUG']:
61             #    add_breadcrumb(
62             #        category='auth',
63             #        message=str(payload),
64             #        level='debug',
65             #    )
66 
67         if log_type in ['ERROR', 'WARNING']:
68             trace = str(traceback.format_stack(limit=20))
69             trac_log = Log(log_type='traceback', source=source, payload=trace, company_id=self.company_id)
70             session.add(trac_log)
71             session.commit()
72 
73             if telemtry_enabled:
74                 add_breadcrumb(
75                     category='stack_trace',
76                     message=trace,
77                     level='info',
78                 )
79                 if log_type in ['ERROR']:
80                     capture_message(str(payload))
81                 if log_type in ['WARNING']:
82                     capture_message(str(payload))
83 
84         log = Log(log_type=str(log_type), source=source, payload=str(payload), company_id=self.company_id)
85         session.add(log)
86         session.commit()
87 
88 def fmt_log_record(log_record):
89   return {
90     'log_from': 'mindsdb',
91     'level': log_record.log_type,
92     'context': 'unkown',
93     'text': log_record.payload,
94     'created_at': str(log_record.created_at).split('.')[0]
95   }
96 
97 def get_logs(min_timestamp, max_timestamp, context, level, log_from, limit):
98     logs = session.query(Log).filter(Log.company_id==os.environ.get('MINDSDB_COMPANY_ID', None), Log.created_at>min_timestamp)
99 
100     if max_timestamp is not None:
101         logs = logs.filter(Log.created_at<max_timestamp)
102 
103     if context is not None:
104         # e.g. datasource/predictor and assoicated id
105         pass
106 
107     if level is not None:
108         logs = logs.filter(Log.log_type==level)
109 
110     if log_from is not None:
111         # mindsdb/native/lightwood/all
112         pass
113 
114     if limit is not None:
115         logs = logs.limit(limit)
116 
117     logs = [fmt_log_record(x) for x in logs]
118     return logs
119 
120 def initialize_log(config=global_config, logger_name='main', wrap_print=False):
121     ''' Create new logger
122     :param config: object, app config
123     :param logger_name: str, name of logger
124     :param wrap_print: bool, if true, then print() calls will be wrapped by log.debug() function.
125     '''
126     log = logging.getLogger(f'mindsdb.{logger_name}')
127     log.propagate = False
128     log.setLevel(min(
129         getattr(logging, config['log']['level']['console']),
130         getattr(logging, config['log']['level']['file'])
131     ))
132 
133     formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
134 
135     ch = logging.StreamHandler()
136     ch.setLevel(config['log']['level']['console']) # that level will be in console
137     log.addHandler(ch)
138     db_handler = DbHandler()
139     log.addHandler(db_handler)
140 
141     if wrap_print:
142         sys.stdout = LoggerWrapper([log.debug, log.info, log.warning, log.error], 1)
143         sys.stderr = LoggerWrapper([log.debug, log.info, log.warning, log.error], 3)
144 
145     return log
146 
147 
148 def get_log(logger_name=None):
149     if logger_name is None:
150         return logging.getLogger('mindsdb')
151     return logging.getLogger(f'mindsdb.{logger_name}')
152 
153 
154 log = initialize_log()
155
```

Path: `mindsdb/__init__.py`
Content:
```
1 import os
2 import sys
3 import json
4 
5 from mindsdb.__about__ import __package_name__ as name, __version__   # noqa
6 from mindsdb.utilities.fs import get_or_create_dir_struct, create_dirs_recursive
7 from mindsdb.utilities.functions import args_parse, is_notebook
8 from mindsdb.__about__ import __version__ as mindsdb_version
9 from mindsdb.utilities.telemetry import telemetry_file_exists, disable_telemetry
10 
11 is_ray_worker = False
12 if '-ray' in str(sys.argv):
13     is_ray_worker = True
14 
15 if not is_ray_worker:
16     try:
17         if not is_notebook():
18             args = args_parse()
19         else:
20             args = None
21     except Exception:
22         # This fials in some notebooks ... check above for is_notebook is still needed because even if the exception is caught trying to read the arg still leads to failure in other notebooks... notebooks a
23         args = None
24 
25     # ---- CHECK SYSTEM ----
26     if not (sys.version_info[0] >= 3 and sys.version_info[1] >= 6):
27         print("""
28     MindsDB server requires Python >= 3.6 to run
29 
30     Once you have Python 3.6 installed you can tun mindsdb as follows:
31 
32     1. create and activate venv:
33     python3.6 -m venv venv
34     source venv/bin/activate
35 
36     2. install MindsDB:
37     pip3 install mindsdb
38 
39     3. Run MindsDB
40     python3.6 -m mindsdb
41 
42     More instructions in https://docs.mindsdb.com
43         """)
44         exit(1)
45 
46     # --- VERSION MODE ----
47     if args is not None and args.version:
48         print(f'MindsDB {mindsdb_version}')
49         sys.exit(0)
50 
51     # --- MODULE OR LIBRARY IMPORT MODE ----
52     if args is not None and args.config is not None:
53         config_path = args.config
54         with open(config_path, 'r') as fp:
55             user_config = json.load(fp)
56     else:
57         user_config = {}
58         config_path = 'absent'
59     os.environ['MINDSDB_CONFIG_PATH'] = config_path
60 
61     if 'storage_dir' in user_config:
62         root_storage_dir = user_config['storage_dir']
63         os.environ['MINDSDB_STORAGE_DIR'] = root_storage_dir
64     elif os.environ.get('MINDSDB_STORAGE_DIR') is not None:
65         root_storage_dir = os.environ['MINDSDB_STORAGE_DIR']
66     else:
67         _, root_storage_dir = get_or_create_dir_struct()
68         os.environ['MINDSDB_STORAGE_DIR'] = root_storage_dir
69 
70     if os.path.isdir(root_storage_dir) is False:
71         os.makedirs(root_storage_dir)
72 
73 
74 
75     if 'storage_db' in user_config:
76         os.environ['MINDSDB_DB_CON'] = user_config['storage_db']
77     elif os.environ.get('MINDSDB_DB_CON','') == '':
78         os.environ['MINDSDB_DB_CON'] = 'sqlite:///' + os.path.join(os.environ['MINDSDB_STORAGE_DIR'],'mindsdb.sqlite3.db') + '?check_same_thread=False'
79 
80     if 'company_id' in user_config:
81         os.environ['MINDSDB_COMPANY_ID'] = user_config['company_id']
82 
83 
84     from mindsdb.utilities.config import Config
85     mindsdb_config = Config()
86     create_dirs_recursive(mindsdb_config['paths'])
87 
88     os.environ['DEFAULT_LOG_LEVEL'] = os.environ.get('DEFAULT_LOG_LEVEL', 'ERROR')
89     os.environ['LIGHTWOOD_LOG_LEVEL'] = os.environ.get('LIGHTWOOD_LOG_LEVEL', 'ERROR')
90     os.environ['MINDSDB_STORAGE_PATH'] = mindsdb_config['paths']['predictors']
91 
92 
93     if telemetry_file_exists(mindsdb_config['storage_dir']):
94         os.environ['CHECK_FOR_UPDATES'] = '0'
95         print('\n x telemetry disabled! \n')
96     elif os.getenv('CHECK_FOR_UPDATES', '1').lower() in ['0', 'false', 'False']:
97         disable_telemetry(mindsdb_config['storage_dir'])
98         print('\n x telemetry disabled \n')
99     else:
100         print('\n ✓ telemetry enabled \n')
101 
102 
103     from mindsdb.interfaces.custom.model_interface import ModelInterface
104
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mindsdb/__init__.py b/mindsdb/__init__.py
--- a/mindsdb/__init__.py
+++ b/mindsdb/__init__.py
@@ -70,17 +70,14 @@
     if os.path.isdir(root_storage_dir) is False:
         os.makedirs(root_storage_dir)
 
-
-
     if 'storage_db' in user_config:
         os.environ['MINDSDB_DB_CON'] = user_config['storage_db']
-    elif os.environ.get('MINDSDB_DB_CON','') == '':
-        os.environ['MINDSDB_DB_CON'] = 'sqlite:///' + os.path.join(os.environ['MINDSDB_STORAGE_DIR'],'mindsdb.sqlite3.db') + '?check_same_thread=False'
+    elif os.environ.get('MINDSDB_DB_CON', '') == '':
+        os.environ['MINDSDB_DB_CON'] = 'sqlite:///' + os.path.join(os.environ['MINDSDB_STORAGE_DIR'], 'mindsdb.sqlite3.db') + '?check_same_thread=False&timeout=30'
 
     if 'company_id' in user_config:
         os.environ['MINDSDB_COMPANY_ID'] = user_config['company_id']
 
-
     from mindsdb.utilities.config import Config
     mindsdb_config = Config()
     create_dirs_recursive(mindsdb_config['paths'])
@@ -89,7 +86,6 @@
     os.environ['LIGHTWOOD_LOG_LEVEL'] = os.environ.get('LIGHTWOOD_LOG_LEVEL', 'ERROR')
     os.environ['MINDSDB_STORAGE_PATH'] = mindsdb_config['paths']['predictors']
 
-
     if telemetry_file_exists(mindsdb_config['storage_dir']):
         os.environ['CHECK_FOR_UPDATES'] = '0'
         print('\n x telemetry disabled! \n')
diff --git a/mindsdb/utilities/log.py b/mindsdb/utilities/log.py
--- a/mindsdb/utilities/log.py
+++ b/mindsdb/utilities/log.py
@@ -17,12 +17,15 @@
         traces_sample_rate=0 #Set to `1` to experiment with performance metrics
     )
 
+
 class LoggerWrapper(object):
     def __init__(self, writer_arr, default_writer_pos):
         self._writer_arr = writer_arr
         self.default_writer_pos = default_writer_pos
 
     def write(self, message):
+        if len(message.strip(' \n')) == 0:
+            return
         if 'DEBUG:' in message:
             self._writer_arr[0](message)
         elif 'INFO:' in message:
@@ -37,12 +40,17 @@
     def flush(self):
         pass
 
+
 class DbHandler(logging.Handler):
     def __init__(self):
         logging.Handler.__init__(self)
         self.company_id = os.environ.get('MINDSDB_COMPANY_ID', None)
 
     def emit(self, record):
+        if len(record.message.strip(' \n')) == 0 \
+            or (record.threadName == 'ray_print_logs' and 'mindsdb-logger' not in record.message):
+            return
+
         log_type = record.levelname
         source = f'file: {record.pathname} - line: {record.lineno}'
         payload = record.msg
@@ -85,14 +93,16 @@
         session.add(log)
         session.commit()
 
+
 def fmt_log_record(log_record):
-  return {
-    'log_from': 'mindsdb',
-    'level': log_record.log_type,
-    'context': 'unkown',
-    'text': log_record.payload,
-    'created_at': str(log_record.created_at).split('.')[0]
-  }
+    return {
+        'log_from': 'mindsdb',
+        'level': log_record.log_type,
+        'context': 'unkown',
+        'text': log_record.payload,
+        'created_at': str(log_record.created_at).split('.')[0]
+    }
+
 
 def get_logs(min_timestamp, max_timestamp, context, level, log_from, limit):
     logs = session.query(Log).filter(Log.company_id==os.environ.get('MINDSDB_COMPANY_ID', None), Log.created_at>min_timestamp)

{"golden_diff": "diff --git a/mindsdb/__init__.py b/mindsdb/__init__.py\n--- a/mindsdb/__init__.py\n+++ b/mindsdb/__init__.py\n@@ -70,17 +70,14 @@\n     if os.path.isdir(root_storage_dir) is False:\n         os.makedirs(root_storage_dir)\n \n-\n-\n     if 'storage_db' in user_config:\n         os.environ['MINDSDB_DB_CON'] = user_config['storage_db']\n-    elif os.environ.get('MINDSDB_DB_CON','') == '':\n-        os.environ['MINDSDB_DB_CON'] = 'sqlite:///' + os.path.join(os.environ['MINDSDB_STORAGE_DIR'],'mindsdb.sqlite3.db') + '?check_same_thread=False'\n+    elif os.environ.get('MINDSDB_DB_CON', '') == '':\n+        os.environ['MINDSDB_DB_CON'] = 'sqlite:///' + os.path.join(os.environ['MINDSDB_STORAGE_DIR'], 'mindsdb.sqlite3.db') + '?check_same_thread=False&timeout=30'\n \n     if 'company_id' in user_config:\n         os.environ['MINDSDB_COMPANY_ID'] = user_config['company_id']\n \n-\n     from mindsdb.utilities.config import Config\n     mindsdb_config = Config()\n     create_dirs_recursive(mindsdb_config['paths'])\n@@ -89,7 +86,6 @@\n     os.environ['LIGHTWOOD_LOG_LEVEL'] = os.environ.get('LIGHTWOOD_LOG_LEVEL', 'ERROR')\n     os.environ['MINDSDB_STORAGE_PATH'] = mindsdb_config['paths']['predictors']\n \n-\n     if telemetry_file_exists(mindsdb_config['storage_dir']):\n         os.environ['CHECK_FOR_UPDATES'] = '0'\n         print('\\n x telemetry disabled! \\n')\ndiff --git a/mindsdb/utilities/log.py b/mindsdb/utilities/log.py\n--- a/mindsdb/utilities/log.py\n+++ b/mindsdb/utilities/log.py\n@@ -17,12 +17,15 @@\n         traces_sample_rate=0 #Set to `1` to experiment with performance metrics\n     )\n \n+\n class LoggerWrapper(object):\n     def __init__(self, writer_arr, default_writer_pos):\n         self._writer_arr = writer_arr\n         self.default_writer_pos = default_writer_pos\n \n     def write(self, message):\n+        if len(message.strip(' \\n')) == 0:\n+            return\n         if 'DEBUG:' in message:\n             self._writer_arr[0](message)\n         elif 'INFO:' in message:\n@@ -37,12 +40,17 @@\n     def flush(self):\n         pass\n \n+\n class DbHandler(logging.Handler):\n     def __init__(self):\n         logging.Handler.__init__(self)\n         self.company_id = os.environ.get('MINDSDB_COMPANY_ID', None)\n \n     def emit(self, record):\n+        if len(record.message.strip(' \\n')) == 0 \\\n+            or (record.threadName == 'ray_print_logs' and 'mindsdb-logger' not in record.message):\n+            return\n+\n         log_type = record.levelname\n         source = f'file: {record.pathname} - line: {record.lineno}'\n         payload = record.msg\n@@ -85,14 +93,16 @@\n         session.add(log)\n         session.commit()\n \n+\n def fmt_log_record(log_record):\n-  return {\n-    'log_from': 'mindsdb',\n-    'level': log_record.log_type,\n-    'context': 'unkown',\n-    'text': log_record.payload,\n-    'created_at': str(log_record.created_at).split('.')[0]\n-  }\n+    return {\n+        'log_from': 'mindsdb',\n+        'level': log_record.log_type,\n+        'context': 'unkown',\n+        'text': log_record.payload,\n+        'created_at': str(log_record.created_at).split('.')[0]\n+    }\n+\n \n def get_logs(min_timestamp, max_timestamp, context, level, log_from, limit):\n     logs = session.query(Log).filter(Log.company_id==os.environ.get('MINDSDB_COMPANY_ID', None), Log.created_at>min_timestamp)\n", "issue": "All logging messages produced in ray actors have 'ERROR' level\nAt this moment, all log messages produced in ray actor came with 'ERROR' level. There are two issues because this:\r\n1. db grow quick.\r\n2. with sqllite as db is many errors related to db lock, especially of start several learn processes.\n", "before_files": [{"content": "import os\nimport sys\nimport logging\nimport traceback\n\nfrom mindsdb.interfaces.storage.db import session, Log\nfrom mindsdb.utilities.config import Config\n\ntelemtry_enabled = os.getenv('CHECK_FOR_UPDATES', '1').lower() not in ['0', 'false', 'False']\nglobal_config = Config().get_all()\n\nif telemtry_enabled:\n    import sentry_sdk\n    from sentry_sdk import capture_exception, capture_message, add_breadcrumb\n    sentry_sdk.init(\n        \"https://29e64dbdf325404ebf95473d5f4a54d3@o404567.ingest.sentry.io/5633566\",\n        traces_sample_rate=0 #Set to `1` to experiment with performance metrics\n    )\n\nclass LoggerWrapper(object):\n    def __init__(self, writer_arr, default_writer_pos):\n        self._writer_arr = writer_arr\n        self.default_writer_pos = default_writer_pos\n\n    def write(self, message):\n        if 'DEBUG:' in message:\n            self._writer_arr[0](message)\n        elif 'INFO:' in message:\n            self._writer_arr[1](message)\n        elif 'WARNING:' in message:\n            self._writer_arr[2](message)\n        elif 'ERROR:' in message:\n            self._writer_arr[3](message)\n        else:\n            self._writer_arr[self.default_writer_pos](message)\n\n    def flush(self):\n        pass\n\nclass DbHandler(logging.Handler):\n    def __init__(self):\n        logging.Handler.__init__(self)\n        self.company_id = os.environ.get('MINDSDB_COMPANY_ID', None)\n\n    def emit(self, record):\n        log_type = record.levelname\n        source = f'file: {record.pathname} - line: {record.lineno}'\n        payload = record.msg\n\n        if telemtry_enabled:\n            pass\n            # @TODO: Enable once we are sure no sensitive info is being outputed in the logs\n            # if log_type in ['INFO']:\n            #    add_breadcrumb(\n            #        category='auth',\n            #        message=str(payload),\n            #        level='info',\n            #    )\n            # Might be too much traffic if we send this for users with slow networks\n            #if log_type in ['DEBUG']:\n            #    add_breadcrumb(\n            #        category='auth',\n            #        message=str(payload),\n            #        level='debug',\n            #    )\n\n        if log_type in ['ERROR', 'WARNING']:\n            trace = str(traceback.format_stack(limit=20))\n            trac_log = Log(log_type='traceback', source=source, payload=trace, company_id=self.company_id)\n            session.add(trac_log)\n            session.commit()\n\n            if telemtry_enabled:\n                add_breadcrumb(\n                    category='stack_trace',\n                    message=trace,\n                    level='info',\n                )\n                if log_type in ['ERROR']:\n                    capture_message(str(payload))\n                if log_type in ['WARNING']:\n                    capture_message(str(payload))\n\n        log = Log(log_type=str(log_type), source=source, payload=str(payload), company_id=self.company_id)\n        session.add(log)\n        session.commit()\n\ndef fmt_log_record(log_record):\n  return {\n    'log_from': 'mindsdb',\n    'level': log_record.log_type,\n    'context': 'unkown',\n    'text': log_record.payload,\n    'created_at': str(log_record.created_at).split('.')[0]\n  }\n\ndef get_logs(min_timestamp, max_timestamp, context, level, log_from, limit):\n    logs = session.query(Log).filter(Log.company_id==os.environ.get('MINDSDB_COMPANY_ID', None), Log.created_at>min_timestamp)\n\n    if max_timestamp is not None:\n        logs = logs.filter(Log.created_at<max_timestamp)\n\n    if context is not None:\n        # e.g. datasource/predictor and assoicated id\n        pass\n\n    if level is not None:\n        logs = logs.filter(Log.log_type==level)\n\n    if log_from is not None:\n        # mindsdb/native/lightwood/all\n        pass\n\n    if limit is not None:\n        logs = logs.limit(limit)\n\n    logs = [fmt_log_record(x) for x in logs]\n    return logs\n\ndef initialize_log(config=global_config, logger_name='main', wrap_print=False):\n    ''' Create new logger\n    :param config: object, app config\n    :param logger_name: str, name of logger\n    :param wrap_print: bool, if true, then print() calls will be wrapped by log.debug() function.\n    '''\n    log = logging.getLogger(f'mindsdb.{logger_name}')\n    log.propagate = False\n    log.setLevel(min(\n        getattr(logging, config['log']['level']['console']),\n        getattr(logging, config['log']['level']['file'])\n    ))\n\n    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')\n\n    ch = logging.StreamHandler()\n    ch.setLevel(config['log']['level']['console']) # that level will be in console\n    log.addHandler(ch)\n    db_handler = DbHandler()\n    log.addHandler(db_handler)\n\n    if wrap_print:\n        sys.stdout = LoggerWrapper([log.debug, log.info, log.warning, log.error], 1)\n        sys.stderr = LoggerWrapper([log.debug, log.info, log.warning, log.error], 3)\n\n    return log\n\n\ndef get_log(logger_name=None):\n    if logger_name is None:\n        return logging.getLogger('mindsdb')\n    return logging.getLogger(f'mindsdb.{logger_name}')\n\n\nlog = initialize_log()\n", "path": "mindsdb/utilities/log.py"}, {"content": "import os\nimport sys\nimport json\n\nfrom mindsdb.__about__ import __package_name__ as name, __version__   # noqa\nfrom mindsdb.utilities.fs import get_or_create_dir_struct, create_dirs_recursive\nfrom mindsdb.utilities.functions import args_parse, is_notebook\nfrom mindsdb.__about__ import __version__ as mindsdb_version\nfrom mindsdb.utilities.telemetry import telemetry_file_exists, disable_telemetry\n\nis_ray_worker = False\nif '-ray' in str(sys.argv):\n    is_ray_worker = True\n\nif not is_ray_worker:\n    try:\n        if not is_notebook():\n            args = args_parse()\n        else:\n            args = None\n    except Exception:\n        # This fials in some notebooks ... check above for is_notebook is still needed because even if the exception is caught trying to read the arg still leads to failure in other notebooks... notebooks a\n        args = None\n\n    # ---- CHECK SYSTEM ----\n    if not (sys.version_info[0] >= 3 and sys.version_info[1] >= 6):\n        print(\"\"\"\n    MindsDB server requires Python >= 3.6 to run\n\n    Once you have Python 3.6 installed you can tun mindsdb as follows:\n\n    1. create and activate venv:\n    python3.6 -m venv venv\n    source venv/bin/activate\n\n    2. install MindsDB:\n    pip3 install mindsdb\n\n    3. Run MindsDB\n    python3.6 -m mindsdb\n\n    More instructions in https://docs.mindsdb.com\n        \"\"\")\n        exit(1)\n\n    # --- VERSION MODE ----\n    if args is not None and args.version:\n        print(f'MindsDB {mindsdb_version}')\n        sys.exit(0)\n\n    # --- MODULE OR LIBRARY IMPORT MODE ----\n    if args is not None and args.config is not None:\n        config_path = args.config\n        with open(config_path, 'r') as fp:\n            user_config = json.load(fp)\n    else:\n        user_config = {}\n        config_path = 'absent'\n    os.environ['MINDSDB_CONFIG_PATH'] = config_path\n\n    if 'storage_dir' in user_config:\n        root_storage_dir = user_config['storage_dir']\n        os.environ['MINDSDB_STORAGE_DIR'] = root_storage_dir\n    elif os.environ.get('MINDSDB_STORAGE_DIR') is not None:\n        root_storage_dir = os.environ['MINDSDB_STORAGE_DIR']\n    else:\n        _, root_storage_dir = get_or_create_dir_struct()\n        os.environ['MINDSDB_STORAGE_DIR'] = root_storage_dir\n\n    if os.path.isdir(root_storage_dir) is False:\n        os.makedirs(root_storage_dir)\n\n\n\n    if 'storage_db' in user_config:\n        os.environ['MINDSDB_DB_CON'] = user_config['storage_db']\n    elif os.environ.get('MINDSDB_DB_CON','') == '':\n        os.environ['MINDSDB_DB_CON'] = 'sqlite:///' + os.path.join(os.environ['MINDSDB_STORAGE_DIR'],'mindsdb.sqlite3.db') + '?check_same_thread=False'\n\n    if 'company_id' in user_config:\n        os.environ['MINDSDB_COMPANY_ID'] = user_config['company_id']\n\n\n    from mindsdb.utilities.config import Config\n    mindsdb_config = Config()\n    create_dirs_recursive(mindsdb_config['paths'])\n\n    os.environ['DEFAULT_LOG_LEVEL'] = os.environ.get('DEFAULT_LOG_LEVEL', 'ERROR')\n    os.environ['LIGHTWOOD_LOG_LEVEL'] = os.environ.get('LIGHTWOOD_LOG_LEVEL', 'ERROR')\n    os.environ['MINDSDB_STORAGE_PATH'] = mindsdb_config['paths']['predictors']\n\n\n    if telemetry_file_exists(mindsdb_config['storage_dir']):\n        os.environ['CHECK_FOR_UPDATES'] = '0'\n        print('\\n x telemetry disabled! \\n')\n    elif os.getenv('CHECK_FOR_UPDATES', '1').lower() in ['0', 'false', 'False']:\n        disable_telemetry(mindsdb_config['storage_dir'])\n        print('\\n x telemetry disabled \\n')\n    else:\n        print('\\n \u2713 telemetry enabled \\n')\n\n\n    from mindsdb.interfaces.custom.model_interface import ModelInterface\n", "path": "mindsdb/__init__.py"}], "after_files": [{"content": "import os\nimport sys\nimport logging\nimport traceback\n\nfrom mindsdb.interfaces.storage.db import session, Log\nfrom mindsdb.utilities.config import Config\n\ntelemtry_enabled = os.getenv('CHECK_FOR_UPDATES', '1').lower() not in ['0', 'false', 'False']\nglobal_config = Config().get_all()\n\nif telemtry_enabled:\n    import sentry_sdk\n    from sentry_sdk import capture_exception, capture_message, add_breadcrumb\n    sentry_sdk.init(\n        \"https://29e64dbdf325404ebf95473d5f4a54d3@o404567.ingest.sentry.io/5633566\",\n        traces_sample_rate=0 #Set to `1` to experiment with performance metrics\n    )\n\n\nclass LoggerWrapper(object):\n    def __init__(self, writer_arr, default_writer_pos):\n        self._writer_arr = writer_arr\n        self.default_writer_pos = default_writer_pos\n\n    def write(self, message):\n        if len(message.strip(' \\n')) == 0:\n            return\n        if 'DEBUG:' in message:\n            self._writer_arr[0](message)\n        elif 'INFO:' in message:\n            self._writer_arr[1](message)\n        elif 'WARNING:' in message:\n            self._writer_arr[2](message)\n        elif 'ERROR:' in message:\n            self._writer_arr[3](message)\n        else:\n            self._writer_arr[self.default_writer_pos](message)\n\n    def flush(self):\n        pass\n\n\nclass DbHandler(logging.Handler):\n    def __init__(self):\n        logging.Handler.__init__(self)\n        self.company_id = os.environ.get('MINDSDB_COMPANY_ID', None)\n\n    def emit(self, record):\n        if len(record.message.strip(' \\n')) == 0 \\\n            or (record.threadName == 'ray_print_logs' and 'mindsdb-logger' not in record.message):\n            return\n\n        log_type = record.levelname\n        source = f'file: {record.pathname} - line: {record.lineno}'\n        payload = record.msg\n\n        if telemtry_enabled:\n            pass\n            # @TODO: Enable once we are sure no sensitive info is being outputed in the logs\n            # if log_type in ['INFO']:\n            #    add_breadcrumb(\n            #        category='auth',\n            #        message=str(payload),\n            #        level='info',\n            #    )\n            # Might be too much traffic if we send this for users with slow networks\n            #if log_type in ['DEBUG']:\n            #    add_breadcrumb(\n            #        category='auth',\n            #        message=str(payload),\n            #        level='debug',\n            #    )\n\n        if log_type in ['ERROR', 'WARNING']:\n            trace = str(traceback.format_stack(limit=20))\n            trac_log = Log(log_type='traceback', source=source, payload=trace, company_id=self.company_id)\n            session.add(trac_log)\n            session.commit()\n\n            if telemtry_enabled:\n                add_breadcrumb(\n                    category='stack_trace',\n                    message=trace,\n                    level='info',\n                )\n                if log_type in ['ERROR']:\n                    capture_message(str(payload))\n                if log_type in ['WARNING']:\n                    capture_message(str(payload))\n\n        log = Log(log_type=str(log_type), source=source, payload=str(payload), company_id=self.company_id)\n        session.add(log)\n        session.commit()\n\n\ndef fmt_log_record(log_record):\n    return {\n        'log_from': 'mindsdb',\n        'level': log_record.log_type,\n        'context': 'unkown',\n        'text': log_record.payload,\n        'created_at': str(log_record.created_at).split('.')[0]\n    }\n\n\ndef get_logs(min_timestamp, max_timestamp, context, level, log_from, limit):\n    logs = session.query(Log).filter(Log.company_id==os.environ.get('MINDSDB_COMPANY_ID', None), Log.created_at>min_timestamp)\n\n    if max_timestamp is not None:\n        logs = logs.filter(Log.created_at<max_timestamp)\n\n    if context is not None:\n        # e.g. datasource/predictor and assoicated id\n        pass\n\n    if level is not None:\n        logs = logs.filter(Log.log_type==level)\n\n    if log_from is not None:\n        # mindsdb/native/lightwood/all\n        pass\n\n    if limit is not None:\n        logs = logs.limit(limit)\n\n    logs = [fmt_log_record(x) for x in logs]\n    return logs\n\ndef initialize_log(config=global_config, logger_name='main', wrap_print=False):\n    ''' Create new logger\n    :param config: object, app config\n    :param logger_name: str, name of logger\n    :param wrap_print: bool, if true, then print() calls will be wrapped by log.debug() function.\n    '''\n    log = logging.getLogger(f'mindsdb.{logger_name}')\n    log.propagate = False\n    log.setLevel(min(\n        getattr(logging, config['log']['level']['console']),\n        getattr(logging, config['log']['level']['file'])\n    ))\n\n    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')\n\n    ch = logging.StreamHandler()\n    ch.setLevel(config['log']['level']['console']) # that level will be in console\n    log.addHandler(ch)\n    db_handler = DbHandler()\n    log.addHandler(db_handler)\n\n    if wrap_print:\n        sys.stdout = LoggerWrapper([log.debug, log.info, log.warning, log.error], 1)\n        sys.stderr = LoggerWrapper([log.debug, log.info, log.warning, log.error], 3)\n\n    return log\n\n\ndef get_log(logger_name=None):\n    if logger_name is None:\n        return logging.getLogger('mindsdb')\n    return logging.getLogger(f'mindsdb.{logger_name}')\n\n\nlog = initialize_log()\n", "path": "mindsdb/utilities/log.py"}, {"content": "import os\nimport sys\nimport json\n\nfrom mindsdb.__about__ import __package_name__ as name, __version__   # noqa\nfrom mindsdb.utilities.fs import get_or_create_dir_struct, create_dirs_recursive\nfrom mindsdb.utilities.functions import args_parse, is_notebook\nfrom mindsdb.__about__ import __version__ as mindsdb_version\nfrom mindsdb.utilities.telemetry import telemetry_file_exists, disable_telemetry\n\nis_ray_worker = False\nif '-ray' in str(sys.argv):\n    is_ray_worker = True\n\nif not is_ray_worker:\n    try:\n        if not is_notebook():\n            args = args_parse()\n        else:\n            args = None\n    except Exception:\n        # This fials in some notebooks ... check above for is_notebook is still needed because even if the exception is caught trying to read the arg still leads to failure in other notebooks... notebooks a\n        args = None\n\n    # ---- CHECK SYSTEM ----\n    if not (sys.version_info[0] >= 3 and sys.version_info[1] >= 6):\n        print(\"\"\"\n    MindsDB server requires Python >= 3.6 to run\n\n    Once you have Python 3.6 installed you can tun mindsdb as follows:\n\n    1. create and activate venv:\n    python3.6 -m venv venv\n    source venv/bin/activate\n\n    2. install MindsDB:\n    pip3 install mindsdb\n\n    3. Run MindsDB\n    python3.6 -m mindsdb\n\n    More instructions in https://docs.mindsdb.com\n        \"\"\")\n        exit(1)\n\n    # --- VERSION MODE ----\n    if args is not None and args.version:\n        print(f'MindsDB {mindsdb_version}')\n        sys.exit(0)\n\n    # --- MODULE OR LIBRARY IMPORT MODE ----\n    if args is not None and args.config is not None:\n        config_path = args.config\n        with open(config_path, 'r') as fp:\n            user_config = json.load(fp)\n    else:\n        user_config = {}\n        config_path = 'absent'\n    os.environ['MINDSDB_CONFIG_PATH'] = config_path\n\n    if 'storage_dir' in user_config:\n        root_storage_dir = user_config['storage_dir']\n        os.environ['MINDSDB_STORAGE_DIR'] = root_storage_dir\n    elif os.environ.get('MINDSDB_STORAGE_DIR') is not None:\n        root_storage_dir = os.environ['MINDSDB_STORAGE_DIR']\n    else:\n        _, root_storage_dir = get_or_create_dir_struct()\n        os.environ['MINDSDB_STORAGE_DIR'] = root_storage_dir\n\n    if os.path.isdir(root_storage_dir) is False:\n        os.makedirs(root_storage_dir)\n\n    if 'storage_db' in user_config:\n        os.environ['MINDSDB_DB_CON'] = user_config['storage_db']\n    elif os.environ.get('MINDSDB_DB_CON', '') == '':\n        os.environ['MINDSDB_DB_CON'] = 'sqlite:///' + os.path.join(os.environ['MINDSDB_STORAGE_DIR'], 'mindsdb.sqlite3.db') + '?check_same_thread=False&timeout=30'\n\n    if 'company_id' in user_config:\n        os.environ['MINDSDB_COMPANY_ID'] = user_config['company_id']\n\n    from mindsdb.utilities.config import Config\n    mindsdb_config = Config()\n    create_dirs_recursive(mindsdb_config['paths'])\n\n    os.environ['DEFAULT_LOG_LEVEL'] = os.environ.get('DEFAULT_LOG_LEVEL', 'ERROR')\n    os.environ['LIGHTWOOD_LOG_LEVEL'] = os.environ.get('LIGHTWOOD_LOG_LEVEL', 'ERROR')\n    os.environ['MINDSDB_STORAGE_PATH'] = mindsdb_config['paths']['predictors']\n\n    if telemetry_file_exists(mindsdb_config['storage_dir']):\n        os.environ['CHECK_FOR_UPDATES'] = '0'\n        print('\\n x telemetry disabled! \\n')\n    elif os.getenv('CHECK_FOR_UPDATES', '1').lower() in ['0', 'false', 'False']:\n        disable_telemetry(mindsdb_config['storage_dir'])\n        print('\\n x telemetry disabled \\n')\n    else:\n        print('\\n \u2713 telemetry enabled \\n')\n\n\n    from mindsdb.interfaces.custom.model_interface import ModelInterface\n", "path": "mindsdb/__init__.py"}]}