Logging:Enable Logs Quickly: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Created page)
 
 
Line 59: Line 59:
!macro LogTextMacro INPUT_TEXT
!macro LogTextMacro INPUT_TEXT
   !ifdef ENABLE_LOGGING
   !ifdef ENABLE_LOGGING
     LogText $INPUT_TEXT
     LogText ${INPUT_TEXT}
   !endif
   !endif
!macroend
!macroend

Latest revision as of 10:24, 26 October 2016

Author: SHayashi (talk, contrib)


Description

LogOn and LogText are very useful debugging tools for your installer. Unfortunately, if you have a bunch of LogText lines spread throughout your code, it makes it very difficult to remove. This set of macros allows you to turn logging on and off with a single statement.

Note: It's assumed you know about the NSIS Special Builds, which enable the LogOn and LogText commands. The standard NSIS build will throw errors if you attempt to use LogOn or LogText directly. These macros will fix this.

Original Logging example

# name the installer
OutFile "Installer.exe"
 
# default section start; every NSIS script has at least one section.
section
LogText "Some Logging Text Here"
 
# default section end
sectionEnd
 
Function .onInit
  SetOutPath $INSTDIR
  LogSet on
FunctionEnd

Using these macros

If you need to enable logging, just define ENABLE_LOGGING. If you're using the standard non-logging NSIS build, just comment out ENABLE_LOGGING.

!define ENABLE_LOGGING
 
!include "logging.nsh"
 
# name the installer
OutFile "Installer.exe"
 
# default section start; every NSIS script has at least one section.
section
${LogText} "Some Text Here"
 
# default section end
sectionEnd
 
Function .onInit
  SetOutPath $INSTDIR
  ${LogSet} on
FunctionEnd


This is the macro file logging.nsh:

!define LogSet "!insertmacro LogSetMacro"
!macro LogSetMacro SETTING
  !ifdef ENABLE_LOGGING
    LogSet ${SETTING}
  !endif
!macroend
 
!define LogText "!insertmacro LogTextMacro"
!macro LogTextMacro INPUT_TEXT
  !ifdef ENABLE_LOGGING
    LogText ${INPUT_TEXT}
  !endif
!macroend

Written by user:SHayashi

Inspired by Logging:_Simple_Text_File_Logging_Functions_and_Macros