Home > Blockchain >  What is the most efficient way to generate a log file in XPROC?
What is the most efficient way to generate a log file in XPROC?

Time:07-24

I created an XPROC 3.0 pipeline that performs several tasks to reorganize files using element such as p:for-each, p:choose, file steps and validation steps. I would like to log the main events such as error, the files processed, etc.

The first solution I tried is :

  • the creation of an empty log file
  • each time I need to log an information, I use a <p:insert position="last-child">
  • then I store the updated log file But I think this solution is not optimal because :
  • the multiple accesses to the log file probably slow down the process
  • sometimes, a fail occurs with an invalid log file, maybe because two steps access the log file at the same time.

Then I tried to concatenate the different messages at the different levels with

  • <p:wrap-sequence/>
  • <p:unwrap> to remove the unwanted wrapper
  • <p:pack> (but this step can concatenate only two sources at a time)

But I find this second way not very elegant.

Can you advise me on the best practice to construct a log file ?

Thank you !

CodePudding user response:

In XProc 1.0 there was no explicit support for logging, which is a weakness of that version of the language. You can open and close a log file yourself, and rewrite it, as you describe in your question, but as you point out, there are issues with that approach. Many if not all XProc 1.0 processors support some kind of message extension step which will write a line of text to the end of a log file.

But since you're using XProc 3.0 you can make use of support for logging that's part of the core XProc language, in the form of a message attribute on any XProc step: https://spec.xproc.org/master/head/xproc/#messages

  • Related