Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi-session LogFile
#1
I wish I knew enough to edit "LogFile" (a 2.1.4beta extension function) to make a version that writes multi-session log files. In other words, I don't want the modified version to rename existing log file when first used in a session. FYI, here is the unmodified LogFile code:
Code:
Copy      Help
/
function ~s [logdatetime] ;;Writes/appends s to file "qm log.txt"

Appends string s to "qm log.txt" file in QM folder.
To use other log file, store path into global
str variable _logfile. First time in session,
existing log file is renamed to "qm log prev.txt".

File-- f
if(!f.m_file)
    str path.expandpath(_logfile)
    
    if(getenv("qmlog")) f.Open(path "a")
    else
        if(dir(path))
            str ppath.from(_qmdir "qm log prev.txt")
            ren- path ppath 0x2C0|FOF_NOERRORUI|FOF_SILENT~FOF_ALLOWUNDO; err
        f.Open(path "w")
        _putenv("qmlog=1")

if(logdatetime) s-_s.time("%c[]")
f.WriteLine(s)

err+ end ES_FAILED
Especially nice would be if the modified function had a third argument [maxlength] so it could remove top lines from log files longer than maxlength.
#2
Execute this before first call to LogFile (you can for example place it in init2 function):

_putenv("qmlog=1")

This makes LogFile think that it is being used not first time in session.
#3
Well that sure did it Big Grin I checked to see if the "qmlog" environmental variable is used by any other programs. It is not, so that is a good thing too. Many thanks! -John


Forum Jump:


Users browsing this thread: 1 Guest(s)