Old 13th October 2008, 16:17   #1
dbach
Member
 
Join Date: Apr 2006
Location: Somewhere in Germany
Posts: 81
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).

code:

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:
code:

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.
dbach is offline   Reply With Quote
Old 13th October 2008, 16:53   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
ifdef __SECTION__
and !ifdef __FUNCTION__?

xx and yy are line numbers inside the macros IIRC

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 14th October 2008, 08:32   #3
dbach
Member
 
Join Date: Apr 2006
Location: Somewhere in Germany
Posts: 81
Hi Anders,

thanks for your reply. We changed the script to this:
code:

!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:
code:

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 is offline   Reply With Quote
Old 15th October 2008, 06:22   #4
dbach
Member
 
Join Date: Apr 2006
Location: Somewhere in Germany
Posts: 81
Nobody can tel me what I am doing wrong? Is this a bug?
dbach is offline   Reply With Quote
Old 15th October 2008, 09:43   #5
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
I don't get the problem, it works fine
code:

!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?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 15th October 2008, 10:38   #6
dbach
Member
 
Join Date: Apr 2006
Location: Somewhere in Germany
Posts: 81
Quote:
Originally posted by Anders
I don't get the problem, it works fine
code:

[...]



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

code:

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 is offline   Reply With Quote
Old 15th October 2008, 10:57   #7
dbach
Member
 
Join Date: Apr 2006
Location: Somewhere in Germany
Posts: 81
Hi Anders,

we've found the problem.

The following example will NOT deliver a __SECTION__ value:

code:

Section -templog
...
SectionEnd


(shows nothing)

The following example will deliver a __SECTION__ value:

code:

Section "ThisIsTempLog" -templog
...
SectionEnd


(shows ThisIsTempLog")

Is it a feature, a bug or by design?
dbach is offline   Reply With Quote
Old 15th October 2008, 11:39   #8
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
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}

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 15th October 2008, 11:45   #9
dbach
Member
 
Join Date: Apr 2006
Location: Somewhere in Germany
Posts: 81
Quote:
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.
dbach is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump