class Coralogix::CoralogixLogger

Attributes

use_source_file[RW]

Public Class Methods

configure(private_key, app_name, sub_system) click to toggle source

Configure coralogix logger with customer specific values

@param private_key - private key @param app_name - application name @param sub_system - sub system name @return [boolean] return a true or false.

# File lib/coralogix_logger.rb, line 95
def self.configure private_key, app_name, sub_system
    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
    LoggerManager.configure(:privateKey => private_key, :applicationName => app_name, :subsystemName => sub_system) unless LoggerManager.configured
end
debug_mode=(value) click to toggle source

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.

@param value - true or false. (Default is false)

# File lib/coralogix_logger.rb, line 47
def self.debug_mode=(value)
    DebugLogger.debug_mode=value
end
debug_mode?() click to toggle source

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.

@return [boolean] - true or false. (Default is false)

# File lib/coralogix_logger.rb, line 38
def self.debug_mode?
    DebugLogger.debug_mode
end
disable_proxy=(value) click to toggle source

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.

@param value - true or false. (Default is false)

# File lib/coralogix_logger.rb, line 75
def self.disable_proxy=(value)
    CoralogixHTTPSender.disable_proxy=value
end
get_logger(name) click to toggle source

A class method (static) to return a new instance of the current class. This is the most common pattern when using logging.

@param name - name of the logger. The category. Usually this will be a new name for every class or a logical unit. @return [CoralogixLogger] return a new instance of CoralogixLogger.

# File lib/coralogix_logger.rb, line 84
def self.get_logger name
    #Return a new instance of the current class.
    CoralogixLogger.send(:new, name)
end
new(name) click to toggle source

Constructor.

@param name - logger name.

# File lib/coralogix_logger.rb, line 19
def initialize name
    @category = name
    @level=0
    @use_source_file = true
end
print_stack_trace=(value) click to toggle source

A setter for print stack trace. Default value is false. When set to true the coralogix logger will print stack trace for each log line.

@param value - true or false. (Default is false)

reconnect() click to toggle source

Spawn a new worker thread

# File lib/coralogix_logger.rb, line 103
def self.reconnect
    LoggerManager.reconnect
end
stack_frame=(value) click to toggle source

A setter for stack frame. Default value is 5. The stack frame to extract from the stack trace

@param value [int] - (Default is 5)

# File lib/coralogix_logger.rb, line 65
def self.stack_frame=(value)
    @@stack_frame=value
end

Public Instance Methods

<<(x) click to toggle source

Logger interface: Dump given message to the log device without any formatting.

# File lib/coralogix_logger.rb, line 180
def << x
    self.add 0, nil, x
end
add(severity, message = nil, progname = nil) { || ... } click to toggle source

Logger interface: Send log message if the given severity is high enough. @param severity - Severity. Constants are defined in Logger namespace: DEBUG, INFO, WARN, ERROR, FATAL, or +UNKNOWN @param message - The log message. A String or Exception. @param progname - Program name string. Can be omitted. Treated as a message if no message and block are given. @param block - Can be omitted. Called to get a message string if message is nil. @return [boolean] When the given severity is not high enough (for this particular logger), log no message, and return true.

# File lib/coralogix_logger.rb, line 143
def add(severity, message = nil, progname = nil, &block)
    
    thread = ""

    begin
        severity ||= DEBUG
        if severity < @level
            return true
        end
        progname ||= @category
        if message.nil?
            if block_given?
                message = yield
            else
                message = progname
                progname = @category
            end
        end
        className = get_source_file if @use_source_file
        thread = Thread.current.object_id.to_s
    rescue Exception => e  
        DebugLogger.error e.message  
        DebugLogger.error e.backtrace.inspect
    end

    # Map Ruby Severity to Coralogix severity:
    #          Ruby Coralogix
    #    DEBUG  0      1
    #    INFO   1      3
    #    WARN   2      4
    #    ERROR  3      5
    #    FATAL  4      6
    LoggerManager.add_logline message, severity == 0 ? Severity::DEBUG : severity + 2, progname, :className => className, :threadId => thread
end
close() click to toggle source

Logger interface: Close coralogix logger. Not implemented

# File lib/coralogix_logger.rb, line 198
def close
    # Not implemented
end
flush() click to toggle source

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

# File lib/coralogix_logger.rb, line 109
def flush
    LoggerManager.flush
end
formatter=(formatter) click to toggle source

Logger interface: Set logger formatter

# File lib/coralogix_logger.rb, line 192
def formatter= formatter
    # Nothing to do here as we always use Coralogix format
end
get_source_file() click to toggle source

Return the file name where the call to the logger was made. This will be used as the class name

# File lib/coralogix_logger.rb, line 203
def get_source_file
    begin
        #        0                          1                               2                   3
        #logger.info(Rails logger) -> Logger.broadcast(Rails Logger)-> add(This class) -> get_source_file(This method)
        if  DebugLogger.debug_mode? && @@print_stack_trace
            DebugLogger.info "Stack trace:"
            DebugLogger.info caller_locations(0..10).join("\n")
        end
        
        file_location_path = caller_locations(@@stack_frame..@@stack_frame)[0].path
        File.basename(file_location_path, File.extname(file_location_path))
    rescue Exception => e  
        DebugLogger.error e.message  
        DebugLogger.error e.backtrace.inspect
        return nil
    end
end
level=(level) click to toggle source

Logger interface:

Set Logger level

@param name - level

# File lib/coralogix_logger.rb, line 29
def level= level
    @level=level
end
log(severity, message, category: @category, className: "", methodName: "", threadId: Thread.current.object_id.to_s) click to toggle source

Log a message.

@param severity - log severity @param message - log message @param category - log category @param className - log class name @param methodName - log method name @param threadId - log thread id

# File lib/coralogix_logger.rb, line 122
def log severity, message, category: @category, className: "", methodName: "", threadId: Thread.current.object_id.to_s
    LoggerManager.add_logline message, severity, category, :className => className, :methodName => methodName, :threadId => threadId
end
progname=(name) click to toggle source

Logger interface: Set logger program name. This will be used as the category.

# File lib/coralogix_logger.rb, line 186
def progname= name
    @category = name
end