Skip to content

Commit

Permalink
Merge pull request #24 from seanap/develop
Browse files Browse the repository at this point in the history
Use real log levels
  • Loading branch information
djdembeck authored Aug 30, 2021
2 parents 7068757 + 11e4e9a commit 4e5167f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 25 deletions.
21 changes: 10 additions & 11 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from update_tools import UpdateTool
from urls import SiteUrl

VERSION_NO = '2021.08.29.2'
VERSION_NO = '2021.08.30.1'

# Delay used when requesting HTML,
# may be good to have to prevent being banned from the site
Expand All @@ -34,7 +34,7 @@ def ValidatePrefs():


def Start():
# HTTP.ClearCache()
HTTP.ClearCache()
HTTP.CacheTime = CACHE_1WEEK
HTTP.Headers['User-agent'] = (
'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0;'
Expand Down Expand Up @@ -120,7 +120,7 @@ def search(self, results, media, lang, manual=False):
log.debug(
'* Artist: %s', media.artist
)
log.debug(
log.error(
'****************************************'
'Not Ready For Artist Search Yet'
'****************************************'
Expand All @@ -140,7 +140,7 @@ def worker(self, queue, stoprequest):
try:
func(*args, **kargs)
except Exception as e:
log.info(e)
log.error(e)
queue.task_done()
except Queue.Empty:
continue
Expand Down Expand Up @@ -184,7 +184,7 @@ def search(self, results, media, lang, manual):

# Write search result status to log
if not result:
log.info(
log.warn(
'No results found for query "%s"',
normalizedName
)
Expand Down Expand Up @@ -250,7 +250,7 @@ def update(self, metadata, media, lang, force=False):
try:
html = HTML.ElementFromURL(url, sleep=REQUEST_DELAY)
except Exception as e:
log.info(e)
log.error(e)

# Instantiate update helper
update_helper = UpdateTool(force, lang, media, metadata, url)
Expand Down Expand Up @@ -627,7 +627,6 @@ def date_missing(self, helper, html):
r'([^\\])(\\(?![bfnrt\'\"\\/]|u[A-Fa-f0-9]{4}))'
)
page_content = remove_inv_json_esc.sub(r'\1\\\2', page_content)
log.debug(page_content)
json_data = self.json_decode(page_content)

helper.re_parse_with_date_published(json_data)
Expand Down Expand Up @@ -790,10 +789,10 @@ def add_series_to_moods(self, helper):
"""
Adds book series' to moods, since collections are not supported
"""

helper.metadata.moods.add(helper.series)
if helper.series:
helper.metadata.moods.add("Series: " + helper.series)
if helper.series2:
helper.metadata.moods.add(helper.series2)
helper.metadata.moods.add("Series: " + helper.series2)

def parse_series(self, helper):
# Clean series
Expand Down Expand Up @@ -887,7 +886,7 @@ def worker(self, queue, stoprequest):
try:
func(*args, **kargs)
except Exception as e:
log.info(e)
log.error(e)
queue.task_done()
except Queue.Empty:
continue
Expand Down
44 changes: 39 additions & 5 deletions Contents/Code/logging.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
class Logging:
# Only prints message with debug mode
def debug(self, message, *args):
if Prefs['debug']:
return Log(message, *args)
"""
Prints passed message with DEBUG TYPE,
when DEBUG pref enabled.
"""
if Prefs['logging_level'] == "DEBUG":
return Log.Debug(message, *args)

# Prints any message you give
def info(self, message, *args):
return Log(message, *args)
"""
Prints passed message with INFO TYPE,
when INFO or DEBUG pref enabled.
"""
if Prefs['logging_level'] == "DEBUG" or (
Prefs['logging_level'] == "INFO"
):
return Log(message, *args)

def warning(self, message, *args):
"""
Prints passed message with INFO TYPE,
when DEBUG, INFO or WARN pref enabled.
"""
if Prefs['logging_level'] == "DEBUG" or (
Prefs['logging_level'] == "INFO") or (
Prefs['logging_level'] == "WARN"
):
# No builtin warn, so use info level for it
return Log(message, *args)

def error(self, message, *args):
"""
Prints passed message with ERROR TYPE,
when DEBUG, INFO, WARN or ERROR pref enabled.
"""
if Prefs['logging_level'] == "DEBUG" or (
Prefs['logging_level'] == "INFO") or (
Prefs['logging_level'] == "WARN") or (
Prefs['logging_level'] == "ERROR"
):
return Log.Error(message, *args)

# For the below logging:
# Default level is info
# Set debug by calling ('sometext', 'debug')
# Set debug by calling (msg='sometext', log_level='debug')

# Prints a bunch of divider chars like ---
def separator(self, msg=None, log_level="info"):
Expand Down
4 changes: 2 additions & 2 deletions Contents/Code/search_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, lang, manual, media, results):
def check_if_preorder(self, book_date):
current_date = (date.today())
if book_date > current_date:
log.debug("Excluding pre-order book")
log.info("Excluding pre-order book")
return True

def get_id_from_url(self, item):
Expand All @@ -29,7 +29,7 @@ def get_id_from_url(self, item):
if asin:
return asin

log.info('No Match: %s', url)
log.warn('No Match: %s', url)
return None

def pre_search_logging(self):
Expand Down
4 changes: 2 additions & 2 deletions Contents/Code/update_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def re_parse_with_date_published(self, json_data):
except AttributeError:
continue
except IndexError:
log.info(
log.warn(
'"' + self.title + '", '
"only has one genre"
)
Expand All @@ -80,7 +80,7 @@ def writeInfo(self):

# Log basic metadata stored in arrays
multi_arr = [
{'Genres & Series': self.metadata.genres},
{'Genres': self.metadata.genres},
{'Moods(Authors)': self.metadata.moods},
{'Styles(Narrators)': self.metadata.styles},
]
Expand Down
16 changes: 11 additions & 5 deletions Contents/DefaultPrefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@
"type": "bool",
"default": "false"
},{
"id": "debug",
"label": "Ouput debugging info in logs",
"type": "bool",
"default": "false"
}]
"id": "logging_level",
"label": "Level of plugin logging: ",
"type": "enum",
"values": [
"DEBUG",
"INFO",
"WARN",
"ERROR"
],
"default": "WARN"
}]

0 comments on commit 4e5167f

Please # to comment.