Permalink
Browse files

add log rotation

  • Loading branch information...
1 parent 29072a3 commit 74592a1c9f795b0dbcdd0705e600b8eaa6494351 @burgalon burgalon committed Feb 29, 2012
Showing with 10 additions and 3 deletions.
  1. +10 −3 bin/gelfd
View
@@ -3,13 +3,21 @@ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
require 'socket'
require 'gelfd'
require 'json'
+require 'logger'
server = UDPSocket.new
port = ENV['PORT'] || 11211
-puts "Starting up port #{port}"
server.bind(nil, port)
trap("INT") { puts "Shutting down"; exit }
+# 100 MB filesize limit
+logfile_limit = (ENV['LOGFILE_LIMIT'] || 10).to_i
+logfile_sizelimit = (ENV['LOGFILE_SIZE'] || 104857600).to_i
+logfile = ENV['LOGFILE'] || STDOUT
+logger = Logger.new(logfile, logfile_limit, logfile_sizelimit)
+
+puts "Starting up port #{port} #{logfile} #{logfile_sizelimit/1024/1024}MB #{logfile_limit}"
+
loop do
data, addr = server.recvfrom(8192)
begin
@@ -19,10 +27,9 @@ loop do
end
if !res.nil?
res = JSON res
- time = Time.at(res['timestamp'])
message = res['short_message'].gsub(/\n/, " ")
email = res['_user_email'] || "anonymous"
- puts "#{res['level']} #{time} #{res['_remote_addr']} #{email} #{message}"
+ logger.add(res['level'], "#{res['level']} #{res['_remote_addr']} #{email} #{message}")
# 127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"
end
end

0 comments on commit 74592a1

Please sign in to comment.