- NSIS Discussion
- LogModule: ${__SECTION__} ${__FUNCTION__} Problems
Archive: LogModule: ${__SECTION__} ${__FUNCTION__} Problems
dbach
13th October 2008 17:17 UTC
LogModule: ${__SECTION__} ${__FUNCTION__} Problems
Hi NSIS Developer Community,
we are currently programming modules for our installers. One of it is the Log_Module. We want to Add a detailed Info to the Logfile, but we don't know if the logfunction is called from a Section or a function. This is what we got (not working).
Call LogSetOn
${If} ${__SECTION__} != ""
FileWrite $Log_File "${TYPE}: ${__TIME__} ${__SECTION__} - ${MSG} (${__FILE__}, line ${__LINE__}) $\r$\n"
${EndIf}
${If} ${__FUNCTION__} != ""
FileWrite $Log_File "${TYPE}: ${__TIME__} ${__FUNCTION__} - ${MSG} (${__FILE__}, line ${__LINE__}) $\r$\n"
${EndIf}
And it results in:
INFO: 17:54:55 ${__SECTION__} - This is an Info (dummyServer.nsi, line 33.1.8)
INFO: 17:54:55 .onInit - This is an Info (dummyServer.nsi, line 33.1.12)
Is there a way to find out if the function was called from a section or function?
I also wonder about the linenumber output (33.xx.yy). What are the xx and yy for?
Thanks for any reply.
Anders
13th October 2008 17:53 UTC
ifdef __SECTION__
and !ifdef __FUNCTION__?
xx and yy are line numbers inside the macros IIRC
dbach
14th October 2008 09:32 UTC
Hi Anders,
thanks for your reply. We changed the script to this:
!ifdef __SECTION__
FileWrite $Log_File "${TYPE}: ${__TIME__} ${__SECTION__} - ${MSG} (${__FILE__}, line ${__LINE__}) $\r$\n"
!endif
!ifdef __FUNCTION__
FileWrite $Log_File "${TYPE}: ${__TIME__} ${__FUNCTION__} - ${MSG} (${__FILE__}, line ${__LINE__}) $\r$\n"
!endif
But the "section" is never show. This is the result:
INFO: 09:12:44 .onInit - This is an Info (myscript.nsi, line 50.1.13)
WARNING: 09:12:44 .onInit - This is an Warning (myscript.nsi, line 51.1.13)
WARNING: 09:12:44 - I am in TempLog (myscript.nsi, line 65.1.9)
The section is never shown. Is this a bug?
Thanks.
dbach
15th October 2008 07:22 UTC
Nobody can tel me what I am doing wrong? Is this a bug?
Anders
15th October 2008 10:43 UTC
I don't get the problem, it works fine
!macro stupidmacro
!ifdef __SECTION__
MessageBox mb_ok "sec=${__SECTION__}"
!endif
!ifdef __FUNCTION__
MessageBox mb_ok func=${__FUNCTION__}
!endif
!macroend
Function func1
!insertmacro stupidmacro
FunctionEnd
Section "sec1"
!insertmacro stupidmacro
call func1
SectionEnd
or did you want __SECTION__ to be defined even when its not in a section, but in a function?
dbach
15th October 2008 11:38 UTC
Originally posted by Anders
I don't get the problem, it works fine
[...]
or did you want __SECTION__ to be defined even when its not in a section, but in a function?
Hi Anders,
thanks for your reply again.
In your case its correct and working nice. But we are programming modules and we use it like this
Section
${Log_Info} "Have done this and that"
SectioEnd
Function yadayada
${Log_Info} "have delete a file (e.g.)"
FunctionEnd
So the ${Log_Info} has to do the check if it was called from a Function OR Section. We do not want to use a special macro for section AND function, instead only one macro (our ${Log_Info}).
I thought, If I call it from a Function then __Function__ will be set and __section__ not. And if I call it from a Section then __section__ is set and __Function__ not.
The result is that "section" is not shown if Section is defined.
Maybe there is something wrong in my script then, I am using 2.38 - will reply later on more detailed test (currently very busy at work). thanks
dbach
15th October 2008 11:57 UTC
Hi Anders,
we've found the problem.
The following example will NOT deliver a __SECTION__ value:
Section -templog
...
SectionEnd
(shows nothing)
The following example
will deliver a __SECTION__ value:
Section "ThisIsTempLog" -templog
...
SectionEnd
(shows ThisIsTempLog")
Is it a feature, a bug or by design?
Anders
15th October 2008 12:39 UTC
Section -foo means a hidden section, so it has no name, Section foo -bar means a section with the name foo and its section index is ${-bar}
dbach
15th October 2008 12:45 UTC
Originally posted by Anders
Section -foo means a hidden section, so it has no name, Section foo -bar means a section with the name foo and its section index is ${-bar}
Thanks for making this clear.