ZeroQI / Hama.bundle

Plex HTTP Anidb Metadata Agent (HAMA)
GNU General Public License v3.0
1.22k stars 114 forks source link

[BETA] Custom Logs are broken #206

Closed KurtzPT closed 6 years ago

KurtzPT commented 6 years ago

Just noticed this while uploading the logs for #190 (logs are on my last post there).

Most of the Hama agent stuff doesn't go to these individual logs at all.

ZeroQI commented 6 years ago

These look ok

The below is out of place in "Bleach [tvdb3-74796].agent-update.log"

GetLibraryRootPath() - library: '', path: 'Cardcaptor Sakura [anidb-102]', root: '/mnt/plexdrive/anime', dir:'/mnt/plexdrive/anime/Cardcaptor Sakura [anidb-102]', PLEX_LIBRARY: '{}'
Log file: /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Data/com.plexapp.agents.hama/DataItems/_Logs/Cardcaptor Sakura [anidb-102].agent-search.log

Concurent threads breaks the custom logs system, ok on manual refresh since a single thread is called Secondary issue, not sure how to solve for now

KurtzPT commented 6 years ago

Yes, I noticed that too. All the episodes metadata wasn't recorded on these custom logs but they were on the main ones so it's probably that concurrency problem.

ZeroQI commented 6 years ago

To fix this so logs are always correct, i need to either:

https://stackoverflow.com/questions/22643337/per-thread-logging-in-python http://plumberjack.blogspot.ie/2010/09/configuring-logging-for-web.html

Look like i need to adapt:

class WebApp:
    def __init__(self, name):
        self.name = name
        self.threads = set()
        handler = logging.FileHandler(name + '.log', 'w')
        f = InjectingFilter(self)
        handler.setFormatter(formatter)
        handler.addFilter(f)
        root.addHandler(handler)
        self.num_requests = 0

    def process_request(self, request):
        tlocal.request = request
        tlocal.appName = self.name
        tname = threading.currentThread().getName()
        self.threads.add(tname)
        self.num_requests += 1
        try:
            logger.debug('Request processing started')
            webapplib.useful()
            logger.debug('Request processing finished')
        finally:
            self.threads.remove(tname)

class InjectingFilter(logging.Filter):
    def __init__(self, app):
        self.app = app

    def filter(self, record):
        record.method = tlocal.request.method
        record.ip = tlocal.request.ip
        record.appName = tlocal.appName
        tname = threading.currentThread().getName()
        return tname in self.app.threads
ZeroQI commented 6 years ago

Worked on that, testing at the moment

ZeroQI commented 6 years ago

I removed removal of loggers in the code some version ago. Is the issue still present ?

ZeroQI commented 6 years ago

Overalled logs Please update scanner and agents and report

ZeroQI commented 6 years ago

@KurtzPT i should have fixed logging. please update both scanner and agent, check loggings for the same series that had bad logging before and report

ZeroQI commented 6 years ago

Please reopen or comment if not fixed

KurtzPT commented 6 years ago

They do seem fine now, good job!