coralogix_logger 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/coralogix_logger.rb +37 -5
- data/lib/manager.rb +11 -2
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 56f317208d45c73dd8f4bd07c14583e68b54f835
         | 
| 4 | 
            +
              data.tar.gz: 19ea7e0e67bed6ea2df97481d962d2897ed9218f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: db23d7041b0f80ba6e92731425263b8a2a0f051a8d33a5103ccafd56dec750b9a155f448e6e258c1aa8b903f49d21d6fe7a4b38685c97687ace55024818bd971
         | 
| 7 | 
            +
              data.tar.gz: b106721209fc8b905c40d6c075fe9e1d3b39818132f416f940103b935e916042e0f7418427bf507cc8f143ce540e6877fd2f09d2555c83e83b80d14ace647e2f
         | 
    
        data/lib/coralogix_logger.rb
    CHANGED
    
    | @@ -8,12 +8,11 @@ module Coralogix | |
| 8 8 | 
             
                class CoralogixLogger
         | 
| 9 9 |  | 
| 10 10 | 
             
                    attr_accessor :use_source_file
         | 
| 11 | 
            -
                    
         | 
| 12 11 | 
             
                    # Set 'new' method to be a private method. 
         | 
| 13 12 | 
             
                    # This way it won't be possible to create a new intance of this class from outside.
         | 
| 14 13 | 
             
                    private_class_method :new
         | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 14 | 
            +
                    @@print_stack_trace = false
         | 
| 15 | 
            +
                    @@stack_frame = 5
         | 
| 17 16 | 
             
                    # Constructor. 
         | 
| 18 17 | 
             
                    #
         | 
| 19 18 | 
             
                    # @param name    -   logger name.
         | 
| @@ -49,6 +48,25 @@ module Coralogix | |
| 49 48 | 
             
                        DebugLogger.debug_mode=value
         | 
| 50 49 | 
             
                    end
         | 
| 51 50 |  | 
| 51 | 
            +
                    # A setter for print stack trace. 
         | 
| 52 | 
            +
                    # Default value is false.
         | 
| 53 | 
            +
                    # When set to true the coralogix logger will print stack trace for each log line.
         | 
| 54 | 
            +
                    #
         | 
| 55 | 
            +
                    # @param value    -   true or false. (Default is false)
         | 
| 56 | 
            +
                    def self.print_stack_trace=(value)
         | 
| 57 | 
            +
                        @@print_stack_trace=value
         | 
| 58 | 
            +
                    end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                    # A setter for stack frame. 
         | 
| 61 | 
            +
                    # Default value is 5.
         | 
| 62 | 
            +
                    # The stack frame to extract from the stack trace
         | 
| 63 | 
            +
                    #
         | 
| 64 | 
            +
                    # @param value [int]   -  (Default is 5)
         | 
| 65 | 
            +
                    def self.stack_frame=(value)
         | 
| 66 | 
            +
                        @@stack_frame=value
         | 
| 67 | 
            +
                    end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
             | 
| 52 70 | 
             
                    # A setter for disable_proxy. 
         | 
| 53 71 | 
             
                    # By default HTTP object will use proxy environment variable if exists. In some cases this migh be an issue
         | 
| 54 72 | 
             
                    # When set to false the HTTP object will ignore any proxy.
         | 
| @@ -81,6 +99,11 @@ module Coralogix | |
| 81 99 | 
             
                        LoggerManager.configure(:privateKey => private_key, :applicationName => app_name, :subsystemName => sub_system) unless LoggerManager.configured
         | 
| 82 100 | 
             
                    end
         | 
| 83 101 |  | 
| 102 | 
            +
                    # Spawn a new worker thread
         | 
| 103 | 
            +
                    def self.reconnect
         | 
| 104 | 
            +
                        LoggerManager.reconnect
         | 
| 105 | 
            +
                    end
         | 
| 106 | 
            +
             | 
| 84 107 | 
             
                    # Log a message. 
         | 
| 85 108 | 
             
                    #
         | 
| 86 109 | 
             
                    # @param severity    -   log severity
         | 
| @@ -111,6 +134,9 @@ module Coralogix | |
| 111 134 | 
             
                    # @param block   -   Can be omitted.  Called to get a message string if +message+ is nil.
         | 
| 112 135 | 
             
                    # @return [boolean] When the given severity is not high enough (for this particular logger), log no message, and return true.
         | 
| 113 136 | 
             
                    def add(severity, message = nil, progname = nil, &block)
         | 
| 137 | 
            +
                        
         | 
| 138 | 
            +
                        thread = ""
         | 
| 139 | 
            +
             | 
| 114 140 | 
             
                        begin
         | 
| 115 141 | 
             
                            severity ||= DEBUG
         | 
| 116 142 | 
             
                            if severity < @level
         | 
| @@ -126,6 +152,7 @@ module Coralogix | |
| 126 152 | 
             
                                end
         | 
| 127 153 | 
             
                            end
         | 
| 128 154 | 
             
                            className = get_source_file if @use_source_file
         | 
