JSON log files

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Joerg Hamacher
Posts: 120
Joined: Thu Feb 11, 2016 12:01 am

JSON log files

Post by Joerg Hamacher »

Hi,

I managed to generate the logfiles for my WEB API requests both on Windows and IBMi.

Is there a possibility to retrieve the name of the folder into which the request and response log files are posted by LANSA?
Either the complete path or at least the number that is used as name of the "deepest folder" (C:\Windows\Temp\lansaxlib_logs\HttpRequest\0000000001644852327657715)?

Customer wants me to retrieve the log files of the current request / response and send them via mail.

Best regards,

Joerg
BrendanB
Posts: 134
Joined: Tue Nov 24, 2015 10:29 am

Re: JSON log files

Post by BrendanB »

Joerg,

i use a method to create the 'logging directory', called in EACH job. This allows me to know where the logging is. the MoveXlibsLogFile method (not shown), merely moves the directory to somewhere to save it (it actually checks if there were no errors processing the httpRequest and deletes the directory if no errors...)

The idea is: by 'creating' the lansaxlibs.config.json file at *runtime*, i can control where the logs go, which means that i can know which logs belong to the job.

instead of #com_self.MoveXlibsLogFile, you could email the files in the directory (and then delete it).

the use of a GUID for the directory name ensures that each job can have its own directory. the 'SetLogging' routine is called *BEFORE* setting up the httpRequest, *AND AFTER* it is run (ie. the first and last things done). The second call has the effect of turning off log creation for httpRequests.

You may be able to adapt this to your situation.

BrendanB.

Code: Select all

Mthroutine Name(SetLogging) Access(*PRIVATE)
Define_Map For(*INPUT) Class(#PRIM_BOLN) Name(#LoggingSetOn) Mandatory(True)

Define_Com Class(#XPRIM_OSUtil) Name(#OSutil)

If (#LoggingSetOn.IsFalse)

#COM_SELF.MoveXlibsLogFile

Endif

#LogDir := #COM_SELF.CreateXlibsLogFile( #LoggingSetOn )
#OSutil.SetEnvironmentVariable Name('LANSA_XLIB_CONFIG') Value((#LogDir + '/lansaxlibs.config.json'))

Endroutine

Mthroutine Name(CreateXlibsLogFile) Access(*PRIVATE)
Define_Map For(*INPUT) Class(#PRIM_BOLN) Name(#LogValues) Mandatory(True)
Define_Map For(*RESULT) Class(#PRIM_ALPH) Name(#Result)

Define_Com Class(#PRIM_IOC.FileStream) Name(#FileStream)
Define_Com Class(#PRIM_IOC.StreamWriter) Name(#StreamWriter) Stream(#FileStream)
Define_Com Class(#PRIM_JSON.Writer) Name(#JsonWriter) TextWriter(#StreamWriter)

Define_Com Class(#XPRIM_Directory) Name(#Dir)
Define_Com Class(#XPRIM_File) Name(#OutFile)

Define_Com Class(#PRIM_ALPH) Name(#TmpDirOut)
Define_Com Class(#PRIM_ALPH) Name(#Guid)

#Guid := *GUID

#Dir.SetPath Directory(*ROOT_DIR)
#Dir.AppendPath Path('tmp')

If (#LogValues)

#Dir.AppendPath Path(#Guid)

Endif

#OutFile.SetPath Directory(#Dir) FilePath('lansaxlibs.config.json')
#OutFile.EnsureFileDirectoryExists

If (#OutFile.Exists)

#OutFile.Delete

Endif

#FileStream.Path := #OutFile.Path
#FileStream.FileMode := Create
#FileStream.FileAccess := Write

#TmpDirOut := #Dir.Path
#TmpDirOut := #TmpDirOut.ReplaceAll( (92).AsUnicodeString '/' )

#JsonWriter.BeginObject
#JsonWriter.BeginObject MemberName("Common")
#JsonWriter.WriteString MemberName("logOutputDir") Value(#TmpDirOut)
#JsonWriter.EndObject
#JsonWriter.BeginObject MemberName("HttpRequest")
#JsonWriter.BeginObject MemberName("logging")
#JsonWriter.WriteBoolean MemberName("requestHeaders") Value(#LogValues)
#JsonWriter.WriteBoolean MemberName("requestBody") Value(#LogValues)
#JsonWriter.WriteBoolean MemberName("responseHeaders") Value(#LogValues)
#JsonWriter.WriteBoolean MemberName("responseBody") Value(#LogValues)
#JsonWriter.EndObject
#JsonWriter.EndObject
#JsonWriter.EndObject

#JsonWriter.Close

#Result := #TmpDirOut

Endroutine

Joerg Hamacher
Posts: 120
Joined: Thu Feb 11, 2016 12:01 am

Re: JSON log files

Post by Joerg Hamacher »

Thank you, Brendan,

this works fine!

Best regards and have a nice weekend,
Joerg
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: JSON log files

Post by Dino »

Hi Brendan

Your example is a great way to use it the OSU trace.

But I noticed you used caps to indicate "EACH" job...

If I have a loop that start httprequest transactions each X minutes and sleepthread for a while, like this:

Code: Select all

Begin_Loop
#COM_OWNER.PerformHTTPRequest
#OSutil.threadSleep Milliseconds(300000)
End_Loop

and PerformHTTPRequest:

Code: Select all

#JSONRP001.SetLogging Loggingseton(True) Logdir(#dirToCreateTrace) Foldertocreatetrace('/tmp/testing')   /* your routines */
#OSUtil.SetEnvironmentVariable Name('LANSA_XLIB_CONFIG') Value(#dirToCreateTrace + '/lansaxlibs.config.json')
* Prepare json #Writer... #HttpRequest.DoPost Url(#Url) etc.
#OSUtil.SetEnvironmentVariable Name('LANSA_XLIB_CONFIG') Value(*NULL)
is there any way to stop the xprim_osutil from using the first folder created as the only one to create traces?

As you can see I am trying to reset the trace with:

Code: Select all

#OSUtil.SetEnvironmentVariable Name('LANSA_XLIB_CONFIG') Value(*NULL)
but I dont see any reaction to it. Just the first folder created have the HttpRequest folder with multiple traces inside.
The others only have the lansaxlibs.config.json

If there is no way, I guess I just have to make each execution a separated job and have a main jbo submit a child job every x minutes.

My goal is to have a trace for each httprequest

Thank you
Post Reply