Logging:Enable Logs Quickly
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