Contents

BNNSGraphCompileOptionsSetMessageLogCallback(_:_:_:)

Specifies a customized callback function that reports compile-time messages.

Declaration

func BNNSGraphCompileOptionsSetMessageLogCallback(_ options: bnns_graph_compile_options_t, _ log_callback: bnns_graph_compile_message_fn_t, _ additional_logging_arguments: UnsafeMutablePointer<bnns_user_message_data_t>?)

Parameters

  • options:

    The compilation options object.

  • log_callback:

    The message-logging callback function.

  • additional_logging_arguments:

    Additional data for the message-logging functions that BNNS passes unaltered to the callback function.

Discussion

If you don’t specify this callback, default callback functions log messages to os_log.

The following code adds a custom graph compile message callback function that prints BNNSGraphMessageLevelInfo level messages to the console:

let options = BNNSGraphCompileOptionsMakeDefault()
defer {
    BNNSGraphCompileOptionsDestroy(options)
}

BNNSGraphCompileOptionsSetMessageLogMask(options, BNNSGraphMessageLevelInfo.rawValue)
BNNSGraphCompileOptionsSetMessageLogCallback(options, messageLogCallback, nil)

func messageLogCallback(msg_level: BNNSGraphMessageLevel,
                        error_msg: UnsafePointer<CChar>,
                        source_location: UnsafePointer<CChar>?,
                        user_message_data_t:UnsafeMutablePointer<user_message_data_t>?) {
    
    print(NSString(cString: error_msg, encoding: NSUTF8StringEncoding) ?? "")
    if let source_location = source_location {
        print(NSString(cString: source_location, encoding: NSUTF8StringEncoding) ?? "")
    }
}

See Also

Specifying a graph’s compile-time message callback