annotate backup/server.luan @ 1751:357daf580951

LuanDomainHandler domain check
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 24 Jan 2023 16:30:29 -0700
parents 8dd8c556c449
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1672
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local ipairs = Luan.ipairs or error()
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Io = require "luan:Io.luan"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 require "java"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local File = require "java:java.io.File"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local BackupServer = require "java:goodjava.lucene.backup.BackupServer"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Logging = require "luan:logging/Logging.luan"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local log_to_console = false
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 for _, arg in ipairs{...} do
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 if arg == "console" then
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 log_to_console = true
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 end
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 end
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 if not log_to_console then
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 local FileWriter = require "java:java.io.FileWriter"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 local LuanLogger = require "java:luan.modules.logging.LuanLogger"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local Layouts = require "java:goodjava.logger.Layouts"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 local DateLayout = require "java:goodjava.logger.DateLayout"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 local ListLayout = require "java:goodjava.logger.ListLayout"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 local Level = require "java:goodjava.logger.Level"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 local WriterAppender = require "java:goodjava.logger.WriterAppender"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 local LevelAppender = require "java:goodjava.logger.LevelAppender"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 local ListAppender = require "java:goodjava.logger.ListAppender"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 local layout = ListLayout.new(DateLayout.new("yyyy-MM-dd HH:mm:ss,SSS")," ",Layouts.LEVEL_PADDED," ",Layouts.LOGGER," - ",Layouts.MESSAGE,"\n",Layouts.THROWABLE)
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 local function new_appender(file,level)
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 local writer = FileWriter.new(file,true)
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 local appender = WriterAppender.new(layout,writer)
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 appender = LevelAppender.new(appender,level)
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 return appender
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 end
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 Io.uri("file:logs").mkdir()
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 local err = new_appender("logs/error.log",Level.ERROR)
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 local warn = new_appender("logs/warn.log",Level.WARN)
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 local info = new_appender("logs/info.log",Level.INFO)
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 local appender = ListAppender.new(err,warn,info)
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 LuanLogger.configure(appender)
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 end
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 local dir = File.new("backups")
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 local server = BackupServer.new(dir)
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 server.start()