-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_log.py
More file actions
96 lines (71 loc) · 2.65 KB
/
check_log.py
File metadata and controls
96 lines (71 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
import obspython as obs
debug = False
script_settings = ''
source_name = ''
search_string = ''
def script_description():
return 'Look for a string in the current log file and notify the user in a text source if found.'
def script_properties():
props = obs.obs_properties_create()
# add text box at the settings page
obs.obs_properties_add_text(props, 'searchstring', 'Search in log:', obs.OBS_TEXT_DEFAULT)
# show a list of text sources to choose where to display the error
props_list = obs.obs_properties_add_list(props, 'source', 'Text Source', obs.OBS_COMBO_TYPE_LIST, obs.OBS_COMBO_FORMAT_STRING)
sources = obs.obs_enum_sources()
if sources:
for source in sources:
source_id = obs.obs_source_get_unversioned_id(source)
if source_id == 'text_gdiplus' or source_id == 'text_ft2_source':
name = obs.obs_source_get_name(source)
obs.obs_property_list_add_string(props_list, name, name)
obs.source_list_release(sources)
return props
def script_load(settings):
"""
Called when loading the script
"""
# make settings available everywhere
global script_settings
script_settings = settings
obs.obs_frontend_add_event_callback(event_handler)
def script_update(settings):
# user set some config
global source_name, search_string
source_name = obs.obs_data_get_string(settings, 'source')
search_string = obs.obs_data_get_string(settings, 'searchstring')
def refresh_pressed(props, prop):
"""
Called when the 'refresh' button defined below is pressed
"""
update_text('Reloaded!')
def script_unload():
"""
Called when unloading the script
"""
update_text('Unloaded!')
def event_handler(event):
if event in (obs.OBS_FRONTEND_EVENT_FINISHED_LOADING, obs.OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED):
# empty the text source before checking
text = ''
update_text(text)
check_log(script_settings)
def check_log(settings):
log_dir = os.getenv('appdata') + '/obs-studio/logs/'
log_list = sorted(os.listdir(log_dir))
log_file = log_list[-1]
if debug:
# create this file next to the logs with the string you are looking for
log_file = '1debug.txt'
l = open(log_dir + log_file, 'r')
log = l.read()
l.close()
if search_string in log:
text = 'Log has error'
update_text(text)
def update_text(text):
source = obs.obs_get_source_by_name(source_name)
if source:
obs.obs_data_set_string(script_settings, 'text', text)
obs.obs_source_update(source, script_settings)
obs.obs_source_release(source)