# Buggy code
def from_line(cls, line):
    """Create a Log Line from a string line.

    :param line:
    :type line: str
    :return:
    :rtype: LogLine or None
    """
    lines = line.split("\n")
    match = LogLine.log_re.match(lines[0])
    if not match:
        return

    g = match.groupdict()
    return LogLine(
        line=lines[0],
        message=g["message"],
        level_name=g["level_name"],
        extra=g.get("extra"),
        curhash=g["curhash"],
        thread_name=g["thread_name"],
        thread_id=int(g["thread_id"]) if g["thread_id"] else None,
        traceback_lines=lines[1:],
        timestamp=datetime.datetime(
            year=int(g["year"]),
            month=int(g["month"]),
            day=int(g["day"]),
            hour=int(g["hour"]),
            minute=int(g["minute"]),
            second=int(g["second"]),
        ),
    )


# Traceback (UnicodeDecodeError)
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for The Five set to: [ the five uk, the five ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Strong set to: [ strong ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Tomorrow When the War Began set to: [ tomorrow when the war began ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for BrainDead set to: [ braindead ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Southern Justice set to: [ southern justice ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for The Returned (US) set to: [ the returned us ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for The Path set to: [ the path ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Submission set to: [ submission ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Coupled set to: [ coupled ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Seven Year Switch (AU) set to: [ seven year switch au ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Person of Interest set to: [ person of interest ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Animal Kingdom (2016) set to: [ animal kingdom us, animal kingdom 2016 ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Lady Dynamite set to: [ lady dynamite ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Still the King set to: [ still the king ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for The Durrells set to: [ the durrells ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Wrecked (2016) set to: [ wrecked, wrecked 2016 ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Dead of Summer set to: [ dead of summer ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Guilt set to: [ guilt ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Secret City set to: [ secret city ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Barbarians Rising set to: [ barbarians rising ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Shooter set to: [ shooter ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Face Off set to: [ face off ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Separation Anxiety set to: [ separation anxiety ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Top Gear (US) set to: [ top gear us ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Las Vegas Law (2016) set to: [ las vegas law 2016, las vegas law ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Private Eyes set to: [ private eyes ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Spartan: Ultimate Team Challenge set to: [ spartan ultimate team challenge ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for The Sex Factor set to: [ the sex factor 2016, the sex factor, sex factor ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Timeless (2016) set to: [ timeless 2016, timeless ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for MacGyver (2016) set to: [ macgyver 2016 ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Frequency set to: [ frequency ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for The Good Place set to: [ the good place ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for This Is Us set to: [ this is us ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for American Gods set to: [ american gods ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Conviction (2016) set to: [ conviction 2016 ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Quarry set to: [ quarry ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for The Amazing Race Canada set to: [ the amazing race canada ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for The Night Of set to: [ the night of ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Aftermath (2016) set to: [ aftermath 2016 ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Better Things set to: [ better things ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Goliath set to: [ goliath ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for People of Earth set to: [ people of earth ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for StartUp (2016) set to: [ startup 2016 ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Chance set to: [ chance ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Chesapeake Shores set to: [ chesapeake shores ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Lethal Weapon set to: [ lethal weapon ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Pure Genius set to: [ pure genius ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for No Tomorrow set to: [ no tomorrow ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Kevin Can Wait set to: [ kevin can wait ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Falling Water set to: [ falling water ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Speechless set to: [ speechless ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Pitch set to: [ pitch ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for One Of Us set to: [ one of us ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Notorious (2016) set to: [ notorious 2016, notorious ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Man With A Plan set to: [ man with a plan ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Vice Principals set to: [ vice principals ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Fleabag set to: [ fleabag ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Mickey Mouse Clubhouse set to: [ mickey mouse clubhouse ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Divorce (2016) set to: [ divorce 2016 ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for American Housewife set to: [ american housewife ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Easy set to: [ easy ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Chicago Justice set to: [ chicago justice ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Designated Survivor set to: [ designated survivor ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Bull (2016) set to: [ bull 2016 ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Making History (2016) set to: [ making history 2016 ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Internal name cache for Big Brother: Over the Top set to: [ big brother over the top ]
2016-10-09 07:41:58 DEBUG    MAIN :: [61b6052] Finished updating network timezones
2016-10-09 07:41:59 DEBUG    CHECKVERSION :: [61b6052] "C:\Users\rusty\AppData\Local\GitHub\PortableGit_284a859b0e6deba86edc624fef1e4db2aa8241a9\cmd\git.exe" fetch origin : returned successful
2016-10-09 07:41:59 DEBUG    CHECKVERSION :: [61b6052] Executing "C:\Users\rusty\AppData\Local\GitHub\PortableGit_284a859b0e6deba86edc624fef1e4db2aa8241a9\cmd\git.exe" rev-parse --verify --quiet "@{upstream}" with your shell in C:\pymedusaSickRage
2016-10-09 07:41:59 DEBUG    CHECKVERSION :: [61b6052] "C:\Users\rusty\AppData\Local\GitHub\PortableGit_284a859b0e6deba86edc624fef1e4db2aa8241a9\cmd\git.exe" rev-parse --verify --quiet "@{upstream}" : returned successful
2016-10-09 07:41:59 DEBUG    CHECKVERSION :: [61b6052] Executing "C:\Users\rusty\AppData\Local\GitHub\PortableGit_284a859b0e6deba86edc624fef1e4db2aa8241a9\cmd\git.exe" rev-list --left-right "@{upstream}"...HEAD with your shell in C:\pymedusaSickRage
2016-10-09 07:41:59 DEBUG    CHECKVERSION :: [61b6052] "C:\Users\rusty\AppData\Local\GitHub\PortableGit_284a859b0e6deba86edc624fef1e4db2aa8241a9\cmd\git.exe" rev-list --left-right "@{upstream}"...HEAD : returned successful
2016-10-09 07:41:59 DEBUG    CHECKVERSION :: [61b6052] cur_commit = 61b60522b98450f541a0f9c4b57c8242338432ba, newest_commit = 61b60522b98450f541a0f9c4b57c8242338432ba, num_commits_behind = 0, num_commits_ahead = 0
2016-10-09 07:41:59 DEBUG    CHECKVERSION :: [61b6052] check_for_new_news: Checking GitHub for latest news.
2016-10-09 07:42:10 ERROR    Thread-18 :: [61b6052] Failed doing web ui callback: Traceback (most recent call last):
  File "C:\pymedusaSickRage\medusa\server\web\core\base.py", line 270, in async_call
    result = function(**kwargs)
  File "C:\pymedusaSickRage\medusa\server\web\core\error_logs.py", line 133, in viewlog
    predicate=lambda l: filter_logline(l, min_level=min_level,
  File "C:\pymedusaSickRage\medusa\logger.py", line 142, in read_loglines
    logline = LogLine.from_line(line)
  File "C:\pymedusaSickRage\medusa\logger.py", line 375, in from_line
    lines = line.split('\n')
  File "C:\Python27\lib\encodings\cp1252.py", line 15, in decode
    return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 106: character maps to <undefined>
Traceback (most recent call last):
  File "C:\pymedusaSickRage\medusa\server\web\core\base.py", line 270, in async_call
    result = function(**kwargs)
  File "C:\pymedusaSickRage\medusa\server\web\core\error_logs.py", line 133, in viewlog
    predicate=lambda l: filter_logline(l, min_level=min_level,
  File "C:\pymedusaSickRage\medusa\logger.py", line 142, in read_loglines
    logline = LogLine.from_line(line)
  File "C:\pymedusaSickRage\medusa\logger.py", line 375, in from_line
    lines = line.split('\n')
  File "C:\Python27\lib\encodings\cp1252.py", line 15, in decode
    return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 106: character maps to <undefined>

# Fixed code
def from_line(cls, line):
    """Create a Log Line from a string line.

    :param line:
    :type line: str
    :return:
    :rtype: LogLine or None
    """
    lines = line.split(b"\n")
    match = LogLine.log_re.match(lines[0])
    if not match:
        return

    g = match.groupdict()
    return LogLine(
        line=lines[0],
        message=g["message"],
        level_name=g["level_name"],
        extra=g.get("extra"),
        curhash=g["curhash"],
        thread_name=g["thread_name"],
        thread_id=int(g["thread_id"]) if g["thread_id"] else None,
        traceback_lines=lines[1:],
        timestamp=datetime.datetime(
            year=int(g["year"]),
            month=int(g["month"]),
            day=int(g["day"]),
            hour=int(g["hour"]),
            minute=int(g["minute"]),
            second=int(g["second"]),
        ),
    )