Class: VidazingLogger::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/vidazing_logger/logger.rb

Overview

Core Logger class api. Calling build returns a logger with 4 Appenders attached.

Since:

  • 0.2.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_dir = VidazingLogger::LOG_DIR, name:) ⇒ Logger

Creates the ‘logs/’ directory

Parameters:

  • name (String)

    Logger name used in messages

  • log_dir (String) (defaults to: VidazingLogger::LOG_DIR)

    Directory to write logs in

Since:

  • 0.2.0



25
26
27
28
29
30
# File 'lib/vidazing_logger/logger.rb', line 25

def initialize(log_dir = VidazingLogger::LOG_DIR, name:)
  @name = name
  @log_dir = log_dir

  create_log_dir
end

Instance Attribute Details

#log_dirString (readonly)

Where to write logs to

Returns:

  • (String)

    where to write logs to

Since:

  • 0.2.0



14
15
16
# File 'lib/vidazing_logger/logger.rb', line 14

def log_dir
  @log_dir
end

#nameString (readonly)

Use in Logging.logger

Returns:

  • (String)

    name

Since:

  • 0.2.0



19
20
21
# File 'lib/vidazing_logger/logger.rb', line 19

def name
  @name
end

Instance Method Details

#buildLogging.logger

Create a Logger with 4 Appenders. STDERR + ‘logs/error.log’ STDOUT + ‘logs/build.log’

Returns:

Since:

  • 0.2.0



42
43
44
45
46
47
48
49
50
# File 'lib/vidazing_logger/logger.rb', line 42

def build
  LoggerBuilder.build(name: @name) do |builder|
    builder
      .add_stdout
      .add_build_log(log_dir: @log_dir)
      .add_stderr
      .add_error_log(log_dir: @log_dir)
  end
end

#cleanObject

Deletes the log_dir directory

Since:

  • 0.2.0



33
34
35
# File 'lib/vidazing_logger/logger.rb', line 33

def clean
  FileUtils.remove_dir(@log_dir, true)
end