| Module | ApplicationLog |
| In: |
lib/application_log.rb
|
Mixin module: This module encapsulates the Code Blue application level logging facility.
Note that the web server must be restarted to recognize changes within this file.
Initialize the trace entry for this page request.
# File lib/application_log.rb, line 14
14: def initialize_trace (
15: env
16: )
17: if ('production' != ENV['RAILS_ENV'])
18: uri = env['SERVER_PROTOCOL'].split('/')[0] + "://" + env['HTTP_HOST'] +
19: env['PATH_INFO']
20: trace([TRACE_BEGIN, uri, env['REMOTE_HOST']])
21: end
22: end
Log debugging messages.
This method may be accessed in one of two ways:
1. Using two parameters:
2. Using any number of parameters:
Logging may be augmented using inclusion and exclusion lists:
Both TRACE_EXCLUDE and TRACE_INCLUDE are application constants.
Do not use any Code Blue methods within this method, as this method may be called by any segment of the Code Blue platform, potentially resulting in an infinite loop.
# File lib/application_log.rb, line 57
57: def trace (
58: *arguments
59: )
60: # This method was accessed using (up to) two parameters.
61: if ('array' == arguments[0].get_variable_class)
62: variables = arguments[0]
63: level = arguments[1] if (arguments[1])
64: # This method was accessed using any number of parameters.
65: else
66: variables = arguments
67: end
68:
69:
70: # Do not process this data if the application has trace disabled or if
71: # the application's log level is less than the level specified by this data
72: # (note that if 'level' is empty or non-existent then processing it with
73: # to_i() will return the integer 0).
74: if ((0 == TRACE_LEVEL) || (TRACE_LEVEL < level.to_i))
75: return
76:
77: else
78: # Determine whether or not the data being processed demarcates the start
79: # of a new trace entry; this is the first execution of trace() for this
80: # page request.
81: if (TRACE_BEGIN == variables[0])
82: @@Logger.debug TRACE_BEGIN.parse_data(variables[1], t, variables[2])
83:
84: # Any other trace().
85: else
86: if (caller && caller.first)
87: model_info = caller.first.match(LOG_MODEL_PATTERN)[1].down
88: model = model_info.scan(/#{LOG_MODEL_FILE_PATTERN}/)
89: method = caller.first.match(LOG_METHOD_PATTERN)[1].down
90: name = "#{model}.#{method}"
91: else
92: model_info = "(missing caller data)"
93: name = "(missing model).(missing method)"
94: end
95:
96: # Do not log this data if it is in the exclusion list but not the
97: # inclusion list.
98: if (TRACE_EXCLUDE.index(name) && !(TRACE_INCLUDE.index(name)))
99: return
100:
101: # Only log this data if the inclusion list is empty or if this method
102: # is in the inclusion list.
103: elsif (TRACE_INCLUDE.index(name) || (0 == TRACE_INCLUDE.size))
104: # Generate and store the log entry for this data.
105: #
106: # Note that a tally is kept using s(), storing the number of times
107: # that trace() is executed, on a per method basis.
108: @@Logger.debug "\n[" + s('trace_count:' + name).to_s + '] ' +
109: "#{method}() | " + model_info.gsub(/:/, ' line ')
110:
111: variables.each { |v| @@Logger.debug v }
112: end
113: end
114: end
115: end