Module: FFI::Libfuse::Adapter::Debug
- Includes:
- Safe
- Included in:
- Filesystem::PassThroughDir, Filesystem::VirtualFS
- Defined in:
- lib/ffi/libfuse/adapter/debug.rb
Overview
Debug callbacks
When included in a filesystem class, and if debugging is enabled via Main#fuse_debug, then installs a wrapper via #FuseCallbacks#fuse_wrappers to log callbacks.
Simple format options can be handled by ##debug_config, or override the Module Functions on an including class for more programmatic control of output.
Constant Summary collapse
- DEFAULT_FORMAT =
Default format
"%<p>s %<n>s %<t>s %<m>s(%<a>s)\n\t=> %<r>s"
Module Functions collapse
-
.debug(fuse_method, args, result, **options) ⇒ Object
Logs the callback.
-
.debug_error(err) ⇒ Object
Log additional information for errors (cause/backtrace etc).
-
.debug_format(fuse_method, args, result, prefix: 'DEBUG', strftime: '%FT%T%:z', format: DEFAULT_FORMAT) ⇒ String
The formatted debug message.
-
.error_message(err) ⇒ String
The detailed error message for err.
Class Method Summary collapse
-
.debug_callback(fuse_method, *args, **options) ⇒ Object
Debug fuse method, args and result of yielding args to the block.
Instance Method Summary collapse
-
#debug? ⇒ Boolean
True if debug is enabled.
-
#debug_config ⇒ Hash<Symbol,String>
abstract
Configure debug output.
Methods included from Safe
Class Method Details
.debug(fuse_method, args, result, **options) ⇒ Object
Logs the callback
87 88 89 |
# File 'lib/ffi/libfuse/adapter/debug.rb', line 87 def debug(fuse_method, args, result, **) warn debug_format(fuse_method, args, result, **) end |
.debug_callback(fuse_method, *args, **options) ⇒ Object
Debug fuse method, args and result of yielding args to the block
74 75 76 77 78 79 80 81 82 |
# File 'lib/ffi/libfuse/adapter/debug.rb', line 74 def debug_callback(fuse_method, *args, **) result = yield(*args) debug(fuse_method, args, result, **) result rescue StandardError, ScriptError => e debug(fuse_method, args, (e), **) debug_error(e) raise end |
.debug_error(err) ⇒ Object
Log additional information for errors (cause/backtrace etc)
103 104 105 106 107 108 109 |
# File 'lib/ffi/libfuse/adapter/debug.rb', line 103 def debug_error(err) if err.is_a?(SystemCallError) warn "Caused by #{(err.cause)}" if err.cause else warn err.backtrace.join("\n\t") end end |
.debug_format(fuse_method, args, result, prefix: 'DEBUG', strftime: '%FT%T%:z', format: DEFAULT_FORMAT) ⇒ String
Returns the formatted debug message.
113 114 115 116 117 118 119 120 121 |
# File 'lib/ffi/libfuse/adapter/debug.rb', line 113 def debug_format(fuse_method, args, result, prefix: 'DEBUG', strftime: '%FT%T%:z', format: DEFAULT_FORMAT) format(format, p: prefix, n: Time.now.strftime(strftime), t: Thread.current.name || Thread.current, m: fuse_method, a: args.map(&:to_s).join(','), r: result) end |
.error_message(err) ⇒ String
Returns the detailed error message for err.
93 94 95 96 97 98 99 |
# File 'lib/ffi/libfuse/adapter/debug.rb', line 93 def (err) if err.is_a?(SystemCallError) "#{err.class.name}(errno=#{err.errno}): #{err.}" else "#{err.class.name}: #{err.}" end end |
Instance Method Details
#debug? ⇒ Boolean
Returns true if debug is enabled.
25 26 27 |
# File 'lib/ffi/libfuse/adapter/debug.rb', line 25 def debug? @debug end |
#debug_config ⇒ Hash<Symbol,String>
Configure debug output
32 33 34 |
# File 'lib/ffi/libfuse/adapter/debug.rb', line 32 def debug_config {} end |