class ChupaText::DefaultLogger

The default logger for ChupaText. Logger options are retrieved from environment variables.

Here are environment variables to be used:

## `CHUPA_TEXT_LOG_OUTPUT`

It specifies log output.

* `-`: ChupaText outputs to the standard output.
* `+`: ChupaText outputs to the standard error output.
* Others: It is used as file name. ChupaText outputs to the file.

The default is `+` (the standard error).

## `CHUPA_TEXT_LOG_ROTATION_PERIOD`

It specifies log rotation period.

It is ignored when `CHUPA_TEXT_LOG_OUTPUT` is `-` (the standard output) or `+` (the standard error output).

* `daily`: Log file is rotated daily.
* `weekly`: Log file is rotated weekly.
* `monthly`: Log file is rotated monthly.
* Others: Invalid value. It is ignored.

## `CHUPA_TEXT_LOG_N_GENERATIONS`

It specifies how many old log files are kept.

It is ignored when (a) `CHUPA_TEXT_LOG_OUTPUT` is `-` (the

standard output) or `+` (the standard error output) or (b) `CHUPA_TEXT_LOG_RATATION_PERIOD` is valid value.

The default value is `7`.

## `CHUPA_TEXT_LOG_LEVEL`

It specifies log verbosity.

The default value is `info`.

* `unknown`: ChupaText outputs only unknown messages.
* `fatal`: ChupaText outputs `unknown` level messages and
  unhandleable error messages.
* `error`: ChupaText outputs `fatal` level messages and
  handleable error messages.
* `warn`: ChupaText outputs `error` level messages and warning
   level messages.
* `info`: ChupaText outputs `warn` level messages and generic useful
  information messages.
* `debug`: ChupaText outputs all messages.

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/chupa-text/default-logger.rb, line 74
def initialize
  super(output_device, default_shift_age, default_shift_size)
  self.level = default_level
  self.formatter = Formatter.new
end

Private Instance Methods

default_level() click to toggle source
# File lib/chupa-text/default-logger.rb, line 117
def default_level
  level_name = (ENV["CHUPA_TEXT_LOG_LEVEL"] || "info").upcase
  if Logger::Severity.const_defined?(level_name)
    Logger::Severity.const_get(level_name)
  else
    Logger::Severity::INFO
  end
end
default_shift_age() click to toggle source
# File lib/chupa-text/default-logger.rb, line 93
def default_shift_age
  rotation_period = ENV["CHUPA_TEXT_LOG_ROTATION_PERIOD"]
  case rotation_period
  when "daily", "weekly", "monthly"
    return rotation_period
  end

  n_generations = ENV["CHUPA_TEXT_LOG_N_GENERATIONS"] || "7"
  begin
    Integer(n_generations)
  rescue ArgumentError
    nil
  end
end
default_shift_size() click to toggle source
# File lib/chupa-text/default-logger.rb, line 108
def default_shift_size
  max_size = ENV["CHUPA_TEXT_LOG_MAX_SIZE"] || "1MB"
  begin
    SizeParser.parse(max_size)
  rescue SizeParser::InvalidSizeError
    nil
  end
end
output_device() click to toggle source
# File lib/chupa-text/default-logger.rb, line 81
def output_device
  output = ENV["CHUPA_TEXT_LOG_OUTPUT"] || "+"
  case output
  when "-"
    STDOUT
  when "+"
    STDERR
  else
    output
  end
end