Quellcode durchsuchen

Use one log file only for now.

scossu vor 5 Stunden
Ursprung
Commit
671ee75d83
5 geänderte Dateien mit 26 neuen und 24 gelöschten Zeilen
  1. 3 3
      src/core.lua
  2. 3 3
      src/generator.lua
  3. 1 1
      src/repo.lua
  4. 1 0
      src/submission.lua
  5. 18 17
      src/util/watcher.lua

+ 3 - 3
src/core.lua

@@ -16,9 +16,6 @@ local PROTECTED = {
 
 local config_path = os.getenv("PKAR_CONFIG_DIR") or
         path.dirname(datafile.path("config/app.lua"))
-
-print ("Using config at:", config_path)
-
 local config = dofile(path.join(config_path, "app.lua"))
 local store_id = "file://" .. (os.getenv("PKAR_BASE") or config.fs.dres_path)
 
@@ -115,4 +112,7 @@ setmetatable (M, mt)
 
 math.randomseed(M.config.id.seed or os.time())
 
+M.logger:info("Pocket Archive initialized using config at " .. config_path)
+
+
 return M

+ 3 - 3
src/generator.lua

@@ -417,7 +417,7 @@ local function generate_ores(s, mconf)
 
     -- Transform and move media assets.
     local dest_fname, dest_dir, dest  -- Reused for thumbnail.
-    logger:info("Transforming resource file.")
+    logger:debug("Transforming resource file.")
     local res_path = techmd.archive_path
     if not res_path then error("No file path for File resource!") end
     local txconf = (mconf.gen or NT).transformers or {}
@@ -433,7 +433,7 @@ local function generate_ores(s, mconf)
     assert(transformers[pres_conf.fn](
             res_path[1], dest, table.unpack(pres_conf or NT)))
     local pres = dest:gsub(pkar.config.htmlgen.out_dir, "")
-    logger:info("Presentation file: ", pres)
+    logger:debug("Presentation file: ", pres)
 
     -- Thumbnail.
     local tn
@@ -445,7 +445,7 @@ local function generate_ores(s, mconf)
         assert(transformers[txconf.thumbnail.fn](
                 res_path[1], dest, table.unpack(txconf.thumbnail or NT)))
         tn = dest:gsub(M.media_dir, TN_WEB_PATH)
-        logger:info("Thumbnail: ", tn)
+        logger:debug("Thumbnail: ", tn)
     end
 
     out_html = templates.ores.data({

+ 1 - 1
src/repo.lua

@@ -60,7 +60,7 @@ M.store_updates = function(tmp_gr, s)
     logger:debug("Removing stored triples.")
     M.gr:remove(s)
 
-    logger:info("Storing triples.")
+    logger:debug("Storing triples.")
     return tmp_gr:copy(M.gr)
 end
 

+ 1 - 0
src/submission.lua

@@ -389,6 +389,7 @@ M.deposit = function(ll_path, cleanup)
             "Validation raised notices: " .. pp.write(val_report)) end
 
         repo.store_updates(tmp_gr, s)
+        logger:info("Stored: ", s.data)
     end
 
     -- Remove processing directory.

+ 18 - 17
src/util/watcher.lua

@@ -6,6 +6,8 @@ local signal = require "posix.signal"
 local sllog = require "sllog"
 local watchdog = require "watchdog"
 
+local pkar = require "pocket_archive"
+local logger = pkar.logger
 local sub = require "pocket_archive.submission"
 local gen = require "pocket_archive.generator"
 
@@ -13,7 +15,7 @@ local gen = require "pocket_archive.generator"
 local running = true
 
 signal.signal(signal.SIGINT, function()
-  print("\nShutting down...")
+  logger:info("\nShutting down Pocket Archive watchdog...\n")
   running = false
 end)
 
@@ -31,12 +33,14 @@ cli.program {
 
     cli.positional "path" {"Local path of folder to watch."},
 
+    --[[
     cli.flag "f,logfile" {
         "Log file.",
         type = cli.string,
         default="/dev/stderr",
     },
 
+    --]]
     cli.flag "l,loglevel" {
         "Log level: 1 = error, 2 = warning, 3 = info [default], 4 = debug.",
         type = cli.number,
@@ -55,27 +59,24 @@ cli.program {
 
     function(args)
         local wd = watchdog.init()
-        local logfile = assert(io.open(args.logfile, "a"))
-
-        local logger = sllog:init{
-            {"err",   "%T %-5L ",          "%n", logfile},
-            {"warn",  "%T %-5L ",          "%n", logfile},
-            {"info",  "%T %-5L ",          "%n", logfile},
-            {"debug", "%T %-5L%f (%S) ",   "%n", logfile},
-            timefn=(require "socket" or {}).gettime,
-            report="debug",
-            hookrequire=false,
-            level=args.loglevel,
-        }
-
-        logger:info("Starting Pocket Archive watchdog on ")
-        logger:info(args.path, "\n")
+        logger:setlevel(args.loglevel or logger:getlevel())
+
+        logger:info("")
+        logger:info("* * * * * * * * * *")
+        logger:info("Starting Pocket Archive watchdog on ", args.path)
+        logger:info("Config file: ", pkar.config_path)
+        logger:info("D-Res path: ", pkar.config.fs.dres_path)
+        logger:info("O-Res path: ", pkar.config.fs.ores_path)
+        if args.gen_site then
+            logger:info("Generating website at: ", pkar.config.htmlgen.out_dir)
+        end
+        logger:info("* * * * * * * * * *")
 
         wd:add(args.path, watchdog.IN_CLOSE_WRITE, function(ev)
             logger:info("Created new file: ", ev.name, " mask: ", ev.mask)
             logger:info("\n")
             if ev.name:find("pkar_submission.*%.csv") then
-		logger:info("Detected new submission file: ", ev.name)
+                logger:info("Detected new submission file: ", ev.name)
                 -- TODO spawn subprocess
                 sub.deposit(plpath.join(args.path, ev.name), args.cleanup)
                 if args.gen_site then gen.generate_site() end