api-logging.texi 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. @c -*-texinfo-*-
  2. @c This file is part of Guile-SSH Reference Manual.
  3. @c Copyright (C) 2014 Artyom V. Poptsov
  4. @c See the file guile-ssh.texi for copying conditions.
  5. @node Logging
  6. @section Logging
  7. @cindex logging
  8. The @code{(ssh log)} module provides procedures to control the libssh logging
  9. facilities.
  10. @deffn {Scheme Procedure} %default-log-printer priority function message userdata
  11. Default callback for printing log messages to the current error port. The
  12. procedure comments out log messages with ``;;; `` to make it easier to
  13. distinguish libssh traces from Guile-SSH messages in REPL mode.
  14. This callback is set by default.
  15. @end deffn
  16. @deffn {Scheme Procedure} %default-libssh-log-printer priority function message userdata
  17. The procedure makes log messages in the same format as the libssh default log
  18. formatter.
  19. @end deffn
  20. @deffn {Scheme Procedure} current-logging-callback
  21. Return the current logging callback. Returns a procedure or @code{#f} if the
  22. callback is not set.
  23. @end deffn
  24. @deffn {Scheme Procedure} set-logging-callback! callback
  25. Change the current logging callback to @var{callback}. The @var{callback}
  26. must be a procedure that takes four arguments: priority of a log message, a
  27. function name, the message and a custom user data.
  28. Throw @code{guile-ssh-error} on an error. Return value is undefined.
  29. Here is an example of a custom callback which indents each log message
  30. according to its priority:
  31. @lisp
  32. (define (pretty-log-printer priority function message userdata)
  33. (do ((i 1 (1+ i)))
  34. ((> i priority))
  35. (display " " (current-error-port)))
  36. (format (current-error-port) "[~a] ~a~%"
  37. (strftime "%Y-%m-%dT%H:%M:%S%z" (localtime (current-time)))
  38. message))
  39. (set-logging-callback! pretty-log-printer)
  40. @end lisp
  41. You can restore the default callback as the follows:
  42. @lisp
  43. (set-logging-callback! %default-log-printer)
  44. @end lisp
  45. @end deffn
  46. @deffn {Scheme Procedure} set-log-userdata! user-data
  47. Set an arbitrary @var{user-data} to be passed to a logging callback.
  48. Throw @code{guile-ssh-error} on an error. Return value is undefined.
  49. By default the user data is set to @code{#f}.
  50. @end deffn
  51. @deffn {Scheme Procedure} get-log-userdata
  52. Get the current user data.
  53. @end deffn
  54. @deffn {Scheme Procedure} format-log priority procedure-name format-string arg ...
  55. Write a formatted message to the libssh log with the given @var{priority}.
  56. Return value is undefined.
  57. Syntax for the @var{format-string} is the same as for @code{format} procedure.
  58. @var{priority} is expected to be a symbol. Acceptable priority levels are:
  59. @table @samp
  60. @item nolog
  61. The message will be printed even if the logging is disabled
  62. @item rare
  63. Rare and noteworthy events
  64. @item protocol
  65. High level protocol information
  66. @item packet
  67. Lower level protocol infomations, packet level
  68. @item functions
  69. Function path
  70. @end table
  71. @end deffn
  72. @deffn {Scheme Procedure} set-log-verbosity! verbosity
  73. Set the global log verbosity to a @var{verbosity}. Throw
  74. @code{guile-ssh-error} on error. Return value is undefined.
  75. @var{verbosity} is expected to be one of the following symbols:
  76. @table @samp
  77. @item nolog
  78. The message will be printed even if the logging is disabled
  79. @item rare
  80. Rare and noteworthy events
  81. @item protocol
  82. High level protocol information
  83. @item packet
  84. Lower level protocol infomations, packet level
  85. @item functions
  86. Function path
  87. @end table
  88. @end deffn
  89. @deffn {Scheme Procedure} get-log-verbosity
  90. Get global log verbosity value.
  91. @end deffn
  92. @c Local Variables:
  93. @c TeX-master: "guile-ssh.texi"
  94. @c End: