DataLink Studio - DataLink Studio Support Forum

Support
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 07, 2010, 06:46:36 am

HomeHome     GuideGuide     SearchSearch     LoginLogin     RegisterRegister
+  Support Forum and Knowledgebase
|-+  Knowledgebase
| |-+  Knowledgebase
| | |-+  Useful Scripts
| | | |-+  Logging diagnostic information to a log file
« previous next »
Pages: 1 Go Down Print
Author Topic: Logging diagnostic information to a log file  (Read 166 times)
« Posted: March 23, 2010, 11:10:58 pm »
richardh
Administrator
Newbie
*****
Posts: 32
Infor

View Profile
Debugging vbscript in datalinks can be hard. I've implemented a logging function that lets you log into a file. This function is turned on by either setting a User Option ( Vision Setup - Profile - Products - Options ) or by logging in with Logging enabled ( on the Options tab of the login Window ). Each output to the log has a timestamp. Put this code at the start of your main Control Tag script. It will create a Control Tag showing if logging is enabled which is then used to switch out the logging instructions if they aren't used - so there is no performance overhead in having logging code in your datalink. The logfile is located in your Temp folder and is called Captains_Log_ with a timestamp on the end

An example of logging some diagnostic information -

     {TagLogging=1}
       Log_Message "C_Name " + CStr(C_Name) + "    C_Server " + CStr(C_Server) + "    C_Database " + CStr(C_Database)
     {TagLoggingEnd}


/*   CODE STARTS HERE   */


select 'UserOption03',0,'Logging Enable - if set ignores Vision Logging - Captains_Log in %temp%'
{OracleStart}From Dual{OracleEnd}
GO


/*VBSCRIPT=10000 GLOBAL*/
dim WshShell
dim tempdir
dim objFSO
dim objLogFile
dim LogFileName
Dim objLog
Dim LsEngine_info
Dim Logging_Enabled

' Extract the location of the System temporary folder ( same place Vision puts its logfiles

Set WshShell = CreateObject("WScript.Shell")
tempdir = WshShell.ExpandEnvironmentStrings("%temp%")
LogFileName = "Captains_Log_" + cstr(year(now)) + right( "00" + cstr(month(now)),2) + right( "00" + cstr(day(now)),2)+ right( "00" + cstr(hour(now)),2)+ right( "00" + cstr(minute(now)),2)

Set objFSO = CreateObject("Scripting.FileSystemObject")

{TagUserOption03=1}
   If 1 = 1 then
{TagUserOption03Else}
If objFSO.FileExists(tempdir+"\LsEngine.log") OR  {TagUserOption03} = 1 Then
   Set objLog = objFSO.GetFile(tempdir+"\LsEngine.log")
   LsEngine_info = objLog.DateLastModified
   If Mid(LogFileName,14,4) = Mid(LsEngine_info,7,4) AND Mid(LogFileName,18,2) = Mid(LsEngine_info,4,2) AND Mid(LogFileName,20,2) = Mid(LsEngine_info,1,2) Then
{TagUserOption03End}

      Log_Message "############################################# Logging Started  #############################"
      Log_Message "###" + cstr(LogFileName) +"###"

      Log_Message "{FilterKey1ProductAuthorProductRegistration} "
      Log_Message "{FilterKey1ProductCode} "
      Log_Message "{FilterKey1ProductDescription}"
      Log_Message "{FilterKey1ProductVersion}"
      Log_Message "{FilterKey1ProductDemoMode}"
      Log_Message "UserOption01 = {TagUSerOption01}"
      Log_Message "UserOption02 = {TagUSerOption02}"
      Log_Message "UserOption03 = {TagUSerOption03}"
      Logging_Enabled = 1
      oAlchemyControlTags.ADD "Logging","1"
   Else
      Logging_Enabled = 0
      oAlchemyControlTags.ADD "Logging","0"
End If
{TagUserOption03=0}
Else
   Logging_Enabled = 0
   oAlchemyControlTags.ADD "Logging","0"
End If
{TagUserOption03End}

Sub Log_Message ( Text_Message )
Set objLogFile = objFSO.OpenTextFile(cstr(tempdir) +"\" + cstr(LogFileName) +".log", 8, True)
objLogFile.Writeline Date & " " & Time & "  " & Text_Message


objLogFile.Close


end sub

GO
Logged
« Reply #1 Posted: May 14, 2010, 07:15:23 pm »
richardh
Administrator
Newbie
*****
Posts: 32
Infor

View Profile
I should add that this code should be taken out for Released software where you intend to use the DataLink with EIF Services.
EIF Services converts the VB in Control Tag Scripts to .NET before running them and the Objects used to write to the file aren't available in .NET so the DataLink will break.
Logged
Pages: 1 Go Up Print 
« previous next »
Jump to:  

Powered by SMF 1.1 RC2 | SMF © 2001-2005, Lewis Media

spacer.png, 0 kB
Infor Logo
Live Help
spacer.png, 0 kB