4 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 /** \addtogroup alpm_log Logging Functions
34 * @brief Functions to log using libalpm
38 /** A printf-like function for logging.
39 * @param handle the context handle
40 * @param fmt output format
41 * @return 0 on success, -1 on error (pm_errno is set accordingly)
43 int SYMEXPORT
alpm_logaction(alpm_handle_t
*handle
, const char *fmt
, ...)
48 ASSERT(handle
!= NULL
, return -1);
50 /* check if the logstream is open already, opening it if needed */
51 if(handle
->logstream
== NULL
) {
52 handle
->logstream
= fopen(handle
->logfile
, "a");
53 /* if we couldn't open it, we have an issue */
54 if(handle
->logstream
== NULL
) {
56 handle
->pm_errno
= ALPM_ERR_BADPERMS
;
57 } else if(errno
== ENOENT
) {
58 handle
->pm_errno
= ALPM_ERR_NOT_A_DIR
;
60 handle
->pm_errno
= ALPM_ERR_SYSTEM
;
67 ret
= _alpm_logaction(handle
, fmt
, args
);
70 /* TODO We should add a prefix to log strings depending on who called us.
71 * If logaction was called by the frontend:
72 * USER: <the frontend log>
73 * and if called internally:
74 * ALPM: <the library log>
75 * Moreover, the frontend should be able to choose its prefix
79 * This would allow us to share the log file between several frontends
80 * and know who does what */
86 void _alpm_log(alpm_handle_t
*handle
, alpm_loglevel_t flag
, const char *fmt
, ...)
90 if(handle
== NULL
|| handle
->logcb
== NULL
) {
95 handle
->logcb(flag
, fmt
, args
);
99 /* vim: set ts=2 sw=2 noet: */