Skip to content

Commit

Permalink
Log All Line Matches (#113) 📖
Browse files Browse the repository at this point in the history
* Log All Line Matches
- Adds a new debug level
- Adds file size limits on debug files

* fix who_player matched bug
  • Loading branch information
mgeitz authored Mar 31, 2022
1 parent 7af124a commit 0624fa5
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ An Everquest Emulator Log Parser with NCurses Interface for Linux
Install from pypi
```sh
$ # Install Stable
$ pip3 install eqalert==2.4.10
$ pip3 install eqalert==2.5.5
$
$ # Install whatever I just pushed to pypi
$ pip3 install eqalert
Expand Down
27 changes: 22 additions & 5 deletions eqa/eqalert.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import threading
import time
import queue
from datetime import datetime

import eqa.lib.action as eqa_action
import eqa.lib.config as eqa_config
Expand Down Expand Up @@ -79,9 +78,14 @@ def startup(base_path):
# Set log file
logging.basicConfig(filename=log_path + "eqalert.log", level=logging.INFO)

# Make the debug directory
if not os.path.exists(base_path + "log/debug/"):
print(" - making a place for optional debug logs")
os.makedirs(base_path + "log/debug/")

# Make the sound directory
if not os.path.exists(sound_path):
print(" - making some sounds")
print(" - making a home for alert sounds")
os.makedirs(sound_path)

# Make the tmp sound directory
Expand Down Expand Up @@ -116,8 +120,9 @@ def startup(base_path):
elif not config["settings"]["version"] == str(
pkg_resources.get_distribution("eqalert").version
):
old_version = str(config["settings"]["version"]).replace(".", "-")
archive_config = (
base_path + "config_" + str(datetime.now().date()) + ".json"
base_path + "config_" + old_version + ".json"
)
print("Your config.json was generated by a older version of eqalert.")
print("Archiving old config to " + archive_config)
Expand Down Expand Up @@ -558,11 +563,23 @@ def system_debug(base_path, state, display_q, sound_q, new_message):
eqa_settings.eqa_time(),
"event",
"events",
"Debug mode enabled",
"Logging all unmatched lines",
)
)
sound_q.put(eqa_struct.sound("speak", "Debug mode enabled"))
sound_q.put(eqa_struct.sound("speak", "Logging all unmatched lines"))
elif state.debug == "true" and new_message.rx == "toggle":
state.set_debug("all")
eqa_config.set_last_state(state, base_path)
display_q.put(
eqa_struct.display(
eqa_settings.eqa_time(),
"event",
"events",
"Logging all line types",
)
)
sound_q.put(eqa_struct.sound("speak", "Logging all line types"))
elif state.debug == "all" and new_message.rx == "toggle":
state.set_debug("false")
eqa_config.set_last_state(state, base_path)
display_q.put(
Expand Down
88 changes: 80 additions & 8 deletions eqa/lib/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import sys
import time
import re
import os
from datetime import datetime

import eqa.lib.config as eqa_config
import eqa.lib.settings as eqa_settings
Expand Down Expand Up @@ -60,8 +62,11 @@ def process(
check_line = new_message.payload

# Line specific checks
if line_type == "undetermined" and state.debug == "true":
action_undetermined(check_line, base_path)
if state.debug != "false":
if line_type == "undetermined":
action_undetermined(check_line, base_path)
if state.debug == "all":
action_matched(line_type, check_line, base_path)
elif line_type == "location":
action_location(system_q, check_line)
elif line_type == "direction":
Expand Down Expand Up @@ -98,7 +103,13 @@ def process(
action_you_say_commands(system_q, check_line, config, mute_list)
elif line_type == "you_new_zone":
action_you_new_zone(
base_path, system_q, display_q, sound_q, state, config, check_line
base_path,
system_q,
display_q,
sound_q,
state,
config,
check_line,
)

# If line_type is a parsable type
Expand Down Expand Up @@ -736,7 +747,9 @@ def action_you_char_bound(system_q, check_line):
)


def action_you_new_zone(base_path, system_q, display_q, sound_q, state, config, check_line):
def action_you_new_zone(
base_path, system_q, display_q, sound_q, state, config, check_line
):
"""Perform actions for you new zone line types"""

try:
Expand Down Expand Up @@ -790,13 +803,72 @@ def action_you_new_zone(base_path, system_q, display_q, sound_q, state, config,
)


def action_matched(line_type, line, base_path):
"""Debug function to log all log lines and matches log lines"""

try:

matched_log = base_path + "log/debug/matched-lines.txt"
if os.path.exists(matched_log):
file_size = os.path.getsize(matched_log)
if file_size > 5000000:
version = str(pkg_resources.get_distribution("eqalert").version).replace(
".", "-"
)
archived_log = (
base_path
+ "log/debug/matched-lines_"
+ version
+ "_"
+ str(datetime.now().date())
+ ".txt"
)
os.rename(matched_log, archived_log)
matched_log_file = open(matched_log, "a")
matched_log_file.write('%-30s : %-70s\n' % (line_type, line))
matched_log_file.close()

except Exception as e:
eqa_settings.log(
"action matched: Error on line "
+ str(sys.exc_info()[-1].tb_lineno)
+ ": "
+ str(e)
)


def action_undetermined(line, base_path):
"""Debug function to log unmatched log lines"""

undetermined_log = base_path + "log/undetermined.txt"
undetermined_log_file = open(undetermined_log, "a")
undetermined_log_file.write(line + "\n")
undetermined_log_file.close()
try:

undetermined_log = base_path + "log/debug/undetermined-lines.txt"
if os.path.exists(undetermined_log):
file_size = os.path.getsize(undetermined_log)
if file_size > 5000000:
version = str(pkg_resources.get_distribution("eqalert").version).replace(
".", "-"
)
archived_log = (
base_path
+ "log/debug/undetermined-lines_"
+ version
+ "_"
+ str(datetime.now().date())
+ ".txt"
)
os.rename(undetermined_log, archived_log)
undetermined_log_file = open(undetermined_log, "a")
undetermined_log_file.write(line + "\n")
undetermined_log_file.close()

except Exception as e:
eqa_settings.log(
"action undetermined: Error on line "
+ str(sys.exc_info()[-1].tb_lineno)
+ ": "
+ str(e)
)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion eqa/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ def build_config(base_path):
"sound": "%ssound/",
"tmp_sound": "/tmp/eqa/sound/"
},
"version": "2.4.11"
"version": "2.5.5"
},
"zones": {
"An Arena (PVP) Area": "false",
Expand Down
2 changes: 1 addition & 1 deletion eqa/lib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ def check_who(line):
return "who_line_friends"
elif (
re.fullmatch(
r"^(AFK |\<LINKDEAD\>|AFK <LINKDEAD>|)\[(\d+ [a-zA-Z\s]+|ANONYMOUS)\] \w+( \([a-zA-Z\s]+\)|)( \<[a-zA-Z\s]+\>|)( ZONE\: \w+|)( LFG|)$",
r"^( AFK |\<LINKDEAD\>| AFK <LINKDEAD>|)\[(\d+ [a-zA-Z\s]+|ANONYMOUS)\] \w+( \([a-zA-Z\s]+\)|)( \<[a-zA-Z\s]+\>| \<[a-zA-Z\s]+\>|)( ZONE\: \w+|)( LFG|)$",
line,
)
is not None
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="eqalert",
version="2.4.11",
version="2.5.5",
author="Michael Geitz",
author_email="git@geitz.xyz",
install_requires=[
Expand Down

0 comments on commit 0624fa5

Please sign in to comment.