Mercurial Hosting > luan
view backup/server.luan @ 1736:a02a75e3daa8
webserver error handling
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 16 Oct 2022 11:44:23 -0600 |
parents | 8dd8c556c449 |
children |
line wrap: on
line source
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()