4 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 #include <sys/types.h>
38 /** \addtogroup alpm_log Logging Functions
39 * @brief Functions to log using libalpm
43 /** A printf-like function for logging.
44 * @param fmt output format
45 * @return 0 on success, -1 on error (pm_errno is set accordingly)
47 int SYMEXPORT
alpm_logaction(char *fmt
, ...)
55 ASSERT(handle
!= NULL
, RET_ERR(PM_ERR_HANDLE_NULL
, -1));
57 /* check if the logstream is open already, opening it if needed */
58 if(handle
->logstream
== NULL
) {
59 handle
->logstream
= fopen(handle
->logfile
, "a");
60 /* if we couldn't open it, we have an issue */
61 if(handle
->logstream
== NULL
) {
63 pm_errno
= PM_ERR_BADPERMS
;
64 } else if(errno
== ENOENT
) {
65 pm_errno
= PM_ERR_NOT_A_DIR
;
67 pm_errno
= PM_ERR_SYSTEM
;
74 ret
= _alpm_logaction(handle
->usesyslog
, handle
->logstream
, fmt
, args
);
77 /* TODO We should add a prefix to log strings depending on who called us.
78 * If logaction was called by the frontend:
79 * USER: <the frontend log>
80 * and if called internally:
81 * ALPM: <the library log>
82 * Moreover, the frontend should be able to choose its prefix
86 * This would allow us to share the log file between several frontends
87 * and know who does what */
93 void _alpm_log(pmloglevel_t flag
, char *fmt
, ...)
96 alpm_cb_log logcb
= alpm_option_get_logcb();
103 logcb(flag
, fmt
, args
);
107 /* vim: set ts=2 sw=2 noet: */