Class: FLogger::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/flogger/log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|@config| ... } ⇒ Log

Returns a new instance of Log.

Yields:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/flogger/log.rb', line 8

def initialize
    @config = OpenStruct.new(
        # set default log paths
        :debug => 'logs/debug.txt',
        :error => 'logs/error.txt',
        :notice => 'logs/notice.txt',
        :warning => 'logs/warning.txt',
        :application => 'logs/application.txt',
        
        # set default log output settings
        :default => :application,
        :format => "[#{Time.now.asctime}] %s"
    )
    
    # yield to custom configuration
    yield @config if block_given?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/flogger/log.rb', line 6

def config
  @config
end

Instance Method Details

#clear(type = @config.default) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/flogger/log.rb', line 82

def clear(type = @config.default)
    case type
        when :all
            clear_log_contents @config.debug
            clear_log_contents @config.error
            clear_log_contents @config.notice
            clear_log_contents @config.warning
            clear_log_contents @config.application
        
        when :debug
            clear_log_contents @config.debug
        
        when :error
            clear_log_contents @config.error
        
        when :notice
            clear_log_contents @config.notice
        
        when :warning
            clear_log_contents @config.warning
        
        when :application
            clear_log_contents @config.application
            
        else
            $stderr.puts "Log type not supported."
    end
end

#configure(&block) ⇒ Object

deprecated: use Log#new configure log file locations



28
29
30
# File 'lib/flogger/log.rb', line 28

def configure(&block)
    FLogger.output_deprecation('0.2.0', 'Log#configure')
end

#debug(message) ⇒ Object

deprecated: use Log#puts outputs to debug log



34
35
36
# File 'lib/flogger/log.rb', line 34

def debug(message)
    FLogger.output_deprecation('0.2.0', 'Log#debug')
end

#error(message) ⇒ Object

deprecated: use Log#puts outputs to error log



40
41
42
# File 'lib/flogger/log.rb', line 40

def error(message)
    FLogger.output_deprecation('0.2.0', 'Log#error')
end

#notice(message) ⇒ Object

deprecated: use Log#puts outputs to notice log



52
53
54
# File 'lib/flogger/log.rb', line 52

def notice(message)
    FLogger.output_deprecation('0.2.0', 'Log#notice')
end

#puts(type = @config.default, message) ⇒ Object

outputs to log file default: logs/application.txt



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/flogger/log.rb', line 58

def puts(type = @config.default, message)
    return if message.empty?
    
    case type
        when :debug
            output_to_log(@config.debug, message)
        
        when :error
            output_to_log(@config.error, message)
        
        when :notice
            output_to_log(@config.notice, message)
        
        when :warning
            output_to_log(@config.warning, message)
        
        when :application
            output_to_log(@config.application, message)
        
        else
            $stderr.puts "Log type not supported."
    end
end

#warning(message) ⇒ Object

deprecated: use Log#puts outputs to warning log



46
47
48
# File 'lib/flogger/log.rb', line 46

def warning(message)
    FLogger.output_deprecation('0.2.0', 'Log#warning')
end