#include <pakfire/ctx.h>
#include <pakfire/daemon.h>
#include <pakfire/job.h>
+#include <pakfire/log_file.h>
#include <pakfire/log_buffer.h>
#include <pakfire/log_stream.h>
#include <pakfire/logging.h>
// Logging
struct {
+ // File
+ struct pakfire_log_file* file;
+
// Buffer
struct pakfire_log_buffer* buffer;
static int pakfire_job_finished(struct pakfire_job* job, int status) {
struct pakfire_xfer* xfer = NULL;
char job_id[UUID_STR_LEN];
+ const char* path = NULL;
+ char* logfile = NULL;
int r;
// Format the job ID as string
}
}
+ // Fetch the path of the log file
+ path = pakfire_log_file_path(job->log.file);
+ if (!path) {
+ ERROR(job->ctx, "Log file has no path\n");
+ r = -EINVAL;
+ goto ERROR;
+ }
+
+ // Upload the log file
+ r = pakfire_buildservice_upload(job->service, path, NULL, &logfile);
+ if (r < 0) {
+ ERROR(job->ctx, "Could not upload the log file: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
// Create a new xfer
r = pakfire_job_xfer_create(&xfer, job, "/api/v1/jobs/%s/finished", job_id);
if (r < 0)
if (r < 0)
goto ERROR;
-#if 0
// Logfile
if (logfile) {
r = pakfire_xfer_add_param(xfer, "logfile", "%s", logfile);
if (r)
goto ERROR;
}
-#endif
// Packages
for (char** upload = job->uploads; *upload; upload++) {
int line, const char* fn, const char* format, va_list args) {
struct pakfire_job* job = data;
char* buffer = NULL;
- int r;
// Format the line
const ssize_t length = vasprintf(&buffer, format, args);
break;
}
+ // Send everything but debug messages to the log file
+ if (likely(job->log.file)) {
+ switch (priority) {
+ case LOG_DEBUG:
+ break;
+
+ default:
+ pakfire_log_file_write(job->log.file, buffer, length);
+ break;
+ }
+ }
+
// Pass everything on to syslog
pakfire_log_syslog(NULL, priority, file, line, fn, format, args);
}
// Setup logging
pakfire_ctx_set_log_callback(ctx, pakfire_job_log, job);
+ // Open a new log file
+ r = pakfire_log_file_create(&job->log.file, ctx, PAKFIRE_LOG_FILE_COMPRESS);
+ if (r < 0) {
+ ERROR(ctx, "Could not open log file: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
// Disable the ccache
if (!(job->flags & PAKFIRE_JOB_CCACHE))
build_flags |= PAKFIRE_BUILD_DISABLE_CCACHE;
// Run the build
r = pakfire_build_exec(build, job->pkg, pakfire_job_result, job);
+ // Close the log file
+ r = pakfire_log_file_close(job->log.file);
+ if (r < 0) {
+ ERROR(ctx, "Could not close the log file: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
// Signal that the job has finished
r = pakfire_job_finished(job, r);
if (r < 0)
goto ERROR;
ERROR:
+ if (job->log.file)
+ pakfire_log_file_unref(job->log.file);
if (build)
pakfire_build_unref(build);
if (ctx)