le0pard/mongodb_logger

View on GitHub
lib/mongodb_logger/logger.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Class Logger has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Logger < RailsLogger
    include ReplicaSetHelper

    DEFAULT_COLLECTION_SIZE = 250.megabytes
    # Looks for configuration files in this order
Severity: Minor
Found in lib/mongodb_logger/logger.rb - About 2 hrs to fix

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

        def add(severity, message = nil, progname = nil, &block)
          $stdout.puts(message) if ENV['HEROKU_RACK'] # log in stdout on Heroku
          if @level && @level <= severity && (message.present? || progname.present?) && Thread.current[:mongodb_logger_mongo_record].present?
            add_log_message(severity, message, progname)
          end
    Severity: Minor
    Found in lib/mongodb_logger/logger.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 initialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize(path = nil, level = DEBUG)
          set_root_and_env
          begin
            path ||= File.join(app_root, "log/#{app_env}.log")
            @level = level
    Severity: Minor
    Found in lib/mongodb_logger/logger.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 read_config_from_file has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def read_config_from_file(config_file)
          if File.file? config_file
            config = ::YAML.load(ERB.new(File.new(config_file).read).result)[app_env]
            config = config['mongodb_logger'] if config && config.has_key?('mongodb_logger')
            return config unless config.blank?
    Severity: Minor
    Found in lib/mongodb_logger/logger.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 record_serializer has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def record_serializer(rec, nice = true)
          [:messages, :params].each do |key|
            if msgs = rec[key]
              msgs.each do |i, j|
                msgs[i] = (true == nice ? nice_serialize_object(j) : j.inspect)
    Severity: Minor
    Found in lib/mongodb_logger/logger.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 ensure_write_to_mongodb has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def ensure_write_to_mongodb
          @insert_block.call
        rescue
          begin
            # try to nice serialize record
    Severity: Minor
    Found in lib/mongodb_logger/logger.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

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

        def configure
          @db_configuration = {
              host: 'localhost',
              port: 27017,
              ssl: false,
    Severity: Minor
    Found in lib/mongodb_logger/logger.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

    There are no issues that match your filters.

    Category
    Status