-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_junk.rb
110 lines (80 loc) · 2.04 KB
/
logger_junk.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
72
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
#####################################################
###
## File: logger_junk.rb
## Desc: Many logging funtions
#
##########################
def simple_error error_msg
$stderr.puts
$stderr.puts "\t#{error_msg}"
$stderr.puts
end
#########################
def trace_error error_msg
simple_error error_msg
c = caller
# remove error helpers
c.delete_at 0 while c[0][/trace_warning|internal_error|fatal_error|die/]
$stderr.puts "\tSTACK TRACE:"
c.each {|cc| $stderr.puts "\t\tfrom #{cc}"}
$stderr.puts
end
##############################
def simple_warning warning_msg
simple_error "WARNING: #{warning_msg}"
end
#############################
def trace_warning warning_msg
trace_error "WARNING: #{warning_msg}"
end
############################
def internal_error error_msg
trace_error "INTERNAL SYSTEM ERROR: #{error_msg}"
end
###################################
def fatal_error error_msg
trace_error "FATAL ERROR: #{error_msg}"
exit(-1)
end
alias :die :fatal_error
###################################
#def die error_msg
# trace_error "FATAL ERROR: #{error_msg}"
# exit(-1)
#end
###########################################################
def log_this(thing)
debug_me("Logged: #{thing}")
$stdout.flush
end
##################
def log_event(msg)
log_this "EVENT: #{@label}: #{msg}"
end
###########################
def verbose_out verbose_msg
if $verbose
target = $stdout
$stdout = STDOUT
$stdout.puts verbose_msg
$stdout = target
end
end
###########################
def log_verbose verbose_msg
log_this verbose_msg if $verbose
end ## end of log_verbose verbose_msg
#######################
def log_debug debug_msg
log_this "DEBUG: #{debug_msg}" if $debug
end ## end of debug_out debug_msg
#######################
def log_error error_msg
log_this "\tERROR: #{error_msg}"
simple_error "ERROR: #{error_msg}" if $stdout != STDOUT
end ## end of error_out error_msg
##################
def log_warning warning_msg
log_this "\tWARNING: #{warning_msg}"
simple_warning warning_msg if $stdout != STDOUT
end