mIRC Homepage
Okay, mIRC's logging system ends up creating a few files for each week, like "[name].log, [name].1.log, etc...". I've already written the script to sort the logfiles in a window based on the date at the top (and filename).

I'm trying to write a script that will combine all the logs for a given week and delete the extra temporary logs ([name].2.log), just to tidy up (and for the sake of my original logfiles alias). However, it's... um... not working. When it does loop, it starts to pick up the right groups of files but then just stops. The part I tacked on to the alias below is pretty messy, but maybe you can see where I went wrong. I was just trying to patch it up any whichway.
Code:
alias logfiles {
  if ($window(@Logfile).font) { window -c @Logfile | return }
  if ($window(@Logfiles).font) { window -c @Logfiles | return }

  /window -c @Logfiles | window -c @Logfile

  if ($1 == combine) /window -h @Logfiles
  else /window -lex @Logfiles 

  /var %loop = 1, %file
  while (1) {
    %file = $findfile($qt($logdir),*.log,%loop)
    if (!%file) break
    aline @Logfiles %file
    inc %loop
  }
  /filter -awwc @Logfiles @Logfiles logsort


  if ($1 != combine) halt

  /window @test
  %loop = 1
  /var %last_files, %loop2 = 1
  while (1) {
    %loop2 = 1
    %file = $line(@Logfiles,%loop)
    aline @test === lastfile: %last_files /// file : %file
    if (!%file) break

    ;$gettok($line(@Logfiles, $gettok(%last_files,1,183)),1-3,46)

    if (($gettok(%file,1-3,46) != $gettok($line(@Logfiles, $gettok(%last_files,1,183)),1-3,46)) && ($numtok(%last_files,183) > 1)) {
      /window -h @combo_wid
      while (%loop2 <= $numtok(%last_files,183)) {
        /var %temp = $qt($line(@Logfiles,$gettok(%last_files,%loop2,183)))
        /filter -fw %temp @combo_wid
        inc %loop2
      }
      /write -c $+($gettok($line(@Logfiles, $gettok(%last_files,1,183)),1-3,46),.log) $chr(32)
      /filter -wf @combo_wid $+($gettok($line(@Logfiles, $gettok(%last_files,1,183)),1-3,46),.log)
      /window -c @combo_wid
      aline @test ===Did something!
      unset %last_files
      goto next
    }
    if ($gettok(%file,1-3,46) != $gettok($line(@Logfiles, $gettok(%last_files,1,183)),1-3,46)) unset %last_files
    %last_files = %last_files $+ %loop $+ $chr(183)
    :next
    inc %loop
  }
  unset %last_files
  /echo -gst DONE!
}
alias logsort {
  if ($gettok($1,1,46) != $gettok($2,1,46)) return $iif($gettok($1,1,46) < $gettok($2,1,46),-1,1)
  if ($ctime($gettok($read($qt($1),2),3-,32)) != $ctime($gettok($read($qt($2),2),3-,32))) return $iif($ctime($gettok($read($qt($1),2),3-,32)) < $ctime($gettok($read($qt($2),2),3-,32)),-1,1)
  ;if ($file($qt($1)).mtime != $file($qt($2)).mtime) return $iif($file($qt($1)).mtime > $file($qt($2)).mtime,1,-1)
  return 0
}
menu @Logfiles {
  dclick:{
    window -ex @Logfile
    filter -cfw $qt($sline(@Logfiles,1)) @Logfile *
    window -c @Logfiles
  }
}
Bah. Made it work, I think, but somewhat pointless right now: The logs are sorted by the starting session time of the first session in each log. But the [name].N.log files can contain sessions before and after the starting session of [name].log, so I'd have to add a bunch more stuff if I want things in order... orz

