project BLF > class tLogger > method LogBusinessCode
Description
Log a certain entry in the log file.
Parameters
icLogEntry | input | character | Character strig that needs to be written to the log file |
icLogParameters | input | character | |
Internal usage
unused
program code (program1/tlogger.p)
if vcLogBusinessCodeFile = ""
and vlStatelessMode = no
then return.
/* ================================================================= */
/* Analyze call stack to know what business method is run. */
/* program-name(1)+(2) = TLogger itself. */
/* ================================================================= */
viMethod = 3.
do while true:
vcMethod = program-name(viMethod).
if num-entries(vcMethod," ") = 2
and ((entry(2,vcMethod," ") begins "program" and
not entry(2,vcMethod," ") begins "program/"))
then viMethod = viMethod + 1.
else leave.
end. /* do while true: */
viMethod = viMethod + 1.
do while true:
if program-name(viMethod) = ?
then leave.
vcParent = program-name(viMethod).
if vcParent begins "query/api"
then viMethod = viMethod + 1.
else if num-entries(vcParent," ") = 2
and ((entry(2,vcParent," ") begins "program" and
not entry(2,vcParent," ") begins "program/") or
entry(2,vcParent," ") begins "custprogram")
then viMethod = viMethod + 1.
else leave.
end. /* do while true: */
/* In case icLogEntry is about a sub-action of a method that is not really a sub-method then we alter the method and the parent */
if (icLogEntry begins "START-SUB":U or
icLogEntry begins "END-SUB":U) and
num-entries(icLogEntry,",":U) > 1 and
trim(entry(2,icLogEntry,",":U)) <> "":U and
trim(entry(2,icLogEntry,",":U)) <> ?
then assign vcParent = vcMethod
vcMethod = vcMethod + "-":U + trim(entry(2,icLogEntry,",":U)).
assign vcMethodProgram = (if num-entries(vcMethod," ") < 2
then vcMethod
else entry(2,vcMethod," "))
vcParentProgram = (if num-entries(vcParent," ") < 2
then vcParent
else entry(2,vcParent," ")).
/* ignore internal procedure of referential integrity programs */
if vcMethodProgram begins "ref_int/"
then vcMethod = vcMethodProgram.
if vcParentProgram begins "ref_int/"
then vcParent = vcParentProgram.
/* if parent is not recognised as CB business logic, it is considered external */
vlExternal = not (vcParentProgram begins "api/" or
vcParentProgram begins "appinfo/" or
vcParentProgram begins "ins/" or
vcParentProgram begins "program/" or
vcParentProgram begins "query/" or
vcParentProgram begins "ref_int/").
if not vlStatelessMode
then output stream sLug to value(vcLogBusinessCodeFile) append.
/* Logging a Start action */
if icLogEntry = "START" or
icLogEntry begins "START-SUB":U
then do:
/* If parent is not known in the stack, replace it by last known in the stack */
if not can-find (first tStack where tStack.tcMethod = vcParent)
then for each tStack by tStack.tiSequence descending:
vcParent = tStack.tcMethod.
leave.
end. /* then for each tStack by tStack.tiSequence descending: */
assign viSequence = viSequence + 1.
create tStack.
assign tStack.TCMETHOD = VCMETHOD
tStack.TCPARENT = VCPARENT
tStack.TGTIME = etime
tStack.tiSequence = viSequence.
release tStack.
end. /* if icLogEntry = "START" or */
/* Closing a left-over of function calls */
if icLogEntry = "END" or
icLogEntry begins "END-SUB":U
then for each bStack where
bStack.tCMETHOD = vCMETHOD
by bStack.tiSequence descending:
assign viDuration = etime - bStack.TGTIME
vcParent = bStack.tcParent
viSequence = bStack.tiSequence - 1.
for each tStack where
tStack.tiSequence > bStack.tiSequence
by tStack.tiSequence descending:
if ((viLoggerDebugLevel mod 2) > 0 and vlExternal) or
(viLoggerDebugLevel mod 4) > 1
then if vlStatelessMode
then do transaction on error undo, leave:
viLogBusinessCodeDataCount = viLogBusinessCodeDataCount + 1.
create tLogBusinessCodeData.
assign tLogBusinessCodeData.tiCount = viLogBusinessCodeDataCount
tLogBusinessCodeData.tcMethod = "<BusCode>" + chr(10)
+ "time=" + string(now) + chr(10)
+ "method=" + tStack.tcMethod + chr(10)
+ "parent=" + tStack.tcParent + chr(10)
+ "duration=0" + chr(10)
+ "END" + chr(10)
+ "</BusCode>" + chr(10).
release tLogBusinessCodeData.
end. /* if vlStatelessMode */
else put stream sLug unformatted
"<BusCode>" skip
"time=" now skip
"method=" tStack.tcMethod skip
"parent=" tStack.tcParent skip
"duration=0" skip
"END" skip
"</BusCode>" skip(1).
delete tStack.
end. /* for each tStack where */
delete bStack.
leave.
end. /* if icLogEntry = "END" or */
if ((viLoggerDebugLevel mod 2) > 0 and vlExternal) or
(viLoggerDebugLevel mod 4) > 1
then if vlStatelessMode
then do transaction on error undo, leave:
viLogBusinessCodeDataCount = viLogBusinessCodeDataCount + 1.
create tLogBusinessCodeData.
assign tLogBusinessCodeData.tiCount = viLogBusinessCodeDataCount
tLogBusinessCodeData.tcMethod = "<BusCode>" + chr(10)
+ "time=" + string(now) + chr(10)
+ "method=" + vcMethod + chr(10)
+ "parent=" + vcParent + chr(10).
if icLogEntry = "END" or
icLogEntry begins "END-SUB"
then tLogBusinessCodeData.tcMethod = tLogBusinessCodeData.tcMethod
+ "duration="
+ (if viDuration = ? then "0" else string(viDuration)) + chr(10).
assign tLogBusinessCodeData.tcMethod = tLogBusinessCodeData.tcMethod + (if icLogEntry begins "END-SUB":U
then "END":U
else if icLogEntry begins "START-SUB":U
then "START":U
else icLogEntry) + chr(10).
if (viLoggerDebugLevel mod 8) > 3
then tLogBusinessCodeData.tcMethod = tLogBusinessCodeData.tcMethod + icLogParameters + chr(10).
assign tLogBusinessCodeData.tcMethod = tLogBusinessCodeData.tcMethod + "</BusCode>" + chr(10).
release tLogBusinessCodeData.
end. /* if vlStatelessMode */
else do:
put stream sLug unformatted
"<BusCode>" skip
"time=" now skip
"method=" vcMethod skip
"parent=" vcParent skip.
if icLogEntry = "END" or
icLogEntry begins "END-SUB"
then put stream sLug unformatted "duration=" (if viDuration = ? then "0" else string(viDuration)) skip.
put stream sLug unformatted
(if icLogEntry begins "END-SUB":U
then "END":U
else if icLogEntry begins "START-SUB":U
then "START":U
else icLogEntry) skip.
if (viLoggerDebugLevel mod 8) > 3
then put stream sLug unformatted icLogParameters skip.
put stream sLug unformatted
"</BusCode>" skip(1).
end. /* Not if vlStatelessMode */
if not vlStatelessMode
then output stream sLug close.