#[no_mangle]
pub unsafe extern "C" fn pactffi_logger_attach_sink(
    sink_specifier: *const c_char,
    level_filter: LevelFilter
) -> c_int
Expand description

Attach an additional sink to the thread-local logger.

This logger does nothing until pactffi_logger_apply has been called.

Types of sinks can be specified:

  • stdout (pactffi_logger_attach_sink("stdout", LevelFilter_Info))
  • stderr (pactffi_logger_attach_sink("stderr", LevelFilter_Debug))
  • file w/ file path (pactffi_logger_attach_sink("file /some/file/path", LevelFilter_Trace))
  • buffer (pactffi_logger_attach_sink("buffer", LevelFilter_Debug))

Usage

int result = pactffi_logger_attach_sink("file /some/file/path", LogLevel_Filter);

Error Handling

The return error codes are as follows:

  • -1: Can’t set logger (applying the logger failed, perhaps because one is applied already).
  • -2: No logger has been initialized (call pactffi_logger_init before any other log function).
  • -3: The sink specifier was not UTF-8 encoded.
  • -4: The sink type specified is not a known type (known types: “stdout”, “stderr”, or “file /some/path”).
  • -5: No file path was specified in a file-type sink specification.
  • -6: Opening a sink to the specified file path failed (check permissions).

Safety

This function checks the validity of the passed-in sink specifier, and errors out if the specifier isn’t valid UTF-8. Passing in an invalid or NULL pointer will result in undefined behaviour.