Mercurial Hosting > luan
diff backup/server.luan @ 1672:8dd8c556c449
backup work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 26 May 2022 21:10:02 -0600 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/backup/server.luan Thu May 26 21:10:02 2022 -0600 @@ -0,0 +1,47 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local ipairs = Luan.ipairs or error() +local Io = require "luan:Io.luan" + +require "java" +local File = require "java:java.io.File" +local BackupServer = require "java:goodjava.lucene.backup.BackupServer" +local Logging = require "luan:logging/Logging.luan" + +local log_to_console = false +for _, arg in ipairs{...} do + if arg == "console" then + log_to_console = true + end +end +if not log_to_console then + local FileWriter = require "java:java.io.FileWriter" + local LuanLogger = require "java:luan.modules.logging.LuanLogger" + local Layouts = require "java:goodjava.logger.Layouts" + local DateLayout = require "java:goodjava.logger.DateLayout" + local ListLayout = require "java:goodjava.logger.ListLayout" + local Level = require "java:goodjava.logger.Level" + local WriterAppender = require "java:goodjava.logger.WriterAppender" + local LevelAppender = require "java:goodjava.logger.LevelAppender" + local ListAppender = require "java:goodjava.logger.ListAppender" + + local layout = ListLayout.new(DateLayout.new("yyyy-MM-dd HH:mm:ss,SSS")," ",Layouts.LEVEL_PADDED," ",Layouts.LOGGER," - ",Layouts.MESSAGE,"\n",Layouts.THROWABLE) + + local function new_appender(file,level) + local writer = FileWriter.new(file,true) + local appender = WriterAppender.new(layout,writer) + appender = LevelAppender.new(appender,level) + return appender + end + + Io.uri("file:logs").mkdir() + local err = new_appender("logs/error.log",Level.ERROR) + local warn = new_appender("logs/warn.log",Level.WARN) + local info = new_appender("logs/info.log",Level.INFO) + local appender = ListAppender.new(err,warn,info) + LuanLogger.configure(appender) +end + +local dir = File.new("backups") +local server = BackupServer.new(dir) +server.start()