cmd_syslog.rb

znmud-0.0.1/cmd/zombie/cmd_syslog.rb · 885 B

From the archive znmud-minimal-0.0.1.tar.gz

Download the archive   « Back to the archive contents

#
# file::    cmd_syslog.rb

# This source code copyright (C) 2009 Craig Smith
# All rights reserved.
#
# Released under the terms of the TeensyMUD Public License
# See LICENSE file for additional information.
#

module Cmd

  bindtextdomain("cmd")

  # Shows the system log
  def cmd_syslog(args)
	sendto("Loading log file...")
	max = 20
	max = args.to_i if args.to_i > 0
	lines = []
	File.open(options['logfile'], "r").each { |l| lines << l }
	revlines = []
	cnt = 1
	lines.reverse.each do |l| 
	    if not l=~/\[DEBUG\]/
		if cnt <= max
			revlines << l
		end
		cnt += 1
	    end
	end
	msg = ""
	revlines.reverse.each do |l|
		if l.size > 70
			msg << "#{l[0,67]}...\n"
		else
			msg << l
		end
	end
	if msg.size > 0
		msg = Msg.new(msg)
		msg.no_parse = true
		sendto(msg)
	else
		sendto _("No messages in syslog.")
	end
  end

end

Site Stats

Snippets: 1791
Codebases: 571