fluent/fluentd

View on GitHub
lib/fluent/log.rb

Summary

Maintainability
F
5 days
Test Coverage

File log.rb has 587 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'forwardable'
require 'logger'

module Fluent
  class Log
Severity: Major
Found in lib/fluent/log.rb - About 1 day to fix

    Class Log has 47 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Log
        module TTYColor
          RESET   = "\033]R"
          CRE     = "\033[K"
          CLEAR   = "\033c"
    Severity: Minor
    Found in lib/fluent/log.rb - About 6 hrs to fix

      Method dump_stacktrace has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

          def dump_stacktrace(type, backtrace, level)
            return if @level > level
      
            time = Time.now
      
      
      Severity: Minor
      Found in lib/fluent/log.rb - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method event has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

          def event(level, args)
            time = Time.now
            message = @optional_header ? @optional_header.dup : ''
            map = @optional_attrs ? @optional_attrs.dup : {}
            args.each {|a|
      Severity: Minor
      Found in lib/fluent/log.rb - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method initialize has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def initialize(logger, opts={})
            # When ServerEngine changes the logger.level, the Fluentd logger level should also change.
            # So overwrites logger.level= below.
            # However, currently Fluentd doesn't use the ServerEngine's reloading feature,
            # so maybe we don't need this overwriting anymore.
      Severity: Minor
      Found in lib/fluent/log.rb - About 1 hr to fix

        Method event has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def event(level, args)
              time = Time.now
              message = @optional_header ? @optional_header.dup : ''
              map = @optional_attrs ? @optional_attrs.dup : {}
              args.each {|a|
        Severity: Minor
        Found in lib/fluent/log.rb - About 1 hr to fix

          Method dump_stacktrace has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def dump_stacktrace(type, backtrace, level)
                return if @level > level
          
                time = Time.now
          
          
          Severity: Minor
          Found in lib/fluent/log.rb - About 1 hr to fix

            Method ignore_same_log? has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def ignore_same_log?(time, message)
                  cached_log = Thread.current[:last_same_log]
                  if cached_log.nil?
                    Thread.current[:last_same_log] = {message => time}
                    return false
            Severity: Minor
            Found in lib/fluent/log.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method format= has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def format=(fmt)
                  return if @format == fmt
            
                  @time_format = '%Y-%m-%d %H:%M:%S %z'
                  @time_formatter = Strftime.new(@time_format) rescue nil
            Severity: Minor
            Found in lib/fluent/log.rb - About 1 hr to fix

              Method debug has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def debug(*args, &block)
                    return if @level > LEVEL_DEBUG
                    type = log_type(args)
                    return if skipped_type?(type)
                    args << block.call if block
              Severity: Minor
              Found in lib/fluent/log.rb - About 55 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method trace has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def trace(*args, &block)
                    return if @level > LEVEL_TRACE
                    type = log_type(args)
                    return if skipped_type?(type)
                    args << block.call if block
              Severity: Minor
              Found in lib/fluent/log.rb - About 55 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method info has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def info(*args, &block)
                    return if @level > LEVEL_INFO
                    type = log_type(args)
                    return if skipped_type?(type)
                    args << block.call if block
              Severity: Minor
              Found in lib/fluent/log.rb - About 55 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method configure has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def configure(conf)
                    super
              
                    if plugin_id_configured? || conf['@log_level']
                      @log = PluginLogger.new($log.dup) unless @log.is_a?(PluginLogger)
              Severity: Minor
              Found in lib/fluent/log.rb - About 55 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method warn has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def warn(*args, &block)
                    return if @level > LEVEL_WARN
                    type = log_type(args)
                    return if skipped_type?(type)
                    args << block.call if block
              Severity: Minor
              Found in lib/fluent/log.rb - About 55 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method error has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def error(*args, &block)
                    return if @level > LEVEL_ERROR
                    type = log_type(args)
                    return if skipped_type?(type)
                    args << block.call if block
              Severity: Minor
              Found in lib/fluent/log.rb - About 55 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method fatal has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def fatal(*args, &block)
                    return if @level > LEVEL_FATAL
                    type = log_type(args)
                    return if skipped_type?(type)
                    args << block.call if block
              Severity: Minor
              Found in lib/fluent/log.rb - About 55 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method caller_line has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def caller_line(type, time, depth, level)
                    worker_id_part = if type == :default && (@process_type == :worker0 || @process_type == :workers)
                                       @worker_id_part
                                     else
                                       "".freeze
              Severity: Minor
              Found in lib/fluent/log.rb - About 35 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method format= has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def format=(fmt)
                    return if @format == fmt
              
                    @time_format = '%Y-%m-%d %H:%M:%S %z'
                    @time_formatter = Strftime.new(@time_format) rescue nil
              Severity: Minor
              Found in lib/fluent/log.rb - About 25 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Similar blocks of code found in 6 locations. Consider refactoring.
              Open

                  def error(*args, &block)
                    return if @level > LEVEL_ERROR
                    type = log_type(args)
                    return if skipped_type?(type)
                    args << block.call if block
              Severity: Major
              Found in lib/fluent/log.rb and 5 other locations - About 1 hr to fix
              lib/fluent/log.rb on lines 312..320
              lib/fluent/log.rb on lines 334..342
              lib/fluent/log.rb on lines 355..363
              lib/fluent/log.rb on lines 376..384
              lib/fluent/log.rb on lines 418..426

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 47.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 6 locations. Consider refactoring.
              Open

                  def trace(*args, &block)
                    return if @level > LEVEL_TRACE
                    type = log_type(args)
                    return if skipped_type?(type)
                    args << block.call if block
              Severity: Major
              Found in lib/fluent/log.rb and 5 other locations - About 1 hr to fix
              lib/fluent/log.rb on lines 334..342
              lib/fluent/log.rb on lines 355..363
              lib/fluent/log.rb on lines 376..384
              lib/fluent/log.rb on lines 397..405
              lib/fluent/log.rb on lines 418..426

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 47.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 6 locations. Consider refactoring.
              Open

                  def warn(*args, &block)
                    return if @level > LEVEL_WARN
                    type = log_type(args)
                    return if skipped_type?(type)
                    args << block.call if block
              Severity: Major
              Found in lib/fluent/log.rb and 5 other locations - About 1 hr to fix
              lib/fluent/log.rb on lines 312..320
              lib/fluent/log.rb on lines 334..342
              lib/fluent/log.rb on lines 355..363
              lib/fluent/log.rb on lines 397..405
              lib/fluent/log.rb on lines 418..426

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 47.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 6 locations. Consider refactoring.
              Open

                  def fatal(*args, &block)
                    return if @level > LEVEL_FATAL
                    type = log_type(args)
                    return if skipped_type?(type)
                    args << block.call if block
              Severity: Major
              Found in lib/fluent/log.rb and 5 other locations - About 1 hr to fix
              lib/fluent/log.rb on lines 312..320
              lib/fluent/log.rb on lines 334..342
              lib/fluent/log.rb on lines 355..363
              lib/fluent/log.rb on lines 376..384
              lib/fluent/log.rb on lines 397..405

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 47.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 6 locations. Consider refactoring.
              Open

                  def debug(*args, &block)
                    return if @level > LEVEL_DEBUG
                    type = log_type(args)
                    return if skipped_type?(type)
                    args << block.call if block
              Severity: Major
              Found in lib/fluent/log.rb and 5 other locations - About 1 hr to fix
              lib/fluent/log.rb on lines 312..320
              lib/fluent/log.rb on lines 355..363
              lib/fluent/log.rb on lines 376..384
              lib/fluent/log.rb on lines 397..405
              lib/fluent/log.rb on lines 418..426

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 47.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 6 locations. Consider refactoring.
              Open

                  def info(*args, &block)
                    return if @level > LEVEL_INFO
                    type = log_type(args)
                    return if skipped_type?(type)
                    args << block.call if block
              Severity: Major
              Found in lib/fluent/log.rb and 5 other locations - About 1 hr to fix
              lib/fluent/log.rb on lines 312..320
              lib/fluent/log.rb on lines 334..342
              lib/fluent/log.rb on lines 376..384
              lib/fluent/log.rb on lines 397..405
              lib/fluent/log.rb on lines 418..426

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 47.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              There are no issues that match your filters.

              Category
              Status