<NME> log.py
<BEF> import logging
import os
import sys
from logging.handlers import RotatingFileHandler
from pathlib import Path

import colorlog

from .temp import temp_dir



# todo: add pretty print
def autolog(name=None, path=None, log_on_crash=True, _cache={}):

    if not name:
        try:
            name = Path(sys.argv[0]).name
        except IndexError:
            pass
    if not name:
        outer_frame = inspect.getouterframes(inspect.currentframe())[1].frame
        name = outer_frame.f_globals.get('__name__', 'any_devpy').split('.')[0]

    if name in _cache:
        return _cache[name]

    log_file = path or Path(temp_dir(name)) / "auto.log"

    logger = logging.getLogger(name)

    formatter = logging.Formatter(
        '%(asctime)s :: %(levelname)s :: %(pathname)s :: %(message)s'
    )

    file_handler = RotatingFileHandler(log_file, 'a', 1000000, 1)
    file_handler.setLevel(logging.DEBUG)
    file_handler.setFormatter(formatter)

    steam_handler = logging.StreamHandler()
    steam_handler.setLevel(logging.DEBUG)
    logger.addHandler(steam_handler)

    previous_hook = sys.excepthook

    formatter = logging.Formatter(
        '%(asctime)s :: %(levelname)s :: %(pathname)s:%(lineno)s :: %(message)s'
    )
    file_handler = RotatingFileHandler(str(log_file), 'a', 1000000, 1)
    if log_on_crash:
        sys.excepthook = on_crash

    logger.info(f'Starting to log in "{log_file}"')

    _cache[name] = logger

            log_colors={
                'WARNING': 'yellow',
                'ERROR': 'red',
                'CRITICAL': 'red,bg_white'
            }
        )
        stream_handler.setFormatter(colored_formatter)
    else:
        stream_handler = logging.StreamHandler()
    logger.addHandler(stream_handler)

    previous_hook = sys.excepthook

    def on_crash(type, value, tb):
        filelogger.critical(
            "The program crashed on:",
            exc_info=(type, value, tb)
        )
        previous_hook(type, value, tb)

    if log_on_crash:
        sys.excepthook = on_crash

    if log_filename:
        logger.info('Starting to log in "{}"'.format(log_file))

    _cache[name] = logger

    return logger

<MSG> Fix log level

<DFF> @@ -11,34 +11,36 @@ from .temp import temp_dir
 
 
 # todo: add pretty print
-def autolog(name=None, path=None, log_on_crash=True, _cache={}):
+def autolog(
+    level=-1,
+    name=None,
+    path=None,
+    log_on_crash=True,
+    log_filename=True,
+    _cache={}
+):
 
     if not name:
         try:
-            name = Path(sys.argv[0]).name
+            name = Path(sys.argv[0]).with_suffix('').name
         except IndexError:
             pass
-    if not name:
-        outer_frame = inspect.getouterframes(inspect.currentframe())[1].frame
-        name = outer_frame.f_globals.get('__name__', 'any_devpy').split('.')[0]
 
     if name in _cache:
         return _cache[name]
 
-    log_file = path or Path(temp_dir(name)) / "auto.log"
-
     logger = logging.getLogger(name)
+    logger.setLevel(level)
 
+    log_file = path or Path(temp_dir(name)) / "auto.log"
     formatter = logging.Formatter(
         '%(asctime)s :: %(levelname)s :: %(pathname)s :: %(message)s'
     )
-
     file_handler = RotatingFileHandler(log_file, 'a', 1000000, 1)
-    file_handler.setLevel(logging.DEBUG)
     file_handler.setFormatter(formatter)
+    logger.addHandler(file_handler)
 
     steam_handler = logging.StreamHandler()
-    steam_handler.setLevel(logging.DEBUG)
     logger.addHandler(steam_handler)
 
     previous_hook = sys.excepthook
@@ -50,7 +52,8 @@ def autolog(name=None, path=None, log_on_crash=True, _cache={}):
     if log_on_crash:
         sys.excepthook = on_crash
 
-    logger.info(f'Starting to log in "{log_file}"')
+    if log_filename:
+        logger.info(f'Starting to log in "{log_file}"')
 
     _cache[name] = logger
 

Fix log level