Sha256: 7e5e04577099952f5344d4fe1b9f45b46efa2683040b5137e12f6479c2eb68df

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Libvirt
  module Loggable
    # caller[0].match(/`(.*)'/)[1]

    module ClassMethods
      def dbg(prog_name = nil, &block)
        return if Libvirt.logger.nil?

        if prog_name.nil?
          meth = caller[0].match(/`(.*)'/)[1]
          meth = "<#{meth}>" if meth.include?(' ')
          prog_name = "#{name}.#{meth}"
        end
        Libvirt.logger.debug(prog_name, &block)
      end

      def err(prog_name = nil, &block)
        return if Libvirt.logger.nil?

        if prog_name.nil?
          meth = caller[0].match(/`(.*)'/)[1]
          meth = "<#{meth}>" if meth.include?(' ')
          prog_name = "#{name}.#{meth}"
        end
        Libvirt.logger.error(prog_name, &block)
      end
    end

    def self.included(base)
      base.extend ClassMethods
      super
    end

    def dbg(prog_name = nil, &block)
      return if Libvirt.logger.nil?

      if prog_name.nil?
        meth = caller[0].match(/`(.*)'/)[1]
        meth = "<#{meth}>" if meth.include?(' ')
        prog_name = "#{self.class.name}##{meth}"
      end
      Libvirt.logger.debug(prog_name, &block)
    end

    def err(prog_name = nil, &block)
      return if Libvirt.logger.nil?

      if prog_name.nil?
        meth = caller[0].match(/`(.*)'/)[1]
        meth = "<#{meth}>" if meth.include?(' ')
        prog_name = "#{self.class.name}##{meth}"
      end
      Libvirt.logger.error(prog_name, &block)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
libvirt_ffi-0.8.1 lib/libvirt/loggable.rb