Class: Common::CloudboxLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/common/cloudbox_logger.rb

Overview

Helper class to log cloudbox project

Direct Known Subclasses

CloudboxLoggerMock

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, path = '/var/log/cloudbox') ⇒ CloudboxLogger

Default constructor.

Parameters:

  • filename (String)

    The filename without extension.

  • path (String) (defaults to: '/var/log/cloudbox')

    Directory where to log.



22
23
24
25
26
27
28
29
30
# File 'lib/common/cloudbox_logger.rb', line 22

def initialize(filename, path='/var/log/cloudbox')
  @path = Pathname.new(path)
  @path.mkpath if !@path.exist?
  # @todo Make the level of logging configurable in a conf file
  level = Logger::DEBUG
  @path = Pathname.new(path + "/" + filename + ".log")
  @filename = filename
  super(@path, "monthly", 100 * 1024 * 1024)
end

Instance Attribute Details

#filenameObject (readonly)

Filename of log file.



16
17
18
# File 'lib/common/cloudbox_logger.rb', line 16

def filename
  @filename
end

#pathObject (readonly)

Path where logging is done.



14
15
16
# File 'lib/common/cloudbox_logger.rb', line 14

def path
  @path
end

Instance Method Details

#begin_execution(params = nil) ⇒ Object

Format the beginning of a command execution.

Parameters:

  • params (Array) (defaults to: nil)

    The ARGV array which store all passed argument.



35
36
37
38
39
40
41
42
43
# File 'lib/common/cloudbox_logger.rb', line 35

def begin_execution(params=nil)
  self.info("############# new execution: #{@filename} #############")
  if !params.nil?
    self.info "Argv:"
    params.each do |arg|
      self.info "  - #{arg}"
    end
  end
end

#begin_main_step(str) ⇒ Object

Format the beginning of a main step.

Parameters:

  • str (String)

    Main step name.



54
55
56
# File 'lib/common/cloudbox_logger.rb', line 54

def begin_main_step(str)
  self.info("#### Main step: #{str}")
end

#end_executionObject

Format the end of a command execution.



47
48
49
# File 'lib/common/cloudbox_logger.rb', line 47

def end_execution
  self.info("############# end of execution #{@filename} #############")
end

#end_main_step(str) ⇒ Object

Format the end of a main step.

Parameters:

  • str (String)

    Main step name.



61
62
63
# File 'lib/common/cloudbox_logger.rb', line 61

def end_main_step(str)
  self.info("#### End of step #{str}")
end

#log_http(http) ⇒ Object

Allows to log an http request.

Parameters:

  • http (Net::HTTP)

    The HTTP request.



68
69
70
71
72
73
# File 'lib/common/cloudbox_logger.rb', line 68

def log_http(http)
  if http.instance_of?(Net::HTTP)
    self.debug("logging http request")
    http.set_debug_output(self)
  end
end

#logging_infoObject

Returns a short string which informs where is located log file.

Returns:

  • a short string which informs where is located log file



77
78
79
# File 'lib/common/cloudbox_logger.rb', line 77

def logging_info
  return "You can see log file at '#{@path}'"
end