Repository: mindsdb/mindsdb

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.


Discussion:

Resolving patch:
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 write(self, message):
     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 @@ def emit(self, record):
         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)


Test patch: