Module: Qless::Pool::Logging

Extended by:
Logging
Included in:
Qless::Pool, Qless::Pool, Logging
Defined in:
lib/qless/pool/logging.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.reopen_logs!Object

more than a little bit complicated… copied this from Unicorn.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/qless/pool/logging.rb', line 8

def self.reopen_logs!
  log "Flushing logs"
  [$stdout, $stderr].each do |fd|
    if fd.instance_of? File
      # skip if the file is the exact same inode and device
      orig_st = fd.stat
      begin
        cur_st = File.stat(fd.path)
        next if orig_st.ino == cur_st.ino && orig_st.dev == cur_st.dev
      rescue Errno::ENOENT
      end
      # match up the encoding
      open_arg = 'a'
      if fd.respond_to?(:external_encoding) && enc = fd.external_encoding
        open_arg << ":#{enc.to_s}"
        enc = fd.internal_encoding and open_arg << ":#{enc.to_s}"
      end
      # match up buffering (does reopen reset this?)
      sync = fd.sync
      # sync to disk
      fd.fsync
      # reopen, and set ruby buffering appropriately
      fd.reopen fd.path, open_arg
      fd.sync = sync
      log "Reopened logfile: #{fd.path}"
    end
  end
end

Instance Method Details

#appObject

Include optional app name in procline



57
58
59
60
61
# File 'lib/qless/pool/logging.rb', line 57

def app
  app_name   = self.respond_to?(:app_name)       && self.app_name
  app_name ||= self.class.respond_to?(:app_name) && self.class.app_name
  app_name ? "[#{app_name}]" : ""
end

#log(message) ⇒ Object

TODO: make this use an actual logger



45
46
47
48
# File 'lib/qless/pool/logging.rb', line 45

def log(message)
  puts "qless-pool-manager#{app}[#{Process.pid}]: #{message}"
  #$stdout.fsync
end

#log_worker(message) ⇒ Object

TODO: make this use an actual logger



51
52
53
54
# File 'lib/qless/pool/logging.rb', line 51

def log_worker(message)
  puts "qless-pool-worker#{app}[#{Process.pid}]: #{message}"
  #$stdout.fsync
end

#procline(string) ⇒ Object

Given a string, sets the procline ($0) Procline is always in the format of:

qless-pool-master: STRING


40
41
42
# File 'lib/qless/pool/logging.rb', line 40

def procline(string)
  $0 = "qless-pool-master#{app}: #{string}"
end