0

I use in my program the function AudioSegment.from_file: sound = AudioSegment.from_file(audio_path, format="m4a")

I also implement a file the I created: import GUI_log

In this file I have the next class:

class TextHandler(logging.Handler):
    """This class allows you to log to a Tkinter scroll_text or Scrolledscroll_text widget"""
    def __init__(self, scroll_text):
        # run the regular Handler __init__
        logging.Handler.__init__(self)

        # Store a reference to the scroll_text it will log to
        self.scroll_text = scroll_text

    def emit(self, record):
        msg = self.format(record)
        tag = ""
        if record.levelno == ACTION:
            tag = "ACTION"
        def append():
            self.scroll_text.configure(state='normal')
            self.scroll_text.insert(Tkinter.END, msg + '\n', tag)
            self.scroll_text.configure(state='disabled')
            # Autoscroll to the bottom
            self.scroll_text.yview(Tkinter.END)     
        # This is necessary because we can't modify the scroll_text from other threads
        self.scroll_text.after(0, append)

For some reason when I execute the first line I mentioned (The one with the from_file), The emit function in the TextHandler class gets executed.

Anyone knows what is the reason for it and how to fix it?

EDIT: I found out I overwrite somewhere in this code:

# Create Tkinter object and ScrolledText
    root =Tkinter.Tk()
    st = ScrolledText.ScrolledText(root, state='disabled')
    st.configure(font='TkFixedFont')
    st.pack()
    st.tag_config("ACTION", foreground="dark green")

    # Create text handler
    text_handler = TextHandler(st)
    formatter = logging.Formatter('%(asctime)s    IP: %(IP)-15s PORT: %(PORT)-5s    MESSAGE: %(message)s', datefmt='%Y-%m-%d,%H:%M:%S') #.%(msecs)03d
    text_handler.setFormatter(formatter)

    # Add action level
    logging.addLevelName(ACTION, "ACTION")
    def action(self, message, *args, **kws):
        self._log(ACTION, message, args, **kws) 
    logging.Logger.action = action

    # Create logger
    logger = logging.getLogger()
    logger.addHandler(text_handler)
    logger.setLevel(logging.DEBUG)

    return (root, logger)
Netanel
  • 477
  • 2
  • 11

1 Answers1

0

After some scrolling in the internet I found out the pydub uses logging and I probably overwrite the logger. To fix it I changed this line: logger = logging.getLogger() to logger = logging.getLogger("SOMENAME")

Netanel
  • 477
  • 2
  • 11