Skip to content

Commit 0166131

Browse files
authored
Merge pull request #172 from metabrainz/add-logging-name
Add logging functions to support third party apps
2 parents 7a1a98d + 0fcc5a3 commit 0166131

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

troi/content_resolver/subsonic.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
from troi.content_resolver.utils import bcolors
1212
from troi.content_resolver.py_sonic_fix import FixedConnection
1313

14-
logger = logging.getLogger(__name__)
14+
logger = logging.getLogger("troi_subsonic_scan")
15+
16+
APP_LOG_LEVEL_NUM = 19
17+
logging.addLevelName(APP_LOG_LEVEL_NUM, "NOTICE")
18+
19+
def applog(message, *args, **kwargs):
20+
logger._log(APP_LOG_LEVEL_NUM, message, args, **kwargs)
1521

1622

1723
class SubsonicDatabase(Database):
@@ -102,8 +108,9 @@ def run_sync(self):
102108
album_mbid = album_info2["albumInfo"]["musicBrainzId"]
103109
except KeyError:
104110
if not self.quiet:
105-
pbar.write(bcolors.FAIL + "FAIL " + bcolors.ENDC + "subsonic album '%s' by '%s' has no MBID" %
106-
(album["name"], album["artist"]))
111+
msg = "subsonic album '%s' by '%s' has no MBID" % (album["name"], album["artist"])
112+
pbar.write(bcolors.FAIL + "FAIL " + bcolors.ENDC + msg)
113+
applog("FAIL: " + msg)
107114
self.error += 1
108115
continue
109116

@@ -123,9 +130,12 @@ def run_sync(self):
123130
artist_id_index[artist_id] = artist["artistInfo2"]["musicBrainzId"]
124131
except KeyError:
125132
if not self.quiet:
126-
pbar.write(bcolors.FAIL + "FAIL " + bcolors.ENDC + "recording '%s' by '%s' has no artist MBID" %
127-
(album["name"], album["artist"]))
128-
pbar.write("Consider retagging this file with Picard! ( https://picard.musicbrainz.org )")
133+
msg = "recording '%s' by '%s' has no artist MBID" % (album["name"], album["artist"])
134+
pbar.write(bcolors.FAIL + "FAIL " + bcolors.ENDC + msg)
135+
applog("FAIL " + msg)
136+
msg = "Consider retagging this file with Picard! ( https://picard.musicbrainz.org )"
137+
pbar.write(msg)
138+
applog(msg)
129139
self.error += 1
130140
continue
131141

@@ -145,8 +155,10 @@ def run_sync(self):
145155
})
146156

147157
if not self.quiet:
148-
pbar.write(bcolors.OKGREEN + "OK " + bcolors.ENDC + "album %-50s %-50s" %
149-
(album["name"][:49], album["artist"][:49]))
158+
msg = "album %-50s %-50s" % (album["name"][:49], album["artist"][:49])
159+
pbar.write(bcolors.OKGREEN + "OK " + bcolors.ENDC + msg)
160+
applog(msg)
161+
150162
self.matched += 1
151163
self.total += 1
152164
if not self.quiet:

0 commit comments

Comments
 (0)