| 155 | 
            +
                            thread = Thread.current.object_id.to_s
         | 
| 129 156 | 
             
                        rescue Exception => e  
         | 
| 130 157 | 
             
                            DebugLogger.error e.message  
         | 
| 131 158 | 
             
                            DebugLogger.error e.backtrace.inspect
         | 
| @@ -138,7 +165,7 @@ module Coralogix | |
| 138 165 | 
             
                        #    WARN   2      4
         | 
| 139 166 | 
             
                        #    ERROR  3      5
         | 
| 140 167 | 
             
                        #    FATAL  4      6
         | 
| 141 | 
            -
                        LoggerManager.add_logline message, severity == 0 ? Severity::DEBUG : severity + 2, progname, :className => className
         | 
| 168 | 
            +
                        LoggerManager.add_logline message, severity == 0 ? Severity::DEBUG : severity + 2, progname, :className => className, :threadId => thread
         | 
| 142 169 | 
             
                    end
         | 
| 143 170 |  | 
| 144 171 | 
             
                    # Logger interface: 
         | 
| @@ -170,7 +197,12 @@ module Coralogix | |
| 170 197 | 
             
                        begin
         | 
| 171 198 | 
             
                            #        0                          1                               2                   3
         | 
| 172 199 | 
             
                            #logger.info(Rails logger) -> Logger.broadcast(Rails Logger)-> add(This class) -> get_source_file(This method)
         | 
| 173 | 
            -
                             | 
| 200 | 
            +
                            if  DebugLogger.debug_mode? && @@print_stack_trace
         | 
| 201 | 
            +
                                DebugLogger.info "Stack trace:"
         | 
| 202 | 
            +
                                DebugLogger.info caller_locations(0..10).join("\n")
         | 
| 203 | 
            +
                            end
         | 
| 204 | 
            +
                            
         | 
| 205 | 
            +
                            file_location_path = caller_locations(@@stack_frame..@@stack_frame)[0].path
         | 
| 174 206 | 
             
                            File.basename(file_location_path, File.extname(file_location_path))
         | 
| 175 207 | 
             
                        rescue Exception => e  
         | 
| 176 208 | 
             
                            DebugLogger.error e.message  
         | 
    
        data/lib/manager.rb
    CHANGED
    
    | @@ -13,9 +13,13 @@ module Coralogix | |
| 13 13 | 
             
                    end
         | 
| 14 14 |  | 
| 15 15 | 
             
                    def self.initialize
         | 
| 16 | 
            +
                        @bulk_template = {:privateKey => FAILED_PRIVATE_KEY, :applicationName => NO_APP_NAME, :subsystemName => NO_SUB_SYSTEM}
         | 
| 17 | 
            +
                        self.init
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    def self.init
         | 
| 16 21 | 
             
                        @buffer = []
         | 
| 17 22 | 
             
                        @buffer_size = 0
         | 
| 18 | 
            -
                        @bulk_template = {:privateKey => FAILED_PRIVATE_KEY, :applicationName => NO_APP_NAME, :subsystemName => NO_SUB_SYSTEM}
         | 
| 19 23 | 
             
                        @mutex = Mutex.new
         | 
| 20 24 | 
             
                        @time_delta_last_update = 0
         | 
| 21 25 | 
             
                        @time_delta = 0
         | 
| @@ -67,6 +71,7 @@ module Coralogix | |
| 67 71 | 
             
                    # @return [boolean] return true for success or false for failure.
         | 
| 68 72 | 
             
                    def self.add_logline message, severity, category, **args
         | 
| 69 73 | 
             
                        begin
         | 
| 74 | 
            +
                           
         | 
| 70 75 | 
             
                            @mutex.synchronize do
         | 
| 71 76 | 
             
                                if @buffer_size < MAX_LOG_BUFFER_SIZE
         | 
| 72 77 | 
             
                                    #Validate message
         | 
| @@ -118,7 +123,6 @@ module Coralogix | |
| 118 123 | 
             
                    def self.send_bulk
         | 
| 119 124 | 
             
                        begin
         | 
| 120 125 | 
             
                            self.update_time_delta_interval
         | 
| 121 | 
            -
             | 
| 122 126 | 
             
                            @mutex.synchronize do
         | 
| 123 127 | 
             
                                # Total buffer size
         | 
| 124 128 | 
             
                                size = @buffer.size
         | 
| @@ -169,6 +173,11 @@ module Coralogix | |
| 169 173 | 
             
                        end
         | 
| 170 174 | 
             
                    end
         | 
| 171 175 |  | 
| 176 | 
            +
                    # Spawn a new workter thread.
         | 
| 177 | 
            +
                    def self.reconnect
         | 
| 178 | 
            +
                        self.init
         | 
| 179 | 
            +
                    end
         | 
| 180 | 
            +
             | 
| 172 181 | 
             
                    # Start timer execution.
         | 
| 173 182 | 
             
                    # The timer should send every X seconds logs from the buffer.
         | 
| 174 183 | 
             
                    def self.run
         |