You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When deploying to a J2EE server file names can get a little long when using %F in the formatter.
For example, this log message:
[ALWAYS][2016-01-12T10:27:06][/work/ETS/glassfish/glassfish4/glassfish/domains/domain1/applications/ets_tooling/WEB-INF/config/initializers/02_log_initializer.rb][59] Logging started.
Would look better as:
[ALWAYS][2016-01-12T12:57:07][/config/initializers/02_log_initializer.rb][108] Logging started!
opening the logging module and redefining the logging event as follows solves the issue for me (but this will only work on JRuby).
v = $VERBOSE
$VERBOSE = nil
module Logging
#opening and redefining LogEvent found in log_event.rb
LogEvent = Struct.new( :logger, :level, :data, :time, :file, :line, :method ) {
# Regular expression used to parse out caller information
#
# * $1 == filename
# * $2 == line number
# * $3 == method name (might be nil)
CALLER_RGXP = %r/([-\.\/\(\)\w]+):(\d+)(?::in `(\w+)')?/o
#CALLER_INDEX = 2
CALLER_INDEX = ((defined? JRUBY_VERSION and JRUBY_VERSION > '1.6') or (defined? RUBY_ENGINE and RUBY_ENGINE[%r/^rbx/i])) ? 1 : 2
def initialize( logger, level, data, caller_tracing )
f = l = m = ''
if caller_tracing
stack = Kernel.caller[CALLER_INDEX]
return if stack.nil?
match = CALLER_RGXP.match(stack)
f = match[1]
separator = java.io.File.separator
last = Rails.root.to_s.split(separator).last
f = f.split(last).last
l = Integer(match[2])
m = match[3] unless match[3].nil?
end
super(logger, level, data, Time.now, f, l, m)
end
}
end # module Logging
#put warnings back to whatever they were.
$VERBOSE = v
The text was updated successfully, but these errors were encountered:
I had the same request and solved it by monkey patching the LogEvent class that returns the filename:
module Logging
# patch LogEvent class to only return file path relative to rails root instead of full path if set
module LogEventExtensions
def file
self[:file].blank? ? self[:file] : Pathname.new(self[:file]).relative_path_from(::Rails.root).to_s
end
end
class LogEvent
prepend LogEventExtensions
end
end
When deploying to a J2EE server file names can get a little long when using %F in the formatter.
For example, this log message:
[ALWAYS][2016-01-12T10:27:06][/work/ETS/glassfish/glassfish4/glassfish/domains/domain1/applications/ets_tooling/WEB-INF/config/initializers/02_log_initializer.rb][59] Logging started.
Would look better as:
[ALWAYS][2016-01-12T12:57:07][/config/initializers/02_log_initializer.rb][108] Logging started!
opening the logging module and redefining the logging event as follows solves the issue for me (but this will only work on JRuby).
The text was updated successfully, but these errors were encountered: