How to stop file logging using logzero


  • Whenever, I am importing SmartApi it is creating ./logs folder in project directory that highly unsafe for my application. the logger might log sensitive critical information that will expose over public access.
    I want to stop logzero logging but unable to do that.

    from SmartApi import SmartConnect
    import logzero
    
    logzero.logfile(None)
    

    Please remove the logzero configuration override package. Please inherit configuration from parent configuration.

    SmartApi/smartConnect.py

    128        log_folder_path = os.path.join("logs", log_folder)  # Construct the full path to the log folder
    129        os.makedirs(log_folder_path, exist_ok=True) # Create the log folder if it doesn't exist
    130        log_path = os.path.join(log_folder_path, "app.log") # Construct the full path to the log file
    131        logzero.logfile(log_path, loglevel=logging.ERROR)  # Output logs to a date-wise log file
    

    Please fix this kind of programming bug 🙏

    logzero documentation



  • As a workaround, you can monkey patch the functions used for creating that folder

        # Monkey patching used functions so that folder and logging is not setup
        import os
        import logzero
        orig_makedirs = os.makedirs
        os.makedirs = lambda *_args, **_kwargs: None
        orig_logfile = logzero.logfile
        logzero.logfile = lambda *_args, **_kwargs: None
    
        # Create api object here
        smart_api = SmartConnect("API KEY")
    
        # Restoring back original functions
        os.makedirs = orig_makedirs
        logzero.logfile = orig_logfile
    

    You can also create a decorator wrapping your function call


  • Any update on this


  • @Moderator_3 any update on this


  • Hello @kr-prashant94
    We have rised your concern to our tech team and we will get back tou on the same soon
    Regards,
    SmartAPI Team