Class: LogMessageBuilder
- Inherits:
-
Object
- Object
- LogMessageBuilder
- Defined in:
- lib/wingify/packages/logger/log_message_builder.rb
Overview
Copyright 2024-2026 Wingify Software Pvt. Ltd.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Constant Summary collapse
- ANSI_COLOR_ENUM =
{ bold: "\x1b[1m", cyan: "\x1b[36m", green: "\x1b[32m", lightblue: "\x1b[94m", red: "\x1b[31m", reset: "\x1b[0m", white: "\x1b[30m", yellow: "\x1b[33m" }
- LOG_LEVEL_COLOR =
{ 'TRACE' => ANSI_COLOR_ENUM[:white], 'DEBUG' => ANSI_COLOR_ENUM[:lightblue], 'INFO' => ANSI_COLOR_ENUM[:cyan], 'WARN' => ANSI_COLOR_ENUM[:yellow], 'ERROR' => ANSI_COLOR_ENUM[:red] }
Instance Method Summary collapse
- #format_message(level, message) ⇒ Object
-
#initialize(logger_config, transport_config) ⇒ LogMessageBuilder
constructor
A new instance of LogMessageBuilder.
Constructor Details
#initialize(logger_config, transport_config) ⇒ LogMessageBuilder
Returns a new instance of LogMessageBuilder.
35 36 37 38 39 40 41 42 |
# File 'lib/wingify/packages/logger/log_message_builder.rb', line 35 def initialize(logger_config, transport_config) @logger_config = logger_config @transport_config = transport_config # Access the values directly from transport_config if available. @prefix = transport_config.instance_variable_get(:@prefix) || logger_config[:prefix] || '' @date_time_format = transport_config.respond_to?(:date_time_format) ? transport_config.date_time_format : logger_config[:date_time_format] || lambda { Time.now.iso8601 } end |
Instance Method Details
#format_message(level, message) ⇒ Object
44 45 46 |
# File 'lib/wingify/packages/logger/log_message_builder.rb', line 44 def (level, ) "[#{get_formatted_level(level)}]: #{get_formatted_prefix(@prefix)} #{get_formatted_date_time} #{}" end |