Scala - Append XML to file

Xcon

New Member
I'm creating a simple web server in Scala and I am trying to implement event logging to an XML file. The XML Structure is thus:\[code\]<log> <event> <type>Info/Warning/Error/etc</type> <description>File not found etc</description> <file>/etc/etc.etc</file> <ip>1.2.3.4</ip> <time>12:34:56 1st Jan 2012</time> </event> <event> etc... <event></log>\[/code\]Currently im attempting to write the XML to a file like this:\[code\]var logEvent = <log><event><type>ERROR</type><description>The Requested File was not found</description><file>{path}</file><ip>{connection.getRemoteSocketAddress}</ip><time>{new Date(System.currentTimeMillis)}</time></event></log>XML.save(logFile, logEvent, "UTF-8", true, null)\[/code\]However when I check the file only the most recent even is there and refreshing the file while the server is running shows each event replaces the last one in the file. Ive also tried using a \[code\]FileOutputStream\[/code\] with appending enabled along with \[code\]XML.write\[/code\]but that inserts the XML schema before each event which stops it being recognised as a proper XML file. It also adds the root \[code\]<log>\[/code\] tags around every event.The only way i can think of is loading the current XML in the file, adding to it and then writing it back which seems rather inefficient to me.Is there a simple way to append XML to a file that i'm missing?Any help appreciated :)
 
Back
Top