Hello, I am stuck. I can not find the variable or dict object that holds the logged messages out of the 2000 in the left panel. I have looked in LogCtrl.py, eg.log and the forums but I am not finding it
I would like to search for an event or message trigger in the past five minutes.
Thanks, Brandon
Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
Log Message Variable
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Log Message Variable
eg.document.frame.logCtrl.data
and it's a list and the one line in the log is one index in the list. and that entry is also a list representing the information as such
(line, icon, wRef, when, indent)
line = text in the log
icon = the icon
wref = is a weak reference dictionary of the class that caused the log entry (if there is one recorded), by calling this func = wRef() it will return the instance of the calling function
when - i am pretty sure it's epoch time of when the entry occurred so using the code below will turn it onto a string and print it out
indent - how much to indent the log entry. i think this is a numerical value of the number of times to indent and not an actual string value of the indent
so it will look like this
happy poking around.
Oh and also. you can add a function to the log listeners
so now every time an entry is made into the log it will also send that entry to newlog.WriteLine and from there you can take the data and do whatever it is you want.
if you do a simple comparison between icon and eg.icons.EVENT_ICON you can tell if the item is an event or not
but you can pretty much use that to separate what the log entry is
here is a list of icons that you can use from eg.icons
INFO_ICON
ERROR_ICON
NOTICE_ICON
EVENT_ICON
FOLDER_ICON
PLUGIN_ICON (stock plugin icon)
ACTION_ICON (stock action icon)
MACRO_ICON
and it's a list and the one line in the log is one index in the list. and that entry is also a list representing the information as such
(line, icon, wRef, when, indent)
line = text in the log
icon = the icon
wref = is a weak reference dictionary of the class that caused the log entry (if there is one recorded), by calling this func = wRef() it will return the instance of the calling function
when - i am pretty sure it's epoch time of when the entry occurred so using the code below will turn it onto a string and print it out
Code: Select all
from time import localtime, strftime
# use this for time only
print strftime(" %H:%M:%S ", localtime(when))
# use this for the date and time
print strftime(" %x - %H:%M:%S ", localtime(when))
so it will look like this
Code: Select all
[
(line, icon, wRef, when, indent),
(line, icon, wRef, when, indent),
(line, icon, wRef, when, indent)
]
Oh and also. you can add a function to the log listeners
Code: Select all
class newlog:
def __init__(self):
pass
def WriteLine(line, icon, wRef, when, indent):
# do something with the data
eg.log.AddLogListener(newlog())
if you do a simple comparison between icon and eg.icons.EVENT_ICON you can tell if the item is an event or not
but you can pretty much use that to separate what the log entry is
here is a list of icons that you can use from eg.icons
INFO_ICON
ERROR_ICON
NOTICE_ICON
EVENT_ICON
FOLDER_ICON
PLUGIN_ICON (stock plugin icon)
ACTION_ICON (stock action icon)
MACRO_ICON
-
m19brandon
- Experienced User
- Posts: 177
- Joined: Mon Feb 03, 2014 10:36 pm
Re: Log Message Variable
Thanks, works great.
Code: Select all
def checkeventincurrntlog(event):
e = False
dt_l = datetime.datetime.now() - datetime.timedelta(minutes=30)
logs = eg.document.frame.logCtrl.data
cur_log = []
for l in list(logs):
#t = strftime(" %x - %H:%M:%S ", localtime(l[3]))
dt = datetime.datetime.fromtimestamp(mktime(localtime(l[3])))
if dt > dt_l and event in l[0]:
#tm = localtime(l[3])
#cur_log.append((tm, l[0]))
e = True
exit
return e
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Log Message Variable
after the last month or so. i have done some much in the way of modifications to the core of EG and reading the code i think i can pretty much tell you where just about every thing is and how to get to it. so please feel free to ask away. I think that for your scenario it might be more efficient code to do this instead because this will overwrite duplicate log entries, and also converts the "when" at time the log entry is made so it doesn't have to do it for every single item at iteration time. but you can also simply iter through the class and get a result. or you can change the __iter__ to __call__(event) and go that route if you want. the issue is with you way it iters through every single log entry, and I am not sure what the limit is on EG. but it's up there and that's a lot of items.
we can also truncate the list if it is always an event you are looking for by changing this code
to this
or add having it prune the dict when a log entry is made instead. i personally like this the best because it is being done from a different thread then what your plugin operates on so it's not a performance hit to remove stale entries but i would only go this route if i was only monitoring for events and nothing else. otherwise the dict could still be large enough to cause an impact on EventGhost making log entries. or have it run a thread at the time an entry is made to prune the thing.
Code: Select all
import eg
import datetime
from time import localtime, mktime
class Event:
def __init__(self):
self.data = {}
eg.log.AddLogListener(self)
def __iter__(self):
dt = datetime.datetime.now()
for key in self.data.keys():
if self.data[key] >= dt:
yield key
else:
del(self.data[key])
def WriteLine(self, line, icon, wRef, when, indent):
when = datetime.datetime.fromtimestamp(mktime(localtime(when)))
when += datetime.timedelta(minutes=30)
self.data[line] = when
Event = Event()
for event in Event:
if event.find('TestEvent') > -1:
#do code here
Code: Select all
def WriteLine(self, line, icon, wRef, when, indent):
when = datetime.datetime.fromtimestamp(mktime(localtime(when)))
when += datetime.timedelta(minutes=30)
self.data[line] = when
Code: Select all
def WriteLine(self, line, icon, wRef, when, indent):
if icon == eg.icons.EVENT_ICON:
when = datetime.datetime.fromtimestamp(mktime(localtime(when)))
when += datetime.timedelta(minutes=30)
self.data[line] = when
Code: Select all
def WriteLine(self, line, icon, wRef, when, indent):
if icon == eg.icons.EVENT_ICON:
when = datetime.datetime.fromtimestamp(mktime(localtime(when)))
when += datetime.timedelta(minutes=30)
self.data[line] = when
dt = datetime.datetime.now()
for key in self.data.keys():
if self.data[key] < dt:
del(self.data[key])
-
m19brandon
- Experienced User
- Posts: 177
- Joined: Mon Feb 03, 2014 10:36 pm
Re: Log Message Variable
I noticed eg.document.frame.logCtrl.data on work if EG is open, if in the tray it return a NoneType.
But I was able to search the logCtrl code and found that eg.log.data is the same list and always returns.
I am using this to clear up a suggestion engine I wrote. No need to suggest an event if has already been ran recently.
It working get, thanks for the help.
But I was able to search the logCtrl code and found that eg.log.data is the same list and always returns.
I am using this to clear up a suggestion engine I wrote. No need to suggest an event if has already been ran recently.
It working get, thanks for the help.
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Log Message Variable
i didn't even think about having the thing minimized. because the frame instance would be a None because it's Destroyed. (kinda of an odd way to handle minimizing something but that is how it's done. don't know exactly why. it could just be hidden and not cause the issue.)
i am not sure if the log.data is identical. because there are several methods in log that print out different things i am not sure if all of them add to the log.data. i don't believe they all do. i think things like PrintTraceback is not added or any Print methods to be honest with you. but i am not sure I would have to look at the code. but if the log entries you are looking for are there then great. i think using the log listener method should work if eg is minimized or not.
and key no worries. I am glad to help. I know how it is when you are searching for something for days on end. you feel like ripping your hair out.
i am not sure if the log.data is identical. because there are several methods in log that print out different things i am not sure if all of them add to the log.data. i don't believe they all do. i think things like PrintTraceback is not added or any Print methods to be honest with you. but i am not sure I would have to look at the code. but if the log entries you are looking for are there then great. i think using the log listener method should work if eg is minimized or not.
and key no worries. I am glad to help. I know how it is when you are searching for something for days on end. you feel like ripping your hair out.
