Module: RG::Log

Defined in:
lib/rubygoods/log.rb

Class Method Summary collapse

Class Method Details

._queueObject



8
9
10
11
12
13
14
15
16
# File 'lib/rubygoods/log.rb', line 8

def self._queue
  @queue = Queue.new
  Thread.new do
    loop do
      puts @queue.pop
      sleep 0.01
    end
  end
end

._write(msg) ⇒ Object



18
19
20
# File 'lib/rubygoods/log.rb', line 18

def self._write(msg)
  @queue << msg
end

.crash(input, code = 1, ln = true, color = true) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/rubygoods/log.rb', line 145

def self.crash(input, code=1, ln=true, color=true)
  msg = input.to_s

  datencstr = "%d.%m.%Y|%H:%M:%S"
  datestr = if color
    Rainbow("%d").magenta + Rainbow(".").red +
    Rainbow("%m").magenta + Rainbow(".").red +
    Rainbow("%Y").magenta + 
    Rainbow("|").red +
    Rainbow("%H").magenta + Rainbow(":").red +
    Rainbow("%M").magenta + Rainbow(":").red +
    Rainbow("%S").magenta
  else
    datencstr
  end

  date = DateTime.now.gregorian
  dateout = date.strftime datestr
  datencout = date.strftime datencstr
  out = if color
    Rainbow("[").red + 
    dateout + 
    Rainbow("]").red + Rainbow("CRASH> ").magenta + 
    msg
  else
    "[" + datencout + "]CRASH>" + " " + msg
  end

  if ln
    puts  out
  else
    print out
  end
  Kernel.exit(code)
end

.err(input, ln = true, color = true) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/rubygoods/log.rb', line 109

def self.err(input, ln=true, color=true)
  msg = input.to_s

  datencstr = "%d.%m.%Y|%H:%M:%S"
  datestr = if color
    Rainbow("%d").red + Rainbow(".").orange +
    Rainbow("%m").red + Rainbow(".").orange +
    Rainbow("%Y").red + 
    Rainbow("|").orange +
    Rainbow("%H").red + Rainbow(":").orange +
    Rainbow("%M").red + Rainbow(":").orange +
    Rainbow("%S").red
  else
    datencstr
  end

  date = DateTime.now.gregorian
  dateout = date.strftime datestr
  datencout = date.strftime datencstr
  out = if color
    Rainbow("[").orange + 
    dateout + 
    Rainbow("]").orange + Rainbow("ERR> ").red + 
    msg
  else
    "[" + datencout + "]ERR> " + msg
  end

  if ln
    puts  out
  else
    print out
  end
  return "[" + datencout + "]ERR>" + " " + msg
end

.info(input, ln = true, color = true) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rubygoods/log.rb', line 37

def self.info(input, ln=true, color=true)
  msg = input.to_s

  datencstr = "%d.%m.%Y|%H:%M:%S"
  datestr = if color
    Rainbow("%d").green + Rainbow(".").cyan +
    Rainbow("%m").green + Rainbow(".").cyan +
    Rainbow("%Y").green + 
    Rainbow("|").cyan +
    Rainbow("%H").green + Rainbow(":").cyan +
    Rainbow("%M").green + Rainbow(":").cyan +
    Rainbow("%S").green
  else
    datencstr
  end

  date = DateTime.now.gregorian
  dateout = date.strftime datestr
  datencout = date.strftime datencstr
  out = if color
    Rainbow("[").cyan + 
    dateout + 
    Rainbow("]").cyan + Rainbow("-> ").green + 
    msg
  else
    "[" + datencout + "]-> " + msg
  end

  if ln
    puts  out
  else
    print out
  end
  return "[" + datencout + "]->" + " " + msg
end

.warn(input, ln = true, color = true) ⇒ Object



73
74
75
76
77
78
79
80
81
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
# File 'lib/rubygoods/log.rb', line 73

def self.warn(input, ln=true, color=true)
  msg = input.to_s

  datencstr = "%d.%m.%Y|%H:%M:%S"
  datestr = if color
    Rainbow("%d").orange + Rainbow(".").red +
    Rainbow("%m").orange + Rainbow(".").red +
    Rainbow("%Y").orange + 
    Rainbow("|").red +
    Rainbow("%H").orange + Rainbow(":").red +
    Rainbow("%M").orange + Rainbow(":").red +
    Rainbow("%S").orange
  else
    datencstr
  end

  date = DateTime.now.gregorian
  dateout = date.strftime datestr
  datencout = date.strftime datencstr
  out = if color
    Rainbow("[").red + 
    dateout + 
    Rainbow("]").red + Rainbow("WARN> ").orange + 
    msg
  else
    "[" + datencout + "]WARN>" + " " + msg
  end

  if ln
    puts  out
  else
    print out
  end
  return "[" + datencout + "]WARN>" + " " + msg
end

.write(input, ln = true, color = true, code = 1) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubygoods/log.rb', line 22

def self.write(input, ln=true, color=true, code=1)
  case $RG_LOG_LEVEL
  when :info
    self.info  input, ln, color
  when :warn
    self.warn  input, ln, color
  when :err
    self.err   input, ln, color
  when :crash
    self.crash input, code, ln, color 
  else
    self.err "Wrong logger-level!"
  end
end