fplutil
An open source project by
FPL.
|
#include <android/log.h>
#include <stdarg.h>
#include <stdio.h>
Go to the source code of this file.
Typedefs | |
typedef int(* | AndroidLogOutputFunction )(int priority, const char *tag, const char *format, va_list list) |
Functions | |
int | SetAndroidLogWrapperTag (const char *tag) |
void | SetAndroidLogWrapperPriority (int priority) |
int | SetAndroidLogWrapperBufferSize (size_t size) |
void | SetAndroidStdioOutputFunction (AndroidLogOutputFunction func) |
int | AndroidPerrorMsg (const char *msg, int err, char *msgout, size_t outsize) |
Header for libfplutil_print.
libfplutil_print makes it easy to redirect writes to the standard output stream to the Android log.
typedef int(* AndroidLogOutputFunction)(int priority, const char *tag, const char *format, va_list list) |
This is the function signature to use if you would like to intercept printf calls in your code. See SetAndroidLogOutputFunction().
The first two parameters to this function are the log priority and tag, respectively. The remaining ones are the same as for the stdio function vprintf(), and overall the expected semantics for this function are the same as for vprintf(). Please see: http://pubs.opengroup.org/onlinepubs/9699919799/functions/vfprintf.html
priority | Android log priority. |
tag | Tag to display before the logged string. |
format | printf format string. |
list | Additional list of arguments referenced by the printf format string. |
int AndroidPerrorMsg | ( | const char * | msg, |
int | err, | ||
char * | msgout, | ||
size_t | outsize | ||
) |
An internal function that will behave like a snprintf-based version of perror. Used by __wrap_perror() and factored out/exposed to be testable.
Output should look equivalent to what you would expect for:
or
depending on the value of msg.
msg | An optional message to prepend to the error to be printed. May be NULL. |
err | The error value to be printed (via strerror). Error value behavior is the same as for strerror. |
msgout | The output buffer. Must not be NULL. |
outsize | The size of the memory pointed to by the output buffer. msgout will be null-terminated to this length. |
int SetAndroidLogWrapperBufferSize | ( | size_t | size | ) |
Set the buffer size for the wrappers. Default is 256 bytes. Setting this to zero will force unbuffered output, which may have unexpected formatting such as additional newlines as text is immediately sent to the log. Nonzero values will accumulate writes until a newline is encountered or the buffer size is reached.
Buffering is done to allow multiple stdio calls to output on the same line, as per normal behavior of stdio. So, something like this:
would output:
and not five separate log lines, which is the unbuffered behavior.
size | The number of bytes to use for buffering. 0 sets unbuffered mode. Default is 256 bytes. |
void SetAndroidLogWrapperPriority | ( | int | priority | ) |
Set the priority used for log output by the wrappers.
priority | An android log priority, as described in the Android NDK header file android/log.h. Default is ANDROID_LOG_INFO from that file. |
int SetAndroidLogWrapperTag | ( | const char * | tag | ) |
Set the tag used for log output by the wrappers. This can used when filtering the output of "adb logcat" to distinguish the log messages from this application vs. other applications and the rest of the system. Note that this pointer is simply assigned so it must have permanent lifetime.
tag | A null terminated C string to use as the log tag. Default is "main". |
void SetAndroidStdioOutputFunction | ( | AndroidLogOutputFunction | func | ) |
Set the function called when these wrappers perform output. This defaults to __android_log_vprint(), which will cause the output to go to the Android log. You may intercept the output yourself by setting this function. Do not call any stdio output functions or use C++ std::cout/cerr from the function you set here, or infinite recursion will result.
func | A function pointer of typedef AndroidLogOutputFunction to use for stdio output. |