/** A printf-like function for logging. * @param handle the context handle * @param prefix caller-specific prefix for the log * @param fmt output format * @return 0 on success, -1 on error (pm_errno is set accordingly) */ int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *prefix, const char *fmt, ...) { int ret; va_list args; ASSERT(handle != NULL, return -1); /* check if the logstream is open already, opening it if needed */ if(handle->logstream == NULL) { handle->logstream = fopen(handle->logfile, "a"); /* if we couldn't open it, we have an issue */ if(handle->logstream == NULL) { if(errno == EACCES) { handle->pm_errno = ALPM_ERR_BADPERMS; } else if(errno == ENOENT) { handle->pm_errno = ALPM_ERR_NOT_A_DIR; } else { handle->pm_errno = ALPM_ERR_SYSTEM; } return -1; } } va_start(args, fmt); ret = _alpm_logaction(handle, prefix, fmt, args); va_end(args); return ret; }
/** A printf-like function for logging. * @param handle the context handle * @param fmt output format * @return 0 on success, -1 on error (pm_errno is set accordingly) */ int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *fmt, ...) { int ret; va_list args; ASSERT(handle != NULL, return -1); /* check if the logstream is open already, opening it if needed */ if(handle->logstream == NULL) { handle->logstream = fopen(handle->logfile, "a"); /* if we couldn't open it, we have an issue */ if(handle->logstream == NULL) { if(errno == EACCES) { handle->pm_errno = ALPM_ERR_BADPERMS; } else if(errno == ENOENT) { handle->pm_errno = ALPM_ERR_NOT_A_DIR; } else { handle->pm_errno = ALPM_ERR_SYSTEM; } return -1; } } va_start(args, fmt); ret = _alpm_logaction(handle, fmt, args); va_end(args); /* TODO We should add a prefix to log strings depending on who called us. * If logaction was called by the frontend: * USER: <the frontend log> * and if called internally: * ALPM: <the library log> * Moreover, the frontend should be able to choose its prefix * (USER by default?): * pacman: "PACMAN" * kpacman: "KPACMAN" * This would allow us to share the log file between several frontends * and know who does what */ return ret; }