Module: ServerSide

Defined in:
lib/serverside.rb,
lib/serverside/log.rb,
lib/serverside/xml.rb,
lib/serverside/http.rb,
lib/serverside/template.rb

Overview

ServerSide is a web framework that make it easy to create custom light-weight web applications. It contains the following functionalities:

  1. A fast multithreaded HTTP server with support for persistent connections

and streaming.

  1. A static file handler.

  2. A daemon for controlling a server or a cluster of servers.

  3. A simple script for serving files or applications easily.

  4. A simple controller-view system for processing requests.

Defined Under Namespace

Modules: HTTP Classes: Template, XML

Constant Summary collapse

REFERER =
"Referer".freeze
USER_AGENT =
"User-Agent".freeze
HOST =
"Host".freeze
HOST_REGEXP =
/([^\:]*)(\:(.*))?$/
@@logger =
nil

Class Method Summary collapse

Class Method Details

.debug(text) ⇒ Object



28
29
30
# File 'lib/serverside/log.rb', line 28

def self.debug(text)
  @@logger.debug(text) if @@logger
end

.error(text) ⇒ Object



40
41
42
# File 'lib/serverside/log.rb', line 40

def self.error(text)
  @@logger.error(text) if @@logger
end

.fatal(text) ⇒ Object



44
45
46
# File 'lib/serverside/log.rb', line 44

def self.fatal(text)
  @@logger.fatal(text) if @@logger
end

.info(text) ⇒ Object



32
33
34
# File 'lib/serverside/log.rb', line 32

def self.info(text)
  @@logger.info(text) if @@logger
end

.log(level, text) ⇒ Object



24
25
26
# File 'lib/serverside/log.rb', line 24

def self.log(level, text)
  @@logger.log(level, text) if @@logger
end

.log_error(e) ⇒ Object



48
49
50
51
52
# File 'lib/serverside/log.rb', line 48

def self.log_error(e)
  if @@logger
    @@logger.error("#{e.message}:\r\n" + e.backtrace.join("\r\n"))
  end
end

.log_request(c) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/serverside/log.rb', line 59

def self.log_request(c)
  if @@logger
    return unless request_line = c.request_line
    req_line.chomp!
    if c.method == :post && c.content_type == HTTP::Request::CONTENT_TYPE_URL_ENCODED
      req_line << " (#{r.body})"
    end
    host = (r.request_headers[HOST] || "") =~ HOST_REGEXP ? $1 : ""
    msg = "%s %s %s %s %s %s %s" % [
      r.client_name,
      host.inspect,
      request_line.inspect,
      r.status || '?',
      r.content_length || '?',
      (r.headers[REFERER] || "").inspect,
      (r.headers[USER_AGENT] || "").inspect
    ]
    @@logger.info(msg)
  end
end

.loggerObject



6
7
8
# File 'lib/serverside/log.rb', line 6

def self.logger
  @@logger
end

.logger=(l) ⇒ Object



10
11
12
# File 'lib/serverside/log.rb', line 10

def self.logger=(l)
  @@logger = l
end

.logger_level=(level) ⇒ Object



20
21
22
# File 'lib/serverside/log.rb', line 20

def self.logger_level=(level)
  @@logger.level = level if @@logger
end

.setup_stock_logger(logdev, shift_age = 0, shift_size = 1048576) ⇒ Object



14
15
16
17
18
# File 'lib/serverside/log.rb', line 14

def self.setup_stock_logger(logdev, shift_age = 0, shift_size = 1048576)
  @@logger = Logger.new(logdev, shift_age, shift_size)
  @@logger.datetime_format = "%Y-%m-%d %H:%M:%S"
  @@logger
end

.warn(text) ⇒ Object



36
37
38
# File 'lib/serverside/log.rb', line 36

def self.warn(text)
  @@logger.warn(text) if @@logger
end