Module: IONeLoggerKit

Defined in:
service/log.rb

Overview

IONe built-in logger functions

Constant Summary collapse

DESTINATIONS =

Table with log locations linked to method name or given label

Hash.new('ione.log')

Instance Method Summary collapse

Instance Method Details

#id_genString

ID generator

Returns:

  • (String)

    heximal number



139
140
141
# File 'service/log.rb', line 139

def id_gen
    ($id += 1).to_s(16)
end

#LOG(msg, method = "none", _time = true) ⇒ Boolean

Note:

If method name setted to 'SnapController', message will be logged into snapshot.log

Note:

If method name setted to 'DEBUG', message will be logged into debug.log

Logging the message to the one of three destinations

Parameters:

  • msg (String)

    Message you want to log

  • method (String) (defaults to: "none")

    Method name, which is logging now something

  • _time (Boolean) (defaults to: true)

    Print or not to print log time

Returns:

  • (Boolean)

    true



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'service/log.rb', line 28

def LOG(msg, method = "none", _time = true)
    case method
    when 'DEBUG'
        destination = "#{LOG_ROOT}/debug.log"
    when "SnapController"
        destination = "#{LOG_ROOT}/snapshot.log"
    else
        destination = "#{LOG_ROOT}/ione.log"
    end
    msg = msg.to_s
    msg = "[ #{time()} ] " + msg if _time
    msg += " [ #{method} ]" if method != 'none' && method != "" && method != nil

    File.open(destination, 'a'){ |log| log.write msg + "\n" }
    File.open("#{LOG_ROOT}/suspend.log", 'a'){ |log| log.write msg + "\n" } if method == 'Suspend'

    $log << "#{msg} | #{destination}"
    true
end

#LOG_AUTO(msg, method = caller_locations(1,1)[0].label, _time = true) ⇒ Boolean

Note:

This function gets method name automatically

Note:

If method name setted to 'SnapController', message will be logged into snapshot.log

Note:

If method name setted to 'DEBUG', message will be logged into debug.log

Logging the message to the one of three destinations

Parameters:

  • msg (String)

    Message you want to log

  • method (String) (defaults to: caller_locations(1,1)[0].label)

    Method name, which is logging now something

  • _time (Boolean) (defaults to: true)

    Print or not to print log time

Returns:

  • (Boolean)

    true



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'service/log.rb', line 80

def LOG_AUTO(msg, method = caller_locations(1,1)[0].label, _time = true)
    case method
    when 'DEBUG'
        destination = "#{LOG_ROOT}/debug.log"
    when "SnapController"
        destination = "#{LOG_ROOT}/snapshot.log"
    else
        destination = "#{LOG_ROOT}/ione.log"
    end
    msg = msg.to_s
    msg = "[ #{time()} ] " + msg if _time
    msg += " [ #{method} ]" if method != 'none' && method != "" && method != nil

    File.open(destination, 'a'){ |log| log.write msg + "\n" }
    File.open("#{LOG_ROOT}/suspend.log", 'a'){ |log| log.write msg + "\n" } if method == 'Suspend'

    $log << "#{msg} | #{destination}"
    true
end

#LOG_CALL(id, called, method = caller_locations(1,1)[0].label) ⇒ Boolean

Note:

You may check this log at $IONELOGROOT/sys.log

Puts processes to process list and deletes them out

Parameters:

  • id (Integer)

    Process id, you should generate it using id_gen function

  • called (Boolean)

    If true adds process to list, of false deletes

  • method (String | Object) (defaults to: caller_locations(1,1)[0].label)

    Method name or method object. This function trying to get method-name automatically

Returns:

  • (Boolean)

    true



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'service/log.rb', line 109

def LOG_CALL(id, called, method = caller_locations(1,1)[0].label)
    level, method = 0, method.to_s
    caller_locations.each do | loc |
        loc = loc.label
        if $methods.include? loc then
            level += 1
            next
        end
        $methods.each do | m |
            if loc.include? m then
                level += 1 
                break
            end
        end
    end
    msg = "[ #{time()} ] Method #{called ? $PROC.push("#{method}:#{id}").last : $PROC.delete("#{method}:#{id}")} #{called ? 'called' : 'closed'}\n" if level < 2
    if level > 1  || !called then
        tabs = (0..(level - 3)).to_a.inject("                             "){|t, i| t +  "    "}
        msg = "#{tabs}|-- Method #{method.to_s}:#{id} #{called ? 'called' : 'closed'}\n"
    end

    File.open(LOG_ROOT + '/sys.log', 'a'){ |log| log.write msg }
    true
end

#LOG_COLOR(msg, method = caller_locations(1,1)[0].label.dup, color = 'red', font = 'bold') ⇒ Object Also known as: LOG_ERROR

Logging the message with choosen color and font to the one of two destinations Check out 'colorize' gem for available colors and fonts



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'service/log.rb', line 49

def LOG_COLOR(msg, method = caller_locations(1,1)[0].label.dup, color = 'red', font = 'bold')
    destination = "#{LOG_ROOT}/ione.log"
    destination = "#{LOG_ROOT}/snapshot.log" if method == "SnapController"
    msg = msg.to_s.send(color).send(font)
    msg = "[ #{time()} ] " + msg
    method.slice!('block in '.dup)
    msg += " [ #{method} ]" if method != 'none' && method != "" && method != nil

    File.open(destination, 'a'){ |log| log.write msg + "\n" }
    File.open("#{LOG_ROOT}/suspend.log", 'a'){ |log| log.write msg + "\n" } if method == 'Suspend'

    $log << "#{msg} | #{destination}"
    true
end

#LOG_DEBUG(msg, method = 'DEBUG', _time = true) ⇒ Object

Logging the message directly into LOG_LOCATION/debug.log



65
66
67
68
69
70
71
# File 'service/log.rb', line 65

def LOG_DEBUG(msg, method = 'DEBUG', _time = true)
    destination = "#{LOG_ROOT}/debug.log"
    msg = "[ #{time()} ] #{msg}"
    File.open(destination, 'a'){ |log| log.write msg + "\n" }
    $log << "#{msg} | #{destination}"
    true
end