Keeping on top of your Server

Cwood3Cwood3 Moderator Posts: 23 mod
edited April 2018 in Power Tools

Over the last several month, I have encountered a number of errors, including SQL Deadlocks, table creation failures, etc.

In order to keep on top of potential problems, I have been in the habit of copying the AdeptServer.log file and reviewing the file frequently(sometimes daily). As the log file size increases, it becomes more arduous to review. At times it grew so large that I could not open it via Notepad, or Excel. I needed another solution.

I wrote a fairly simple Python 3 script (with some help) which can quickly parse the file and write the relevant sections to an output file. The file has a string variable that is what is searched for. When it finds the string in the current line being parsed it writes a few lines above, the current line and a few lines below to the output file. The script will process the log file and open the result file for you.

Step 1. Run the Python 3 script (using IDLE, Visual Studio, Geany, or save script as a ".py" file and call it via Python).
Step 2. Enter the path and file name for where the AdeptServer.log (copy) is located. If you edit the path in the script for a default path\name, you can hit enter for the default.
Step 3. Enter the path and file name for where the output file should go. If you edit the path in the script for a default path\name, you can hit enter for the default.
Step 4. Enter an option "a", "b", or "c" to select which type of error you are interested (any, connection closed, or deadlock.
Step 5. Wait patiently, it only takes a few moments.
Step 6. Review the specified errors in a neat, compact output without having to scroll through thousands lf lines.

This let's me process the log file incredibly quickly and focus on the problem areas.

Here is the script: (Due to formatting issues, copy this and replace the "_" with " "

import_subprocess_as_sp

print("Welcome_to_the_Adept_Log_Checker")
print("Please_enter_the_Adept_Log_file_path/name_")
InPutFile_=input("or_hit_return_for_default.")#f:/AdeptServer.log"
____if_InPutFile.lower()=="x":
________sp.call("explorer_f:\",_shell=True)
if_InPutFile
=="":
_____InPutFile_="f:/AdeptServer.log"#Edit_this_to_where_you_have_your_default_file_location_is
OutPutFile_=input("Please_enter_the_path/name_for_the_output_file,_or_hit_return_for_default:")
if_OutPutFile_=="":
_____OutPutFile
="f:/errorOutputFile.txt"#Edit_this_to_where_you_have_your_default_file_location_is
print("Please_select_an_Option")
print("a)_Check_for_any_error")
print("_b)_Check_for_closed_connection")
print("_c)_Check_for_deadlocks")
selected
=input("_a,_b,_or_c?:")
____if_selected_=="a":
________myString="Adept_Server_has_encountered_the_following_error:"
____elif_selected
=="b":
________myString="The_connection's_current_state_is_closed"
____elif_selected
=="c":
________myString_="deadlocked"
____else_:
________print("You_made_a_bad_choice")
________print("Press_any_key_to_exit")
________exit
print("....Reading_the_file.Be_patient\n")
errorCount
=0
array
=[]
with_open(InPutFile)_as_f:
____lineCount
=sum(1_for___in_f)
f.close
print("...Started_Processing\n")
with_open(InPutFile,
'r')as_infile,_open(OutPutFile,'w')_as_outfile:
____for_x_in_range(0,20):
________s
=infile.readline()
________if
""_in_s:
____________array.append(s)
____for_y_in_range(0,_lineCount-20):
________if_y==(lineCount/2)_or_y==((lineCount/2)+.5):
____________print("..Half_way_there!..\n")
________z
=infile.readline()
________if
""_in_z:
____________if
(myString_in_array[4])and(myString_not_in_array[5]):
________________errorCount=errorCount+1
________________for_i_in_range(0,len(array)):
____________________outfile.writelines(array[i])
________________outfile.write('\n\n')
____________del_array[0]
____________array.append(z)
print(".Yipppeeee!We're_done!\n")
print("There_were
",errorCount,"_errors_detected")
programName
="notepad.exe"#Edit_to_change_default_text_file_viewer
sp.Popen([programName,_OutPutFile])

Best Answers

Sign In or Register to comment.