lib/oslg/oslog.rb in oslg-0.2.5 vs lib/oslg/oslog.rb in oslg-0.2.6
- old
+ new
@@ -1,8 +1,8 @@
# BSD 3-Clause License
#
-# Copyright (c) 2022, Denis Bourgeois
+# Copyright (c) 2022-2023, Denis Bourgeois
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
@@ -125,10 +125,11 @@
# @param level [Integer] DEBUG, INFO, WARN, ERROR or FATAL
#
# @return [String] "DEBUG", "INFO", "WARN", "ERROR" or "FATAL"
def tag(level)
return @@tag[level] if level >= DEBUG && level <= FATAL
+
""
end
##
# Return preset OSlg message linked to status.
@@ -136,10 +137,11 @@
# @param status [Integer] DEBUG, INFO, WARN, ERROR or FATAL
#
# @return [String] preset OSlg message
def msg(status)
return @@msg[status] if status >= DEBUG && status <= FATAL
+
""
end
##
# Set level.
@@ -161,10 +163,11 @@
def log(level = DEBUG, message = "")
if level >= DEBUG && level <= FATAL && level >= @@level
@@logs << {level: level, message: message}
@@status = level if level > @@status
end
+
@@status
end
##
# Log template 'invalid object' message and return user-set object.
@@ -192,14 +195,15 @@
return res if id.empty?
mth = mth[0...60] + " ..." if mth.length > 60
return res if mth.empty?
- msg = "Invalid '#{id}' "
+ msg = "Invalid '#{id}' "
msg += "arg ##{ord} " if ord > 0
msg += "(#{mth})"
log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
+
res
end
##
# Log template 'instance/class mismatch' message and return user-set object.
@@ -230,10 +234,11 @@
mth = mth[0...60] + " ..." if mth.length > 60
return res if mth.empty?
msg = "'#{id}' #{obj.class}? expecting #{cl} (#{mth})"
log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
+
res
end
##
# Log template 'missing hash key' message and return user-set object.
@@ -262,12 +267,13 @@
return res if id.empty?
mth = mth[0...60] + " ..." if mth.length > 60
return res if mth.empty?
- msg = "Missing '#{key}' key in '#{id}' Hash (#{mth})"
+ msg = "Missing '#{key}' key in '#{id}' Hash (#{mth})"
log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
+
res
end
##
# Log template 'empty (uninitialized)' message and return user-set object.
@@ -292,12 +298,13 @@
return res if id.empty?
mth = mth[0...60] + " ..." if mth.length > 60
return res if mth.empty?
- msg = "Empty '#{id}' (#{mth})"
+ msg = "Empty '#{id}' (#{mth})"
log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
+
res
end
##
# Log template 'near zero' message and return user-set object.
@@ -323,12 +330,13 @@
return res if id.empty?
mth = mth[0...60] + " ..." if mth.length > 60
return res if mth.empty?
- msg = "Zero '#{id}' (#{mth})"
+ msg = "Zero '#{id}' (#{mth})"
log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
+
res
end
##
# Log template 'negative' message and return user-set object.
@@ -353,22 +361,24 @@
id = id[0...60] + " ..." if id.length > 60
return res if id.empty?
mth = mth[0...60] + " ..." if mth.length > 60
return res if mth.empty?
-
- msg = "Negative '#{id}' (#{mth})"
+
+ msg = "Negative '#{id}' (#{mth})"
log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
+
res
end
##
# Reset log status and entries.
#
# @return [Integer] current level
def clean!
@@status = 0
@@logs = []
+
@@level
end
##
# Callback when other modules extend OSlg