Class: Smplkit::Logging::LoggersClient
- Inherits:
-
Object
- Object
- Smplkit::Logging::LoggersClient
- Defined in:
- lib/smplkit/logging/client.rb
Overview
Surface for client.logging.loggers.* (sync).
Logger CRUD plus the discovery buffer. The buffer is owned by the fused
LoggingClient and shared here so discovery (driven by
LoggingClient#install) and explicit register drain through one queue.
Instance Method Summary collapse
- #_update_logger(logger) ⇒ Object private
-
#delete(id) ⇒ void
Delete a logger by id.
-
#flush ⇒ void
Drain the buffer and POST pending logger sources to the bulk endpoint.
-
#flush_sync ⇒ void
Synchronous flush — alias of
flushfor the periodic-flush path. -
#get(id) ⇒ SmplLogger
Fetch a single logger by id.
-
#get_logger_entry(id) ⇒ Object
private
Fetch one logger as a resolution-cache entry.
-
#initialize(http_client, buffer:, streaming: true) ⇒ LoggersClient
constructor
A new instance of LoggersClient.
-
#list(page_number: nil, page_size: nil) ⇒ Array<SmplLogger>
List loggers for the authenticated account.
-
#list_logger_entries ⇒ Object
private
Runtime entry — walks every page and returns an id-keyed Hash of resolution-cache entries (+level+,
group,managed,environments). -
#new(id, managed: true) ⇒ SmplLogger
Build a new unsaved logger.
-
#pending_count ⇒ Integer
Number of sources queued and awaiting flush.
-
#register(items, flush: false) ⇒ void
Queue one or more logger sources for registration with the server.
Constructor Details
#initialize(http_client, buffer:, streaming: true) ⇒ LoggersClient
Returns a new instance of LoggersClient.
119 120 121 122 123 |
# File 'lib/smplkit/logging/client.rb', line 119 def initialize(http_client, buffer:, streaming: true) @api = SmplkitGeneratedClient::Logging::LoggersApi.new(http_client) @buffer = buffer @streaming = streaming ? true : false end |
Instance Method Details
#_update_logger(logger) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
239 240 241 242 |
# File 'lib/smplkit/logging/client.rb', line 239 def _update_logger(logger) response = ApiSupport::ErrorMapping.call { @api.update_logger(logger.id || logger.name, logger_body(logger)) } Helpers.logger_resource_to_model(self, ApiSupport::ResourceShim.from_model(response.data)) end |
#delete(id) ⇒ void
This method returns an undefined value.
Delete a logger by id.
233 234 235 236 |
# File 'lib/smplkit/logging/client.rb', line 233 def delete(id) ApiSupport::ErrorMapping.call { @api.delete_logger(id) } nil end |
#flush ⇒ void
This method returns an undefined value.
Drain the buffer and POST pending logger sources to the bulk endpoint.
163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/smplkit/logging/client.rb', line 163 def flush batch = @buffer.drain return if batch.empty? items = batch.map do |entry| SmplkitGeneratedClient::Logging::LoggerBulkItem.new( id: entry["id"], resolved_level: entry["resolved_level"], level: entry["level"], service: entry["service"], environment: entry["environment"] ) end body = SmplkitGeneratedClient::Logging::LoggerBulkRequest.new(loggers: items) ApiSupport::ErrorMapping.call { @api.bulk_register_loggers(body) } end |
#flush_sync ⇒ void
This method returns an undefined value.
Synchronous flush — alias of flush for the periodic-flush path.
180 181 182 |
# File 'lib/smplkit/logging/client.rb', line 180 def flush_sync flush end |
#get(id) ⇒ SmplLogger
Fetch a single logger by id.
223 224 225 226 |
# File 'lib/smplkit/logging/client.rb', line 223 def get(id) response = ApiSupport::ErrorMapping.call { @api.get_logger(id) } Helpers.logger_resource_to_model(self, ApiSupport::ResourceShim.from_model(response.data)) end |
#get_logger_entry(id) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fetch one logger as a resolution-cache entry. Used by the logger_changed
WS handler.
257 258 259 260 |
# File 'lib/smplkit/logging/client.rb', line 257 def get_logger_entry(id) response = ApiSupport::ErrorMapping.call { @api.get_logger(id) } logger_entry_from_resource(ApiSupport::ResourceShim.from_model(response.data)) end |
#list(page_number: nil, page_size: nil) ⇒ Array<SmplLogger>
List loggers for the authenticated account.
210 211 212 213 214 215 216 |
# File 'lib/smplkit/logging/client.rb', line 210 def list(page_number: nil, page_size: nil) opts = {} opts[:page_number] = page_number unless page_number.nil? opts[:page_size] = page_size unless page_size.nil? response = ApiSupport::ErrorMapping.call { @api.list_loggers(opts) } (response.data || []).map { |r| Helpers.logger_resource_to_model(self, ApiSupport::ResourceShim.from_model(r)) } end |
#list_logger_entries ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runtime entry — walks every page and returns an id-keyed Hash of
resolution-cache entries (+level+, group, managed, environments).
248 249 250 251 |
# File 'lib/smplkit/logging/client.rb', line 248 def list_logger_entries rows = ApiSupport::PaginatedFetch.collect { |opts| @api.list_loggers(opts) } rows.to_h { |r| logger_entry_from_resource(ApiSupport::ResourceShim.from_model(r)) } end |
#new(id, managed: true) ⇒ SmplLogger
Build a new unsaved logger. The returned SmplLogger is local only;
call its SmplLogger#save to persist it.
199 200 201 |
# File 'lib/smplkit/logging/client.rb', line 199 def new(id, managed: true) SmplLogger.new(self, id: id, name: id, resolved_level: nil, managed: managed) end |
#pending_count ⇒ Integer
Number of sources queued and awaiting flush.
187 188 189 |
# File 'lib/smplkit/logging/client.rb', line 187 def pending_count @buffer.pending_count end |
#register(items, flush: false) ⇒ void
This method returns an undefined value.
Queue one or more logger sources for registration with the server.
Sources are buffered locally and sent in a batch. The batch is sent
automatically once enough sources accumulate; pass flush: true to send
the current batch right away instead of waiting.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/smplkit/logging/client.rb', line 136 def register(items, flush: false) batch = items.is_a?(Array) ? items : [items] batch.each do |src| @buffer.add(LoggerSource.new( name: Normalize.normalize_logger_name(src.name), resolved_level: src.resolved_level, level: src.level, service: src.service, environment: src.environment )) end if flush self.flush return end return unless @buffer.pending_count >= LOGGER_BATCH_FLUSH_SIZE # Stateless mode (+streaming: false+) never spawns background threads — # the threshold flush runs inline (blocking) instead. if @streaming Thread.new { threshold_flush } else threshold_flush end end |