MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: Indirect Access to Environment Variables (by reference)[Next]: Logging Whole Batch File Execution
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->Batch Files->Batch File Tips and Tricks->Logging RollOver (keep "x" logs)

Logging RollOver (keep "x" logs)

This is an example of how you can maintain a history of the past 'x' logs:

@rem --- Prepare for logging (max 1+15=16 logs) ---
@echo off
set LogDir=C:\tmp\Log
md "%LogDir%" >nul 2>&1
set      LogFile=%LogDir%\SomeLog.TXT
set  LogFileMask=%LogDir%\SomeLog?.TXT

@REM --- Actually do the rollover ---
call :RollOverLogs "%LogFileMask%" 15

@rem --- Now do "stuff" and log ---
echo [%date% %time%] Now doing stuff > "%LogFile%" 2>&1
goto :EOF



@rem ======================[ Version 07.100] ==================================
:RollOverLogs
@rem === Parm 1: What backup logs look like, example "c:\tmp\SomeFile?.Log" (? replaced by number)
@rem === Parm 2: Number of logs
@rem ==========================================================================
    SetLocal ENABLEDELAYEDEXPANSION
      set      LogMask=%~1
      set  LogNumbBackups=%~2
      for /L %%b in (%LogNumbBackups%, -1, 1) do (
          @rem *** Work out log numbers and names **********************
          set    This=%%b
          set /a Prev=!This! - 1
          if    "!Prev!" == "0" set Prev=
          call :LogName "FileThis", "%LogMask%", "!This!"
          call :LogName "FilePrev", "%LogMask%", "!Prev!"
          for %%f in ("!FileThis!") do set FileThisSN=%%~nf%%~xf

          @rem *** Move "previous" log to this level *******************
          if exist "!FileThis!" del "!FileThis!" >nul 2>&1
          if exist "!FilePrev!" ren "!FilePrev!" "!FileThisSN!" >nul 2>&1
      )
    EndLocal
    goto :EOF


@rem ==========================================================================
:LogName
@rem Helper routine only to be used by ":RollOverLogs"
@rem ==========================================================================
    set LogMask2=%~2
    set   NewVal=%~3
    set %~1=!LogMask2:?=%NewVal%!
    goto :EOF


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Indirect Access to Environment Variables (by reference)[Next]: Logging Whole Batch File Execution


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Saturday May 28 2022 at 3:11pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.