Class: Swiftcore::Analogger::Client
- Inherits:
-
Object
- Object
- Swiftcore::Analogger::Client
- Defined in:
- lib/swiftcore/Analogger/Client.rb,
lib/swiftcore/LoggerInterface.rb,
lib/swiftcore/Analogger/EMClient.rb
Overview
Swift::Analogger::Client is the client library for writing logging messages to the Swift Analogger asynchronous logging server.
To use the Analogger client, instantiate an instance of the Client class.
logger = Swift::Analogger::Client.new(:myapplog,'127.0.0.1',12345)
Four arguments are accepted when a new Client is created. The first is the name of the logging facility that this Client will write to. The second is the hostname where the Analogger process is running, and the third is the port number that it is listening on for connections.
The fourth argument is optional. Analogger can require an authentication key before it will allow logging clients to use its facilities. If the Analogger that one is connecting to requires an authentication key, it must be passed to the new() call as the fourth argument. If the key is incorrect, the connection will be closed.
If a Client connects to the Analogger using a facility that is undefined in the Analogger, the log messages will still be accepted, but they will be dumped to the default logging destination.
Once connected, the Client is ready to deliver messages to the Analogger. To send a messagine, the log() method is used:
logger.log(:debug,"The logging client is now connected.")
The log() method takes two arguments. The first is the severity of the message, and the second is the message itself. The default Analogger severity levels are the same as in the standard Ruby
Defined Under Namespace
Modules: LoggerInterface Classes: FailedToAuthenticate
Constant Summary collapse
- MaxMessageLength =
8192
- MaxLengthBytes =
MaxMessageLength.to_s.length
- ConnectionFailureTimeout =
Log locally for a long time if Analogger server goes down.
86400 * 2
- MaxFailureCount =
Max integer – i.e. really big
(2**(0.size * 8 - 2) - 1)
- PersistentQueueLimit =
Default to allowing around 10GB temporary local log storage
10737412742
- ReconnectThrottleInterval =
0.1
Class Method Summary collapse
-
.connection_failure_timeout ⇒ Object
—– Various class accessors – use these to set defaults.
- .connection_failure_timeout=(val) ⇒ Object
- .max_failure_count ⇒ Object
- .max_failure_count=(val) ⇒ Object
- .new(*args) ⇒ Object
- .persistent_queue_limit ⇒ Object
- .persistent_queue_limit=(val) ⇒ Object
- .reconnect_throttle_interval ⇒ Object
- .reconnect_throttle_interval=(val) ⇒ Object
- .tmplog ⇒ Object
- .tmplog=(val) ⇒ Object
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#connect ⇒ Object
—– The meat of the client.
- #connection_failure_timeout ⇒ Object
- #connection_failure_timeout=(val) ⇒ Object
-
#initialize(service = -"default",, host = -"127.0.0.1" ,, port = 6766, key = nil) ⇒ Client
constructor
—–.
- #log(severity, msg) ⇒ Object
- #max_failure_count ⇒ Object
- #max_failure_count=(val) ⇒ Object
- #persistent_queue_limit ⇒ Object
- #persistent_queue_limit=(val) ⇒ Object
- #ram_queue_limit ⇒ Object
- #ram_queue_limit=(val) ⇒ Object
- #reconnect ⇒ Object
- #reconnect_throttle_interval ⇒ Object
- #reconnect_throttle_interval=(val) ⇒ Object
- #tmplog ⇒ Object
- #tmplog=(val) ⇒ Object
- #tmplog_prefix ⇒ Object
- #tmplogs ⇒ Object
-
#total_count ⇒ Object
—– Various instance accessors.
Constructor Details
#initialize(service = -"default",, host = -"127.0.0.1" ,, port = 6766, key = nil) ⇒ Client
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/swiftcore/Analogger/Client.rb', line 114 def initialize(service = -"default", host = -"127.0.0.1" , port = 6766, key = nil) @service = service.to_s @key = key @host = host @port = port @socket = nil klass = self.class @connection_failure_timeout = klass.connection_failure_timeout @max_failure_count = klass.max_failure_count @persistent_queue_limit = klass.persistent_queue_limit @destination = nil @reconnection_thread = nil @authenticated = false @total_count = 0 @logfile = nil @swamp_drainer = nil clear_failure connect end |
Class Method Details
.connection_failure_timeout ⇒ Object
—– Various class accessors – use these to set defaults
72 73 74 |
# File 'lib/swiftcore/Analogger/Client.rb', line 72 def self.connection_failure_timeout @connection_failure_timeout ||= ConnectionFailureTimeout end |
.connection_failure_timeout=(val) ⇒ Object
76 77 78 |
# File 'lib/swiftcore/Analogger/Client.rb', line 76 def self.connection_failure_timeout=(val) @connection_failure_timeout = val.to_i end |
.max_failure_count ⇒ Object
80 81 82 |
# File 'lib/swiftcore/Analogger/Client.rb', line 80 def self.max_failure_count @max_failure_count ||= MaxFailureCount end |
.max_failure_count=(val) ⇒ Object
84 85 86 |
# File 'lib/swiftcore/Analogger/Client.rb', line 84 def self.max_failure_count=(val) @max_failure_count = val.to_i end |
.new(*args) ⇒ Object
95 96 97 |
# File 'lib/swiftcore/Analogger/EMClient.rb', line 95 def self.new(*args) ClientProtocol.connect(*args) end |
.persistent_queue_limit ⇒ Object
88 89 90 |
# File 'lib/swiftcore/Analogger/Client.rb', line 88 def self.persistent_queue_limit @persistent_queue_limit ||= PersistentQueueLimit end |
.persistent_queue_limit=(val) ⇒ Object
92 93 94 |
# File 'lib/swiftcore/Analogger/Client.rb', line 92 def self.persistent_queue_limit=(val) @persistent_queue_limit = val.to_i end |
.reconnect_throttle_interval ⇒ Object
104 105 106 |
# File 'lib/swiftcore/Analogger/Client.rb', line 104 def self.reconnect_throttle_interval @reconnect_throttle_interval ||= ReconnectThrottleInterval end |
.reconnect_throttle_interval=(val) ⇒ Object
108 109 110 |
# File 'lib/swiftcore/Analogger/Client.rb', line 108 def self.reconnect_throttle_interval=(val) @reconnect_throttle_interval = val.to_i end |
.tmplog ⇒ Object
96 97 98 |
# File 'lib/swiftcore/Analogger/Client.rb', line 96 def self.tmplog @tmplog end |
.tmplog=(val) ⇒ Object
100 101 102 |
# File 'lib/swiftcore/Analogger/Client.rb', line 100 def self.tmplog=(val) @tmplog = val end |
Instance Method Details
#authenticated? ⇒ Boolean
387 388 389 |
# File 'lib/swiftcore/Analogger/Client.rb', line 387 def authenticated? @authenticated end |
#close ⇒ Object
395 396 397 |
# File 'lib/swiftcore/Analogger/Client.rb', line 395 def close @socket.close end |
#closed? ⇒ Boolean
399 400 401 |
# File 'lib/swiftcore/Analogger/Client.rb', line 399 def closed? @socket.closed? end |
#connect ⇒ Object
—– The meat of the client
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/swiftcore/Analogger/Client.rb', line 200 def connect @socket = open_connection(@host, @port) authenticate raise FailedToAuthenticate(@host, @port) unless authenticated? clear_failure if there_is_a_swamp? drain_the_swamp else setup_remote_logging end rescue Exception => e register_failure close_connection setup_reconnect_thread unless @reconnection_thread && Thread.current == @reconnection_thread setup_local_logging raise e if fail_connect? end |
#connection_failure_timeout ⇒ Object
142 143 144 |
# File 'lib/swiftcore/Analogger/Client.rb', line 142 def connection_failure_timeout @connection_failure_timeout end |
#connection_failure_timeout=(val) ⇒ Object
146 147 148 |
# File 'lib/swiftcore/Analogger/Client.rb', line 146 def connection_failure_timeout=(val) @connection_failure_timeout = val.to_i end |
#log(severity, msg) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/swiftcore/Analogger/Client.rb', line 58 def log(severity, msg) if @destination == :local _local_log(@service, severity, msg) else _remote_log(@service, severity, msg) end rescue Exception @authenticated = false setup_local_logging setup_reconnect_thread end |
#max_failure_count ⇒ Object
150 151 152 |
# File 'lib/swiftcore/Analogger/Client.rb', line 150 def max_failure_count @max_failure_count end |
#max_failure_count=(val) ⇒ Object
154 155 156 |
# File 'lib/swiftcore/Analogger/Client.rb', line 154 def max_failure_count=(val) @max_failure_count = val.to_i end |
#persistent_queue_limit ⇒ Object
166 167 168 |
# File 'lib/swiftcore/Analogger/Client.rb', line 166 def persistent_queue_limit @persistent_queue_limit end |
#persistent_queue_limit=(val) ⇒ Object
170 171 172 |
# File 'lib/swiftcore/Analogger/Client.rb', line 170 def persistent_queue_limit=(val) @persistent_queue_limit = val.to_i end |
#ram_queue_limit ⇒ Object
158 159 160 |
# File 'lib/swiftcore/Analogger/Client.rb', line 158 def ram_queue_limit @ram_queue_limit end |
#ram_queue_limit=(val) ⇒ Object
162 163 164 |
# File 'lib/swiftcore/Analogger/Client.rb', line 162 def ram_queue_limit=(val) @ram_queue_limit = val.to_i end |
#reconnect ⇒ Object
391 392 393 |
# File 'lib/swiftcore/Analogger/Client.rb', line 391 def reconnect connect(@host,@port) end |
#reconnect_throttle_interval ⇒ Object
190 191 192 |
# File 'lib/swiftcore/Analogger/Client.rb', line 190 def reconnect_throttle_interval @reconnect_throttle_interval ||= self.class.reconnect_throttle_interval end |
#reconnect_throttle_interval=(val) ⇒ Object
194 195 196 |
# File 'lib/swiftcore/Analogger/Client.rb', line 194 def reconnect_throttle_interval=(val) @reconnect_throttle_interval = val.to_i end |
#tmplog ⇒ Object
178 179 180 |
# File 'lib/swiftcore/Analogger/Client.rb', line 178 def tmplog @tmplog ||= tmplog_prefix.gsub(/SERVICE/, @service).gsub(/PID/,$$.to_s) end |
#tmplog=(val) ⇒ Object
186 187 188 |
# File 'lib/swiftcore/Analogger/Client.rb', line 186 def tmplog=(val) @tmplog = val end |
#tmplog_prefix ⇒ Object
174 175 176 |
# File 'lib/swiftcore/Analogger/Client.rb', line 174 def tmplog_prefix File.join(Dir.tmpdir, -"analogger-SERVICE-PID.log") end |
#tmplogs ⇒ Object
182 183 184 |
# File 'lib/swiftcore/Analogger/Client.rb', line 182 def tmplogs Dir[tmplog_prefix.gsub(/SERVICE/, @service).gsub(/PID/,-"*")].sort_by {|f| File.mtime(f)} end |
#total_count ⇒ Object
—– Various instance accessors
138 139 140 |
# File 'lib/swiftcore/Analogger/Client.rb', line 138 def total_count @total_count end |