2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* log.c
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2013-01-01 23:19:59 -05:00
|
|
|
* Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org>
|
2009-07-01 03:08:33 -04:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2005-03-14 20:51:43 -05:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-12-10 23:55:22 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2007-11-04 17:38:59 -05:00
|
|
|
#include <errno.h>
|
2007-03-05 17:13:33 -05:00
|
|
|
|
|
|
|
/* libalpm */
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "log.h"
|
2007-06-03 23:57:38 -04:00
|
|
|
#include "handle.h"
|
|
|
|
#include "util.h"
|
2007-03-05 17:13:33 -05:00
|
|
|
#include "alpm.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-06-03 23:57:38 -04:00
|
|
|
/** \addtogroup alpm_log Logging Functions
|
|
|
|
* @brief Functions to log using libalpm
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** A printf-like function for logging.
|
2011-06-07 17:06:16 -04:00
|
|
|
* @param handle the context handle
|
2013-01-18 20:42:21 -05:00
|
|
|
* @param prefix caller-specific prefix for the log
|
2007-06-03 23:57:38 -04:00
|
|
|
* @param fmt output format
|
|
|
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
|
|
|
*/
|
2013-02-10 01:47:39 -05:00
|
|
|
int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *prefix,
|
|
|
|
const char *fmt, ...)
|
2007-06-03 23:57:38 -04:00
|
|
|
{
|
2007-06-07 20:55:13 -04:00
|
|
|
int ret;
|
2007-06-03 23:57:38 -04:00
|
|
|
va_list args;
|
|
|
|
|
2011-06-07 17:06:16 -04:00
|
|
|
ASSERT(handle != NULL, return -1);
|
2007-06-03 23:57:38 -04:00
|
|
|
|
2007-11-04 17:38:59 -05:00
|
|
|
/* 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) {
|
2011-07-01 12:01:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_BADPERMS;
|
2007-11-04 17:38:59 -05:00
|
|
|
} else if(errno == ENOENT) {
|
2011-07-01 12:01:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_NOT_A_DIR;
|
2007-11-04 17:38:59 -05:00
|
|
|
} else {
|
2011-07-01 12:01:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_SYSTEM;
|
2007-11-04 17:38:59 -05:00
|
|
|
}
|
2011-06-07 17:06:16 -04:00
|
|
|
return -1;
|
2007-11-04 17:38:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-03 23:57:38 -04:00
|
|
|
va_start(args, fmt);
|
2013-01-18 20:42:21 -05:00
|
|
|
ret = _alpm_logaction(handle, prefix, fmt, args);
|
2007-06-03 23:57:38 -04:00
|
|
|
va_end(args);
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return ret;
|
2007-06-03 23:57:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
2011-06-28 00:41:07 -04:00
|
|
|
void _alpm_log(alpm_handle_t *handle, alpm_loglevel_t flag, const char *fmt, ...)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-06-07 20:55:13 -04:00
|
|
|
va_list args;
|
|
|
|
|
2011-06-18 21:44:49 -04:00
|
|
|
if(handle == NULL || handle->logcb == NULL) {
|
2005-03-14 20:51:43 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-06-07 20:55:13 -04:00
|
|
|
va_start(args, fmt);
|
2011-06-18 21:44:49 -04:00
|
|
|
handle->logcb(flag, fmt, args);
|
2007-06-07 20:55:13 -04:00
|
|
|
va_end(args);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|