Code:
alias logfiles {
  if ($window(@Logfile).font) { window -c @Logfile | return }
  if ($window(@Logfiles).font) { window -c @Logfiles | return }

  /window -c @Logfiles | window -c @Logfile

  if ($1 == combine) /window -h @Logfiles
  else /window -lex @Logfiles 

  /var %loop = 1, %file
  while (1) {
    %file = $findfile($qt($logdir),*.log,%loop)
    if (!%file) break
    aline @Logfiles %file
    inc %loop
  }
  /filter -awwc @Logfiles @Logfiles logsort

  if (!$1) halt

  /window @temp
  /window -h @log_buffer
  /var %loop = 0, %last_line, %current_line, %trip = 0
  while (%loop < $line(@Logfiles,0)) {
    inc %loop
    %current_line = $line(@Logfiles,%loop)

    /aline @temp $chr(160)
    /aline @temp >> last = %last_line ///// current = %current_line

    inc %trip
    if ($gettok(%current_line,1-3,46) != $gettok(%last_line,1-3,46)) {
      if (%trip > 1) {
        /aline @temp --Clear the original log: /write -c $qt($+($gettok(%last_line,1-3,46),.log)) $cr
        /write -c $qt($+($gettok(%last_line,1-3,46),.log)) $cr
        /aline @temp --Dump the contents: /filter -wf @log_buffer $qt($+($gettok(%last_line,1-3,46),.log)) *
        /filter -wf @log_buffer $qt($+($gettok(%last_line,1-3,46),.log)) *
      }
      /aline @temp --Clear the buffer window and reset %trip!
      /window -c @log_buffer
      /window -h @log_buffer
      %trip = 0
    }
    /aline @temp ~~ Append the contents of $qt(%current_line) to the @temp window: /filter -fw $qt(%current_line) @log_buffer *
    /filter -fw $qt(%current_line) @log_buffer *

    %last_line = %current_line
  }
  %loop = 0
  while (%loop < $line(@Logfiles,0)) {
    inc %loop
    if ($regex($line(@Logfiles,%loop),.*\.[1-9]\.log$)) { /remove -b $qt($line(@Logfiles,%loop)) | aline @temp ====Delete: /remove -b $qt($line(@Logfiles,%loop)) }
  }
}
alias logsort {
  if ($gettok($1,1,46) != $gettok($2,1,46)) return $iif($gettok($1,1,46) < $gettok($2,1,46),-1,1)
  if ($ctime($gettok($read($qt($1),2),3-,32)) != $ctime($gettok($read($qt($2),2),3-,32))) return $iif($ctime($gettok($read($qt($1),2),3-,32)) < $ctime($gettok($read($qt($2),2),3-,32)),-1,1)
  ;if ($file($qt($1)).mtime != $file($qt($2)).mtime) return $iif($file($qt($1)).mtime > $file($qt($2)).mtime,1,-1)
  return 0
}
menu @Logfiles {
  dclick:{
    window -ex @Logfile
    filter -cfw $qt($sline(@Logfiles,1)) @Logfile *
    window -c @Logfiles
  }
}
Just for posterity's sake, I will continue to record my efforts. I don't know why mIRC makes these extra, out-of-order files, but my solution is the same for my efforts with the default text: Throw in a bunch of remote scripts and write my own. ^^ The main script (EXIT event) is below. This way of logging has the additional benefit of not showing the timestamp twice for events in which I've halted default text to display the text my own way.

Of course, I'm going to have to halt default text for the ACTION event to keep the color, though that won't add color to my own ACTIONs... =/

A bigger problem, though, is that the buffer can only be so long, so I'll often end up missing the beginning where it gets cut off...

As explanation: The text I don't want to log starts out with a color-15 background or doesn't start with a timestamp.
Code:
ON *:EXIT:{
  /window -c @temp
  /var %loopServ = 1, %loopChan = 1
  while (%loopServ <= $scid(0)) {
    /scid %loopServ
    while (%loopChan <= $chan(0)) {
      if ($istok(#chan1 #chan3 #chan9,$chan(%loopChan),32)) {
        /window -h @temp
        /var %file = $+($network,.,$chan(%loopChan),.,$asctime($calc($ctime - $uptime(mirc,3)),yyyy-mm-dd),.log)

        /write %file ====Session Start: $asctime($calc($ctime - $uptime(mirc,3)),ddd mmm hh:nn:ss yyyy)
        /filter -wwxg $chan(%loopChan) @temp ^[0-15],15*
        /filter -bwfg @temp %file ^\[
        /write %file ====Session End: $asctime($ctime,ddd mmm hh:nn:ss yyyy)

        /window -c @temp
      }
      inc %loopChan
    }
    %loopChan = 1
    inc %loopServ
  }
}

Thoughts?
© mIRC Discussion Forums