return 0;
}
-/** Initialise a file logging destination
+/** Initialise a file logging destination to a FILE*
*
* @param[out] log Destination to initialise.
- * @param[in] file to open handle for.
+ * @param[in] fp pre-existing handle
* @return
* - 0 on success.
* - -1 on failure.
*/
-int fr_log_init_file(fr_log_t *log, char const *file)
+int fr_log_init_fp(fr_log_t *log, FILE *fp)
{
memset(log, 0, sizeof(*log));
log->dst = L_DST_FILES;
-
- if (unlikely((log->handle = fopen(file, "a")) == NULL)) {
- fr_strerror_printf("Failed opening log file \"%s\": %s", file, fr_syserror(errno));
- return -1;
- }
+ log->handle = fp;
setlinebuf(log->handle);
log->fd = fileno(log->handle);
return 0;
}
+/** Initialise a file logging destination
+ *
+ * @param[out] log Destination to initialise.
+ * @param[in] file to open handle for.
+ * @return
+ * - 0 on success.
+ * - -1 on failure.
+ */
+int fr_log_init_file(fr_log_t *log, char const *file)
+{
+ FILE *fp;
+
+ if (unlikely((fp = fopen(file, "a")) == NULL)) {
+ fr_strerror_printf("Failed opening log file \"%s\": %s", file, fr_syserror(errno));
+ return -1;
+ }
+
+ return fr_log_init_fp(log, fp);
+}
+
/** Write complete lines to syslog
*
*/
int fr_log_init_file(fr_log_t *log, char const *file) CC_HINT(nonnull);
+int fr_log_init_fp(fr_log_t *log, FILE *fp) CC_HINT(nonnull);
+
int fr_log_init_syslog(fr_log_t *log) CC_HINT(nonnull);
int fr_log_init_func(fr_log_t *log, cookie_write_function_t write, cookie_close_function_t close, void *uctx)