Skip to content

Commit

Permalink
Logging added
Browse files Browse the repository at this point in the history
  • Loading branch information
cstrotm committed Dec 26, 2017
1 parent f300e28 commit ead8b36
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions gophermoon
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
--- Gopher Moon Version 0.2
--- Gopher Moon Version 0.3
--- a simple Gopher Server in Lua
--- with some help from Systemd socket activation
-------------------------------------------------

--- configuration variables
---------------------------
version="0.2"
servername="blog.defaultroutes.de"
version="0.3"
servername="gopher.defaultroutes.de"
serverport="70"
gopherroot="/gopher"

Expand All @@ -33,6 +33,7 @@ end

--- test if a filename is a directory
function isDir(path)
if not exists(path) then return false end
f = io.open(path)
return not f:read(0) and f:seek("end") ~= 0
end
Expand Down Expand Up @@ -96,6 +97,19 @@ function send_gophermap(filepath)
end
end

--- write a log entry
function write_log(severity,msg)
io.stderr:write(severity .. ": " .. msg .. "\n")
end

--- send an error message to the Gopher client
function send_error(msg)
send_info("Welcome to GopherMoon @ gopher.defaultroutes.de")
send_info("-----------------------------------------------")
send_info("Error: " .. msg)
send_end()
end

--- Main Program
----------------

Expand All @@ -110,6 +124,8 @@ if selector == '' then
selector = "/"
end

write_log("INFO", "Selector is " .. selector)

--- make selector relative to the gopher root
filepath = gopherroot .. selector

Expand All @@ -127,10 +143,7 @@ else
if isReadable(filepath) then
send_textfile(filepath)
else
send_info("Welcome to GopherMoon @ defaultroutes.de")
send_info("----------------------------------------")
send_info("Error: Selector not found")
send_end()
send_error("Selector [" .. selector .. "] not found")
write_log("ERROR","Selector not found")
end
end

0 comments on commit ead8b36

Please sign in to comment.