Persistent Device Logging Module
DHawthorne
Posts: 4,584
I've seen several solutions for logging events on a NetLinx device that will survive a master reboot, but none of them really did what I needed for my own use. So I'm going to share what I cobbled together and am using in my own projects.
This module requires no external server. It creates a daily log file for every device you want to monitor on the RAM drive of the master itself, which you can then access by FTP'ing into the master. You can specify how many days worth of log files it will maintain, and there are hourly timestamps in the logs to help narrow down problem spots. The module supports 100 strings worth of filtering, to trap out all that useless dreck you don't need in your logs. If your system crashes and burns, the log should be intact up to, or pretty nearly up to, the time of impact .
I have been using this on several system, and have been tweaking it as I go; I've included the full source so anyone using it can do their own tweaking and modifications. I deem it ready for prime time, but you may have a different opinion, so feel free to adjust it as necessary on your own. If I make any significant changes, I'll repost it.
There is a Readme in the ZIP file that should cover everything you need to know to use the module. Don't forget to compile it, only the source is included.
EDIT: I have uploaded a new version below, and deleted this one because it was broken. See the post below...
This module requires no external server. It creates a daily log file for every device you want to monitor on the RAM drive of the master itself, which you can then access by FTP'ing into the master. You can specify how many days worth of log files it will maintain, and there are hourly timestamps in the logs to help narrow down problem spots. The module supports 100 strings worth of filtering, to trap out all that useless dreck you don't need in your logs. If your system crashes and burns, the log should be intact up to, or pretty nearly up to, the time of impact .
I have been using this on several system, and have been tweaking it as I go; I've included the full source so anyone using it can do their own tweaking and modifications. I deem it ready for prime time, but you may have a different opinion, so feel free to adjust it as necessary on your own. If I make any significant changes, I'll repost it.
There is a Readme in the ZIP file that should cover everything you need to know to use the module. Don't forget to compile it, only the source is included.
EDIT: I have uploaded a new version below, and deleted this one because it was broken. See the post below...
0
Comments
This could be handy for those hard to troubleshoot problems.
I made a quick update to that module before uploading it here, and didn't think it was a big enough change to warrant extensive testing. Well, it shouldn't have been, but it seems I broke the filtering feature. If you downloaded it, replace it with the one attached to this post.
I'm putting out a new version of this module that adds two things:
1) Drive space checking. I've found that a runaway error condition can potentially fill up the RAM drive with logged messages, especially on smaller masters (I have one of the original ME cards at home, it's tiny compared to the ME260 or ME260/64's). Since NetLinx does not seem to have any built-in memory checking functions (grumble), I've had to put in a once-a-minute query to the master for it's available drive space. Between queries, it updates the number based on what it knows it has written to the file, but this can only be considered an approximation because it can't know what other modules or processes may be doing to that number. Hence, the once-a-minute check to get the real value. I have also put in a user-settable threshhold at which logging will be disabled. For example, if you tell it to reserve 10,000 bytes, when there are 10,000 or less bytes free on the drive, logging will stop until some space is freed up. It will automatically restart when drive space becomes available. You can't set the threshhold below 2048, and I wouldn't think you would want to in any case .
2) E-mail notifications. The module now uses i!-EquipmentMonitorOut to send an e-mail notification if the available drive space reaches the reserved space threshhold. I would think the last thing you would want on a system you are monitoring is a full drive of error messages, and the logging happily shut down for weeks before you got around to checking it. Chances are, if you have run out of drive space, something dire has happened, and you need to look into it prontissimo. So, if you enable the e-mail, you will be notified and can do so right away.
These changes require some additions to the parameters to the module, so it's not exactly a drop-in replacement for version 1. You'll have to add those new parameters to update an existing project that uses it.
Paul d
Dave, this is a great module. I'm hopping to use this one for some troubleshooting.
Do you have a something similar that logs commands to/from an rs-232 port? I have a problematic Sanyo projector that seems to be intermittently locking up.
Thanks.
USE Send_String 0,
Thanks
All I need is to save logs to a local file on my master
thanks
The module is, I don't see any examples?
I saw the text file but it a bit complicated, all I need is a simple example, thanks
* maybe this is over kill, but I couldn't find any way to create a log file ( I searched the forum and found this thread)
I'm feeling generous... this will do what you want:
Many thanks!
I am sure this will help other people as well.
Too bad I can't add a tag, I named my respond as "log file", hope that it will do the work.
Ady
What do you mean?
logToFile("'TAG - Some Message Variable',foo")
of just edit the function.
Yes I know about all of the extra things that Daves module adds, but I was replying to the person asking for a simple way to make a log for a few days to find a bug. The module is over his head and overkill for that scenario.
I meant to the forum post
When I was developing that module, and before I put the memory check in, I actually had a runaway bug completely fill the master's memory drive in a matter of hours and lock the whole thing up. It takes surprisingly little. Perhaps it's not so easy nowadays, and the masters have a lot more onboard memory.
That said, for a temporary sort of thing, it might not be ill-advised to connect a laptop, open a telnet connection and set the client to log to a file, and just leave it running. That way, the drive space eaten up is on the laptop, not the master.
For tracking down specific bugs, that's exactly what I do. For logging and scripting, I prefer SecureCRT. I talked about it some in this thread: Controlling the Master from Batch Files
For logging, each profile can have a different method of logging. For example, I have one session for "daily" logging that creates a log file based on the date and auto sends "msg on 3" so I only get the SEND_STRING 0 messages, but I have a separate session for debugging purposes that initially sends "msg on all" and bases the log file on the current time (down to the millisecond if you need!) so that each time the processor reboots, I get a separate log file so I don't have to wade through hours of logging data to find that last error message.
When you do find that error message, you could use SCRT's great scripting integration to do almost anything with the data. While you can use JScript and Python for scripting, they have a great guide on using VBScript and quite a number of example VB scripts that come with the program. You can control almost every aspect of the program, including creating new sessions, starting/stopping logs, parsing/responding to data, modifying session parameters, and everything else VB is capable of.
-Nick
[size=-2]Fineprint: I swear I'm not being compensated by VanDyke Software. I just really like their program. ;-)[/size]