Comparison

plugins/mod_scansion_record.lua @ 9369:dd452f932b67

mod_scansion_record: Merge header and log into one file at shutdown
author Kim Alvefur <zash@zash.se>
date Sat, 22 Sep 2018 18:43:09 +0200
parent 9368:0c5177738ffd
child 9370:7872abb9fc1f
comparison
equal deleted inserted replaced
9368:0c5177738ffd 9369:dd452f932b67
7 local dt = require "util.datetime"; 7 local dt = require "util.datetime";
8 local dm = require "util.datamanager"; 8 local dm = require "util.datamanager";
9 9
10 local record_id = id.medium():lower(); 10 local record_id = id.medium():lower();
11 local record_date = os.date("%Y%b%d"):lower(); 11 local record_date = os.date("%Y%b%d"):lower();
12 local header_file = dm.getpath(record_id, "scansion", record_date, "sch", true); 12 local header_file = dm.getpath(record_id, "scansion", record_date, "scs", true);
13 local record_file = dm.getpath(record_id, "scansion", record_date, "scs", true); 13 local record_file = dm.getpath(record_id, "scansion", record_date, "log", true);
14 14
15 local head = io.open(header_file, "w"); 15 local head = io.open(header_file, "w");
16 local scan = io.open(record_file, "w"); 16 local scan = io.open(record_file, "w+");
17 17
18 local function record(string) 18 local function record(string)
19 scan:write(string); 19 scan:write(string);
20 end 20 end
21 21
94 94
95 ]] 95 ]]
96 96
97 module:hook_global("server-stopping", function () 97 module:hook_global("server-stopping", function ()
98 record("# recording ended on "..dt.datetime().."\n"); 98 record("# recording ended on "..dt.datetime().."\n");
99 module:log("info", "Scansion recording available in %s", record_file); 99 module:log("info", "Scansion recording available in %s", header_file);
100 end); 100 end);
101 101
102 prosody.events.add_handler("server-cleanup", function () 102 prosody.events.add_handler("server-cleanup", function ()
103 scan:seek("set", 0);
104 for line in scan:lines() do
105 head:write(line, "\n");
106 end
103 scan:close(); 107 scan:close();
108 os.remove(record_file);
104 head:close() 109 head:close()
105 end); 110 end);