Multiple problems with OpenLog

Posted by Vincitore on Wed 23 Feb 2011 11:48 PM — 6 posts, 21,717 views.

#0
I'm trying to create an alias to open a log, get some information, and close the log. It doesn't work, though, although there's no problem with opening the log manually--just with OpenLog.

Here's an alias I wrote for testing:
OpenLog ("test.txt", true)
Note(IsLogOpen())
SetLogOutput (true)
Note(GetLogOutput ())
SetLogInput (true)
Note(GetLogInput ())
Send ("do look,hop")
WriteLog("--- Message for the log file ---")
CloseLog()
FlushLog()

And here's what it appends to test.txt:
true
true
true
--- Message for the log file ---

I see the output for "do look,hop" in the game window, but it isn't appended to the file.

Also, OpenLog ignores the chosen log directory. In XP it would save stuff in the Start Menu folder, for some reason, and in Windows 7 it saves in C:\Mushclient. Trying to set a relative or absolute path fails entirely; I get "false" for IsLogOpen. I don't really care about this part, since I can figure out where to find the files... but not being able to log game output (unless I manually open the log) is a pain. Is this a problem with OpenLog or with something I'm doing?
Australia Forum Administrator #1
Well let's see...

  • If you don't specify a path name it opens files in the "current directory" whatever that is. You might want to try:

    
    OpenLog (GetInfo (58) .. "test.txt", true)
    


    Where GetInfo (58) is the default log files directory.
  • You need to flush the log before closing it. Once it is closed it can't be flushed. However closing flushes it anyway. The idea of flushing is to force out half-filled blocks in case of a crash, so you might do that every 5 minutes or so.
  • Your script executes completely before MUSHclient processes more input. Thus it may have sent "do look,hop" to the MUD, but it hasn't got the reply back yet. And then you closed the log file before it did.
#2
Right on all accounts! Changing it as follows, all behaviors are as expected.
require "wait"
wait.make (function ()
    OpenLog (GetInfo (58) .. "test.txt", true)
    Note(IsLogOpen())
    SetLogOutput (true)
    Note(GetLogOutput ())
    SetLogInput (true)
    Note(GetLogInput ())
    Send ("do l,hop")
    WriteLog (os.date ("%d %b %y %I:%M %p"))
wait.time (1)
    CloseLog()
    Note "Log closed."
end)
Amended on Fri 25 Feb 2011 12:55 AM by Vincitore
USA #3
I'm having a problem with logging from a plugin, using OpenLog().

I have this trigger:

<triggers>
 <trigger
  enabled="y"
  match="^$"
  omit_from_log="y"
  omit_from_output="y"
  regexp="y"
  sequence="100"
 >
 </trigger>
</triggers>


This trigger's job is to gag blank lines after every prompt. If I use: FILE>LOG SESSION this trigger works, i.e. no blank lines show up in my log file.

However when I initiate a logging session via OpenLog(), I'm logging all of my blank lines.
Australia Forum Administrator #4
I don't see why that should happen. Once the log file is open, logging is done the same way, regardless of how you opened it.
#5
The solution to my path problem was to stop trying to use backslashes. Forward slashes work, as though the file path were an internet address. Odd, but easy enough to deal with once the issue is known.