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) ⇒ CoralogixLogger

Constructor.

Parameters:

  • name
    • logger name.



11
12
13
14
15
16
# 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
    self.debug_mode=debug            
    @category = CORALOGIX_CATEGORY
    @manager = LoggerManager.new
    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.



53
54
55
56
57
58
59
60
# File 'lib/centralized_ruby_logger.rb', line 53

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)



32
33
34
# File 'lib/centralized_ruby_logger.rb', line 32

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)



23
24
25
# File 'lib/centralized_ruby_logger.rb', line 23

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)



41
42
43
# File 'lib/centralized_ruby_logger.rb', line 41

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

#flushObject

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



64
65
66
# File 'lib/centralized_ruby_logger.rb', line 64

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



76
77
78
79
80
81
82
83
# File 'lib/centralized_ruby_logger.rb', line 76

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