-- LOGbook debrief archive for DCS World, version 1 (2026-10-15) -- https://www.ansirial.it/Download -- -- INSTALL: copy this file to Saved Games\DCS\Scripts\Hooks\LOGbook-archive.lua -- (create the Hooks folder if it doesn't exist). Restart DCS. To remove it, delete the file. -- No changes to MissionScripting.lua are needed: scripts in Scripts\Hooks run in the DCS GUI environment, -- where io, os and lfs are already available (see API\Sim_ControlAPI.md in your DCS install). -- -- WHAT IT DOES: DCS rewrites Logs\debrief.log after every mission, so if you fly several missions in a row -- only the last one can be uploaded to LOGbook. This script copies debrief.log to Logs\LOGbook\ before DCS -- overwrites it: when DCS starts and when each new mission starts loading. Upload the copies from there -- with "Upload DCS Mission Log" on your pilot page. The last mission of a session stays in Logs\debrief.log -- until the next mission or the next time you start DCS. -- (It doesn't copy at the end of a mission because DCS writes the debrief a moment after the stop callbacks.) -- -- WHAT IT DOESN'T DO: it sends nothing over the network, reads nothing but debrief.log, and doesn't touch -- missions or multiplayer. It keeps the last 40 copies and deletes older ones. Any error stays inside this -- script and is written to dcs.log with the LOGBOOK prefix: it must never get in the way of DCS. local lfs = require("lfs") local LOGbook = {} local KEEP_FILES = 40 -- copies kept; older ones are deleted local LOG_DIR = lfs.writedir() .. "Logs\\" local SOURCE = LOG_DIR .. "debrief.log" local ARCHIVE = LOG_DIR .. "LOGbook\\" local function info(message) log.write("LOGBOOK", log.INFO, message) end -- Binary copy in blocks: a multiplayer debrief can be over 50 MB. -- The loop is bounded by the file size, not by the end of reading: in the DCS io library read() does not -- return nil at the end of the file (an earlier version that waited for nil froze DCS at startup). local CHUNK = 1048576 local function copyFile(from, to, size) local input = io.open(from, "rb") if not input then return false end local output = io.open(to, "wb") if not output then input:close() return false end local remaining = size local blocks = math.floor(size / CHUNK) + 2 while remaining > 0 and blocks > 0 do local block = input:read(math.min(CHUNK, remaining)) if not block or #block == 0 then break end output:write(block) remaining = remaining - #block blocks = blocks - 1 end input:close() output:close() return remaining == 0 end -- oldest first: the name holds the date and time of the mission local function pruneArchive() local files = {} for name in lfs.dir(ARCHIVE) do if name:match("^debrief%-%d+%-%d+%.log$") then table.insert(files, name) end end table.sort(files) for i = 1, #files - KEEP_FILES do os.remove(ARCHIVE .. files[i]) end end -- The name comes from the time debrief.log was last written, that is the end of the mission: archiving the -- same debrief twice gives the same name, so there are no duplicates. local function archive(reason) local ok, err = pcall(function() local size = lfs.attributes(SOURCE, "size") if not size or size == 0 then return end local modified = lfs.attributes(SOURCE, "modification") local target = ARCHIVE .. "debrief-" .. os.date("%Y%m%d-%H%M%S", modified) .. ".log" if lfs.attributes(target, "mode") == "file" and lfs.attributes(target, "size") == size then return end if lfs.attributes(ARCHIVE, "mode") ~= "directory" then lfs.mkdir(ARCHIVE) end info("archiving debrief.log (" .. reason .. ", " .. size .. " bytes)") if copyFile(SOURCE, target, size) then info("archived debrief.log (" .. reason .. ") as " .. target) pruneArchive() else info("could not archive debrief.log (" .. reason .. ")") end end) if not ok then info("error: " .. tostring(err)) end end function LOGbook.onMissionLoadBegin() archive("mission load") end local loaded, loadError = pcall(function() -- the documented API table is Sim.*, existing hooks still use DCS.* local api = Sim or DCS api.setUserCallbacks(LOGbook) -- at DCS startup: the debrief of the last mission of the previous session archive("startup") info("debrief archive hook loaded, archive folder " .. ARCHIVE) end) if not loaded then log.write("LOGBOOK", log.ERROR, "hook not loaded: " .. tostring(loadError)) end