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.

log events to file

If you have a question or need help, this is the place to be.
Post Reply
manjh
Posts: 41
Joined: Thu Mar 12, 2009 11:14 am

log events to file

Post by manjh »

I have been using EG now for a while, and am increasingly happy with the possibilities, discovering new things all the time.
The one thing that I have been looking for with no result is a way to log events into a file, which I can later use for analysis. In fact, if I can save and access the log at the left half of the screen, then that would cover it.
Seems like a basic thing, so I can't imagine that there is nothing to do this... I must be looking in the wrong plugins.
Can anyone point me in the right direction?
LaTropa64
Posts: 5
Joined: Thu Apr 09, 2009 7:33 pm

Re: log events to file

Post by LaTropa64 »

manjh wrote:I have been using EG now for a while, and am increasingly happy with the possibilities, discovering new things all the time.
The one thing that I have been looking for with no result is a way to log events into a file, which I can later use for analysis. In fact, if I can save and access the log at the left half of the screen, then that would cover it.
Seems like a basic thing, so I can't imagine that there is nothing to do this... I must be looking in the wrong plugins.
Can anyone point me in the right direction?
Select the first event in the log, scroll to the bottom, hold shift and click the last event. Right click > Copy. Paste to notepad.
manjh
Posts: 41
Joined: Thu Mar 12, 2009 11:14 am

Re: log events to file

Post by manjh »

LaTropa64 wrote:
manjh wrote:I have been using EG now for a while, and am increasingly happy with the possibilities, discovering new things all the time.
The one thing that I have been looking for with no result is a way to log events into a file, which I can later use for analysis. In fact, if I can save and access the log at the left half of the screen, then that would cover it.
Seems like a basic thing, so I can't imagine that there is nothing to do this... I must be looking in the wrong plugins.
Can anyone point me in the right direction?
Select the first event in the log, scroll to the bottom, hold shift and click the last event. Right click > Copy. Paste to notepad.
Thanks for your reply, but that wasn't quite what I was looking for.
I wanted to log events automatically and selectively. For instance, I want to log the date/time that my door open sensors send a signal. If I could trigger a "log record" into a file from within a macro, I could do what I intended...
manjh
Posts: 41
Joined: Thu Mar 12, 2009 11:14 am

Re: log events to file

Post by manjh »

ideas, anyone?
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: log events to file

Post by krambriw »

Well, I would write a small plugin that should
- have settings for which type of events you are interested in (with wildcards)
- write those to a logfile (ev with settings for format/path/name and type (txt, html))

Capturing events in python is not so difficult. Writing to a log file is also simple. Making a plugin is not so hard either

In many plugins you actually can find examples of what you are asking for. Maybe your effort can be reduced to some smart copy & paste exercise :wink:

Look at some plugins already made by all authors

Best regards, Walter
manjh
Posts: 41
Joined: Thu Mar 12, 2009 11:14 am

Re: log events to file

Post by manjh »

Oops.... there is a plugin called File Operations that does just that.
Teaches me to look a bit deeper before asking.
manjh
Posts: 41
Joined: Thu Mar 12, 2009 11:14 am

Re: log events to file

Post by manjh »

I've been playing around with the file operations plugin, and would like to write some data to a file.
One of my events comes from a micro processor, and after the event identifier it carries some data that I need to log.
I suspected a variable "payload" or "input", or something alike, but no luck.
The only variable I found that works, is "eg.result". But that gives me meta-information about the USB link that the event came in across, and nothing about the data in the event itself.
Is there a way to capture that data into the file operation, without actually going into plugin-writing?
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: log events to file

Post by krambriw »

Hi, maybe something like this can help you

Best regards, Walter


I created a simple setup here with a macro holding two actions and a python script (see picture)
Image3.jpg
Image3.jpg (37.78 KiB) Viewed 4717 times
When an event is received that matches, the python script executes and logs the event to a html-file

The script looks like this:

Code: Select all

import time, os, sys

def LogToFile(s):
    majorVersion = sys.getwindowsversion()[0:2]
    
    timeStamp = str(
        time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    )
    logStr = timeStamp+"\t"+s+"<br\n>"
    
    if majorVersion > 5:
        progData = os.environ['ALLUSERSPROFILE']
        if not os.path.exists(progData+"/EventGhost/Log") and not os.path.isdir(progData+"/EventGhost/Log"):
            os.makedirs(progData+"/EventGhost/Log")
        fileHandle = open (progData+'/EventGhost/Log/MyLog.html', 'a' )
        fileHandle.write ( logStr )
        fileHandle.close ()
    else:
        if not os.path.exists('Log') and not os.path.isdir('Log'):
            os.mkdir('Log')
        fileHandle = open ( 'Log/MyLog.html', 'a' )
        fileHandle.write ( logStr )
        fileHandle.close ()


LogToFile(eg.event.string+"|||"+str(eg.event.payload))
manjh
Posts: 41
Joined: Thu Mar 12, 2009 11:14 am

Re: log events to file

Post by manjh »

krambriw wrote:Hi, maybe something like this can help you
Before I start, apologies for being new to this Python stuff... :-)

I created a macro with the Python script as you provided, and EG gives me this at startup:
Error compiling script.
Traceback (most recent call last) (1076):
File "C:\temp\EventGhost\eg\Classes\ActionItem.py", line 149, in SetArgs
File "C:\temp\EventGhost\plugins\EventGhost\PythonScript.py", line 76, in __init__
File "C:\temp\EventGhost\plugins\EventGhost\PythonScript.py", line 102, in PrintTraceback
AttributeError: 'NoneType' object has no attribute 'PrintError'
I linked the middle mouse button as an event to the macro, and when I press it, this shows up:
Mouse.MiddleButton
Python Script
Python Script
Error in Action: "Python Script"
Traceback (most recent call last) (1076):
TypeError: 'NoneType' object is not callable
I'm sure it is something obvious that I missed, but what is wrong?
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: log events to file

Post by krambriw »

Very strange...I do not think it is the script itself that crashes (no such line numbers and variable names in the script)

Make a new simple setup with EG and try again


Best regards, Walter
manjh
Posts: 41
Joined: Thu Mar 12, 2009 11:14 am

Re: log events to file

Post by manjh »

I gave up when I found out I can do just what I want with the File Operations plugin, using variable eg.event.string and writing that to a file.

I did notice, however, that the filename has to be filled in as a "real" filename.
I tried assigning the name to a global variable and use that in the outputfile field, but that is not resolved.
confirmator
Posts: 22
Joined: Sat Apr 05, 2008 7:10 pm

Re: log events to file

Post by confirmator »

Is there a variable which would return anything that gets written in the log, instead of just events like eg.event.string?

I am trying to chase down a bug that apparently only appears when EG is minimized to tray, so a full log might be conclusive.
But I haven't found a way to have EG write its full log to disk :/
Post Reply