Archive: Logging Installation Messages from NSIS


Logging Installation Messages from NSIS
How to log all the messages displayed while we install NSIS
any one help me if they have done that...
i want to log all the operations performed by the installer.


Uses NSISlog plug-in


thanks for your reply

can you tell how to use that plugin to enable logging from NSIS or some snippet of code so that it is helpful for me.

thanks in advance


I can provide some code, but not for that plugin as I ahve not used it. I use the Advanced Logging special build of NSIS. See Special Build link on nsis homepage.

This is my logging header file:


;These three macros are used with logging functions below
!macro _DebugInfoSuffix _cmd _text
!insertmacro _SectionSuffix '${_cmd}' '${_text} {on line $\"${__LINE__}$\" in file $\"${__FILE__}$\"'
!macroend
!macro _SectionSuffix _cmd _text
!ifdef __SECTION__
!insertmacro _FunctionSuffix '${_cmd}' '${_text} in section $\"${__SECTION__}$\"'
!else
!insertmacro _FunctionSuffix '${_cmd}' '${_text}'
!endif
!macroend
!macro _FunctionSuffix _cmd _text
!ifdef __FUNCTION__
'${_cmd}' '${_text} in function $\"${__FUNCTION__}$\"}'
!else
'${_cmd}' '${_text}}'
!endif
!macroend

;note that the LogText command requires the Advanced Logging special build of NSIS: http://nsis.sourceforge.net/Special_Builds
!define PrintInfo "!insertmacro _PrintInfo"
!macro _PrintInfo _text
!insertmacro _DebugInfoSuffix DetailPrint 'Info: ${_text}'
!macroend
!define LogInfo "!insertmacro _LogInfo"
;!define LogInfo "!insertmacro _DebugInfo"
!macro _LogInfo _text
!insertmacro _DebugInfoSuffix LogText 'Info: ${_text}'
!macroend

!define PrintWarning "!insertmacro _PrintWarning"
!macro _PrintWarning _text
!insertmacro _DebugInfoSuffix DetailPrint 'Warning: ${_text}'
!macroend
!define LogWarning "!insertmacro _LogWarning"
;!define LogWarning "!insertmacro _DebugWarning"
!macro _LogWarning _text
!insertmacro _DebugInfoSuffix LogText 'Warning: ${_text}'
!macroend
!define NotifyWarning "!insertmacro _NotifyWarning"
!macro _NotifyWarning _text
!insertmacro _DebugInfoSuffix DetailPrint 'Warning: ${_text}'
MessageBox MB_OK|MB_ICONEXCLAMATION 'Warning: ${_text}'
!macroend

!define PrintError "!insertmacro _PrintError"
!macro _PrintError _text
!insertmacro _DebugInfoSuffix DetailPrint 'Error: ${_text}'
!macroend
!define LogError "!insertmacro _LogError"
;!define LogError "!insertmacro _DebugError"
!macro _LogError _text
!insertmacro _DebugInfoSuffix LogText 'Error: ${_text}'
!macroend

!define LogVar "!insertmacro _LogVar"
!macro _LogVar _varName
!insertmacro _DebugInfoSuffix LogText 'Var: ${_varName} == $\"$${_varName}$\"'
!macroend
!define PrintVar "!insertmacro _PrintVar"
!macro _PrintVar _varName
!insertmacro _DebugInfoSuffix DetailPrint 'Var: ${_varName} == $\"$${_varName}$\"'
!macroend

Var /GLOBAL Utilities_LogLocation

;the Subdirectory parameter is the location relative to $INSTDIR that the log is placed.
;The log will be named install.log and will be in a datetime stamped subdirectory
;Note that if INSTDIR is later changed, the logging will continue to the original location.
;Also note that only the first call to this macro takes effect, subsequent calls will be unsuccessful because LogSet on statement only works once.
!define Utilities_InitializeLogging "!insertmacro _Utilities_InitializeLogging"
!macro _Utilities_InitializeLogging _Subdirectory
!ifndef _Utilities_InitializeLogging_UseOnce
!define _Utilities_InitializeLogging_UseOnce
!else
!error "InitializeLogging macro used more than once. Subsequent calls are ineffective."
!endif

Push '${_Subdirectory}'
Call _Utilities_InitializeLoggingFunc
!macroend
Function _Utilities_InitializeLoggingFunc
Exch $8 ;get subdirectory and backup 8
Push $0
Push $1
Push $2
Push $3
Push $4
Push $5
Push $6
Push $7

${GetTime} "" "L" $2 $1 $0 $6 $3 $4 $5 ;get time for YYYYMMDDHHmmss format
StrLen $7 $3 ;the hour comes out as a single digit sometimes
${If} $7 = 1
StrCpy $3 '0$3'
${EndIf}
StrCpy $1 '$0$1$2$3$4$5' ;YYYYMMDDHHmmSS
StrCpy $0 $INSTDIR ;backup value of $INSTDIR
StrCpy $INSTDIR '$INSTDIR\$8\$1'
CreateDirectory '$INSTDIR'
LogSet on ;this enables advanced logging, requires the Advanced Logging build of makensis: http://nsis.sourceforge.net/Special_Builds
StrCpy $Utilities_LogLocation '$INSTDIR\install.log'
StrCpy $INSTDIR $0 ;restore original value of INSTDIR
${PrintInfo} 'Logging started to $Utilities_LogLocation'
;TODO: add error handling?

Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
Pop $8
FunctionEnd

This is usage:

;initialize with a subdirectory relative to $INSTDIR
${Utilities_InitializeLogging} "MyInstallerLogs"
${PrintVar} INSTDIR ;logging a var
${PrintInfo} "Some message to screen and log"
${LogInfo} "Some message only to log"


Also note that if you've already initialized logging, then in the beginning of your first section, you should add the "LogSet on" statement, because for some reason when the directory is set by the directory page, the logging is turned off. Also note that I haven't found any way to change the log location after the first time it is initialized. The second LogSet on call simply turns logging on again to the original initialized location.

is there any simple mechanism to do that.......
i am not able to follow the code as i am very much new to NSIS

thanks in advance.


Put the nsislog.dll in your dir (if not already there) and use

nsislog::log "$INSTDIR\install.log" " my log message"


thanks for your reply i dont have that dll available with me can you attach it to this post so that i can test it

thanks in advance


The NSISLog plugin can be found here:
http://nsis.sourceforge.net/NSISLog_plug-in
Download the zipfile and extract nsislog.dll in the plugins subdirectory of the NSIS installation directory

You also might want to have a look at my Logging plugin:
http://nsis.sourceforge.net/LogEx_plug-in

Regards,
JP