Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    How to stop file logging using logzero

    Python SDK
    0
    6
    38
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kr.prashant94 last edited by

      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

      M 1 Reply Last reply Reply Quote 0
      • M
        Moderator_3 @kr.prashant94 last edited by

        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

        C 1 Reply Last reply Reply Quote 0
        • C
          chs8788 @Moderator_3 last edited by

          @Moderator_3 any update on this

          1 Reply Last reply Reply Quote 0
          • C
            chs8788 last edited by

            Any update on this

            1 Reply Last reply Reply Quote 0
            • A
              ayushagarwal last edited by

              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

              K 1 Reply Last reply Reply Quote 0
              • K
                kr.prashant94 @ayushagarwal last edited by

                @ayushagarwal 🙏

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post