Logfile and Logsize
Posted by KilledInAction
Tuesday, March 16, 2004
Description: Returns the logfile, (its properties,) or its size if network folders and daily logs are used.


;Returns the specific logfile for the channel you are looking for.
;Offset is the number of days.  Properties can include any $file properties
;Usage: $logfile([window],[offset])[.prop]
;ie. $logfile($active,-1) will return yesterdays log for your current screen
alias logfile {
  ;find todays logfile for the requested screen
  if ($isid) {
    if ($1) var %file = $window($1).logfile
    else var %file = $window($active).logfile
  }
  else {
    if ($left($1,1) == $chr(35)) { %file = $window($1).logfile | tokenize 32 %file $2 }
    else { var %file = $window($active).logfile | tokenize 32 %file $1 }
  }
  ;change the offset
  if ($2) {
    if ($2 !isnum) return
    ;a little magic
    var %time = $gettok(%file,$calc($numtok(%file,46) - 1),46)
    %time = $asctime($mid(%time,7,2) $+ / $+ $mid(%time,5,2) $+ / $+ $mid(%time,1,4) 00:00:00)
    %time = $asctime($calc($ctime(%time) + ($2 * 86400)),yyyymmdd)
    %file = $puttok(%file,%time,$calc($numtok(%file,46) - 1),46)
  }
  ;return with properties if specified
  if ($isid) {
    if ($prop) return $file(%file). [ $+ [ $prop ] ]
    return %file
  }
  run %file
}

;Usage: $logfilesize([window],[offset])
;Returns the size of the log file returned in $logfile in KB format w/suffix
alias logfilesize { return $bytes($logfile($iif($1,$1),$iif($2,$2)).size,k).suf }
Update
Posted by KilledInAction
Wednesday, March 24, 2004 03:20pm PST
Snippet updated to allow it to be used as a command.

Ie.
Run todays log file for active screen
/logfile

Run todays log file for another screen
/logfile #somechannel

Run yesterdays log file for active screen
/logfile -1

Rim yesterdays log file for another screen
/logfile #somechannel -1
Submit a comment
Oops! You need to login or register before you can post a comment!

ebaum's world