Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

How to modify log files of existing builds. #4040

mrinal.das ·

I want to modify log files of existing builds. What function should be used for same need help regarding this

  • solved #6
  • replies 8
  • views 1250
  • stars 1
robinshen ADMIN ·

Log files can not be modified currently. Any reason you want to do that?

mrinal.das ·

Some of old builds have log information missing which we added in later in our scripts. We need same information in old builds as well as log files are used by other projects.

robinshen ADMIN ·

Check the "BuildLogTextStream.java" file in QB source code for how to read the log and you should be able to modify/insert entries and write back with groovy script.

mrinal.das ·

I have tried this

logStream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(logFile), Bootstrap.BUFFER_SIZE)
logStream.writeObject(new_entry);

But what it does is replaces old log with new and doesn't append

logStream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(logFile,true), Bootstrap.BUFFER_SIZE)
  • This doesn't work as well and I end up with a corrupt file.

Probably because - https://stackoverflow.com/questions/1194656/appending-to-an-objectoutputstream

robinshen ADMIN ·

Basically you will need to read all entries to a List, and then add your entries to the list. Then finally write all entries in the list to original stream like below:

for (entry: entries) {
  logStream.writeObject(entry);
}
logStream.writeObject(null); // indicate that the log reaches to end
logStream.close();
mrinal.das ·

Thanks for the help. It works fine now.
I have one more query -
Even though log is modified in the backend but log displayed in view is not changed.
I defined all fields for BuildLogEntry object.

robinshen ADMIN ·

Please make sure:

  1. File is written to the original place and is actually modified
  2. The page is refreshed to re-display the log
robinshen ADMIN ·

Also make sure that you are doing this after build is finished, as otherwise, it will be overwritten by current build log.