Class: Coralogix::CoralogixLogger

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

Instance Method Summary collapse

Constructor Details

#initialize(private_key, app_name, sub_system_name, debug = false, type_name = "Centralized Ruby", force_compression = false, proxy = {}, external_logger = nil) ⇒ CoralogixLogger

Constructor.

Parameters:

  • name
    • logger name.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/centralized_ruby_logger.rb', line 11

def initialize private_key, app_name, sub_system_name, debug=false, type_name="Centralized Ruby", force_compression=false, proxy={}, external_logger=nil
    self.debug_mode=debug            
    @category = CORALOGIX_CATEGORY
    @manager = LoggerManager.new proxy
    unless external_logger.nil?
        DebugLogger.enabled = true
        DebugLogger.external = true
        DebugLogger.logger = external_logger
    end
    configure(private_key, app_name, sub_system_name, type_name, force_compression)
end

Instance Method Details

#configure(private_key, app_name, sub_system, type_name, force_compression) ⇒ boolean

Configure coralogix logger with customer specific values

Parameters:

  • private_key
    • private key

  • app_name
    • application name

  • sub_system
    • sub system name

  • type_name
    • type name

  • force_compression
    • when true, will not send the raw data if data compression failed

Returns:

  • (boolean)

    return a true or false.



58
59
60
61
62
63
64
65
# File 'lib/centralized_ruby_logger.rb', line 58

def configure private_key, app_name, sub_system, type_name, force_compression
    private_key = (private_key.nil? || private_key.to_s.strip.empty?) ? FAILED_PRIVATE_KEY : private_key
    app_name = (app_name.nil? || app_name.to_s.strip.empty?) ? NO_APP_NAME : app_name
    sub_system = (sub_system.nil? || sub_system.to_s.strip.empty?) ? NO_SUB_SYSTEM : sub_system
    @manager.set_logger_type_name type_name
    @manager.force_compression = force_compression
    @manager.configure(:privateKey => private_key, :applicationName => app_name, :subsystemName => sub_system) unless @manager.configured
end

#debug_mode=(value) ⇒ Object

A setter for debug_mode.

Default value is false. When set to true the coralogix logger will print output messages to a console and a file.

Parameters:

  • value
    • true or false. (Default is false)



37
38
39
# File 'lib/centralized_ruby_logger.rb', line 37

def debug_mode=(value)
    DebugLogger.debug_mode=value
end

#debug_mode?boolean

A getter for debug_mode. Default value is false. When set to true the coralogix logger will print output messages to a console and a file.

Returns:

  • (boolean)
    • true or false. (Default is false)



28
29
30
# File 'lib/centralized_ruby_logger.rb', line 28

def debug_mode?
    DebugLogger.debug_mode
end

#disable_proxy=(value) ⇒ Object

A setter for disable_proxy. By default HTTP object will use proxy environment variable if exists. In some cases this migh be an issue When set to false the HTTP object will ignore any proxy.

Parameters:

  • value
    • true or false. (Default is false)



46
47
48
# File 'lib/centralized_ruby_logger.rb', line 46

def disable_proxy=(value)
    @manager.disable_proxy=value
end

#flushObject

Flush all messages in buffer and send them immediately on the current thread.



69
70
71
# File 'lib/centralized_ruby_logger.rb', line 69

def flush
    @manager.flush
end

#log(severity, message, category = @category, named_args = {}) ⇒ Object

Log a message.

Parameters:

  • severity
    • log severity

  • message
    • log message

  • category (defaults to: @category)
    • log category

  • className
    • log class name

  • methodName
    • log method name

  • threadId
    • log thread id



81
82
83
84
85
86
87
88
# File 'lib/centralized_ruby_logger.rb', line 81

def log severity, message, category=@category, named_args = {}

    className = named_args.fetch(:className,"")
    methodName = named_args.fetch(:methodName,"")
    threadId = named_args.fetch(:threadId,Thread.current.object_id.to_s)

    @manager.add_logline message, severity, category, :className => className, :methodName => methodName, :threadId => threadId
end