Class: CustomLogs::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/custom_logs/socket.rb

Constant Summary collapse

@@socket =
nil
@@socket_type =
nil

Class Method Summary collapse

Class Method Details

.getObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/custom_logs/socket.rb', line 10

def get
  @@socket if @@socket
  if (syslog_config = ParseConfig.get[:syslog]).present?
    @@socket = RemoteSyslogLogger.new(syslog_config[:host], syslog_config[:port])
    @@socket_type = :syslog
  else
    @@socket = ::Logger.new(STDOUT)
    @@socket_type = :stdout
  end

  @@socket.formatter  = proc do |severity, datetime, progname, msg|
    "#{msg}\n"
  end

  @@socket
end

.socket_typeObject



31
32
33
34
# File 'lib/custom_logs/socket.rb', line 31

def socket_type
  get unless @@socket
  @@socket_type
end

.stdout?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/custom_logs/socket.rb', line 40

def stdout?
  socket_type == :stdout
end

.syslog?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/custom_logs/socket.rb', line 36

def syslog?
  socket_type == :syslog
end

.write(message) ⇒ Object



27
28
29
# File 'lib/custom_logs/socket.rb', line 27

def write(message)
  get.unknown("[CUSTOM-LOGS]#{message}")
end