Skip to content

Setting custom log handler when using gallery_dl as import / Custom Log Handler Option #4023

@ZizzyDizzyMC

Description

@ZizzyDizzyMC

I've been trying unsuccessfully to add a log handler to gallery_dl when used as an import.

import logging
import gallery_dl

class MyLogger(logging.Handler):
    
    #def handle(*args):
    def emit(*args, **kwags):
        print('--- args ---')
        for item in args:
            print(item)
        print('---')
        
# --- main ---

logger = logging.getLogger()
logger.setLevel(logging.INFO) 
my_logger = MyLogger(logging.INFO)
logger.addHandler(my_logger)
gallery_dl.job.DownloadJob("imgur.com/8372ne").run()

The resulting output will be:

--- args ---
<MyLogger (info)>
<LogRecord: imgur, 40, /home/ubuntu/bot-venv/lib/python3.10/site-packages/gallery_dl/job.py, 105, "%s: %s">
---
[imgur][error] HttpError: '404 Not Found' for 'https://api.imgur.com/post/v1/media/8372n'
4

Unfortunately I've tried grabbing ahold of getLogger('gallery-dl') also without success. This is related to #642 however this is also a request for an addition of using custom loggers similar to yt_dlp. I'm sure I can add it, I just cannot find it. Without being able to capture status results and messages in real time I am unable to act on items that return statuses I need to act on, such as 404's or other status codes in addition to file failures etc.

I appear to be getting the LogRecord as definied in the Logger class in output.py - however the msg contents of this log record are always blank with "%s: $s"

I am not wanting to write to a file, as seems to be the way for the entirety of output.py.

I appreciate your time, having to make a post was my last resort as I've given up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions