[pacman-dev] [PATCH 0/4] [RFC] add caller prefix to alpm_logaction
Implements the following TODO from alpm_logaction in log.c:
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
The log prefix can be added two different ways. To make it easier for frontends, handle->program can be set to the program name (defaults to "USER") which will be used for calls to alpm_logaction. The prefix can be set per call with alpm_plogaction; this is what alpm does. Resulting logfile looks like this:
[2012-12-20 16:29] [PACMAN] Running '/home/ag/devel/pacman/src/pacman/.libs/lt-pacman -Rdd pacman' [2012-12-20 16:29] [ALPM] warning: /etc/pacman.conf saved as /etc/pacman.conf.pacsave [2012-12-20 16:29] [PACMAN] removed pacman (4.0.3-5) [2012-12-20 16:29] [PACMAN] Running '/home/ag/devel/pacman/src/pacman/.libs/lt-pacman --conf /etc/pacman.conf.pacsave -S pacman' [2012-12-20 16:29] [ALPM-SCRIPTLET] >>> Run `pacman-key --init; pacman-key --populate archlinux` [2012-12-20 16:29] [ALPM-SCRIPTLET] >>> to import the data required by pacman for package verification. [2012-12-20 16:29] [ALPM-SCRIPTLET] >>> See: https://www.archlinux.org/news/having-pacman-verify-packages [2012-12-20 16:29] [PACMAN] installed pacman (4.0.3-5)
Andrew Gregory (4): alpm_handle_t: add program name for use in log prefix _alpm_logaction: add support for prefix log.c: add alpm_plogaction pacman: set program name for logging lib/libalpm/add.c | 22 +++++++++++----------- lib/libalpm/alpm.c | 2 ++ lib/libalpm/alpm.h | 4 ++++ lib/libalpm/handle.c | 18 ++++++++++++++++++ lib/libalpm/handle.h | 1 + lib/libalpm/log.c | 50 ++++++++++++++++++++++++++++++++++++++------------ lib/libalpm/remove.c | 6 +++--- lib/libalpm/util.c | 8 ++++++-- lib/libalpm/util.h | 2 +- src/pacman/conf.c | 1 + 10 files changed, 85 insertions(+), 29 deletions(-) -- 1.8.0.2
Signed-off-by: Andrew Gregory
Signed-off-by: Andrew Gregory
Signed-off-by: Andrew Gregory
Signed-off-by: Andrew Gregory
On 21/12/12 08:09, Andrew Gregory wrote:
Implements the following TODO from alpm_logaction in log.c:
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
The log prefix can be added two different ways. To make it easier for frontends, handle->program can be set to the program name (defaults to "USER") which will be used for calls to alpm_logaction. The prefix can be set per call with alpm_plogaction; this is what alpm does.
Resulting logfile looks like this:
[2012-12-20 16:29] [PACMAN] Running '/home/ag/devel/pacman/src/pacman/.libs/lt-pacman -Rdd pacman' [2012-12-20 16:29] [ALPM] warning: /etc/pacman.conf saved as /etc/pacman.conf.pacsave [2012-12-20 16:29] [PACMAN] removed pacman (4.0.3-5) [2012-12-20 16:29] [PACMAN] Running '/home/ag/devel/pacman/src/pacman/.libs/lt-pacman --conf /etc/pacman.conf.pacsave -S pacman' [2012-12-20 16:29] [ALPM-SCRIPTLET] >>> Run `pacman-key --init; pacman-key --populate archlinux` [2012-12-20 16:29] [ALPM-SCRIPTLET] >>> to import the data required by pacman for package verification. [2012-12-20 16:29] [ALPM-SCRIPTLET] >>> See: https://www.archlinux.org/news/having-pacman-verify-packages [2012-12-20 16:29] [PACMAN] installed pacman (4.0.3-5)
That looks fine to me. Not it will break paclog-pkglist, but should be reasonably easy to fix... However, I think there is too much going on here with the setting a package name, creating a new function for use in libalpm, etc. We are never that attached to API around here, so I would just add a new parameter to alpm_logaction and for everything to provide a caller. Anyone else have an opinion on this? Allan
prefix defaults to "UNKOWN" if null or an empty string is provided.
Signed-off-by: Andrew Gregory
Signed-off-by: Andrew Gregory
On 19/01/13 11:42, Andrew Gregory wrote:
Signed-off-by: Andrew Gregory
--- I'm not very familiar with awk, so there is probably a better way to do this.
Dave: can you please comment on this?
contrib/paclog-pkglist.sh.in | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/contrib/paclog-pkglist.sh.in b/contrib/paclog-pkglist.sh.in index 222bbc4..e1bd58e 100644 --- a/contrib/paclog-pkglist.sh.in +++ b/contrib/paclog-pkglist.sh.in @@ -50,25 +50,34 @@ fi
<"$logfile" awk ' { - action = $3 - pkgname = $4 - pkgver = $5 - upgver = $7 + if ($3 ~ /^\[.*\]$/) { + # new style with caller name + action = $4 + pkgname = $5 + pkgver = $6 + upgver = $8 + } else { + action = $3 + pkgname = $4 + pkgver = $5 + upgver = $7 + NF = (NF + 1) + } }
-NF == 5 && action == "installed" { +NF == 6 && action == "installed" { gsub(/[()]/, "", pkgver) pkg[pkgname] = pkgver next }
-NF == 7 && action == "upgraded" { +NF == 8 && action == "upgraded" { sub(/\)/, "", upgver) pkg[pkgname] = upgver next }
-NF == 5 && action == "removed" { +NF == 6 && action == "removed" { pkg[pkgname] = -1 }
On Fri, Jan 18, 2013 at 08:42:22PM -0500, Andrew Gregory wrote:
Signed-off-by: Andrew Gregory
--- I'm not very familiar with awk, so there is probably a better way to do this.
contrib/paclog-pkglist.sh.in | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/contrib/paclog-pkglist.sh.in b/contrib/paclog-pkglist.sh.in index 222bbc4..e1bd58e 100644 --- a/contrib/paclog-pkglist.sh.in +++ b/contrib/paclog-pkglist.sh.in @@ -50,25 +50,34 @@ fi
<"$logfile" awk ' { - action = $3 - pkgname = $4 - pkgver = $5 - upgver = $7 + if ($3 ~ /^\[.*\]$/) { + # new style with caller name + action = $4 + pkgname = $5 + pkgver = $6 + upgver = $8 + } else { + action = $3 + pkgname = $4 + pkgver = $5 + upgver = $7 + NF = (NF + 1)
Would prefer using a different varname over modifying/lying about the value of an internal var. This seems fine otherwise.
+ } }
-NF == 5 && action == "installed" { +NF == 6 && action == "installed" { gsub(/[()]/, "", pkgver) pkg[pkgname] = pkgver next }
-NF == 7 && action == "upgraded" { +NF == 8 && action == "upgraded" { sub(/\)/, "", upgver) pkg[pkgname] = upgver next }
-NF == 5 && action == "removed" { +NF == 6 && action == "removed" { pkg[pkgname] = -1 }
-- 1.8.1.1
On 21/01/13 22:56, Dave Reisner wrote:
On Fri, Jan 18, 2013 at 08:42:22PM -0500, Andrew Gregory wrote:
Signed-off-by: Andrew Gregory
--- I'm not very familiar with awk, so there is probably a better way to do this.
contrib/paclog-pkglist.sh.in | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/contrib/paclog-pkglist.sh.in b/contrib/paclog-pkglist.sh.in index 222bbc4..e1bd58e 100644 --- a/contrib/paclog-pkglist.sh.in +++ b/contrib/paclog-pkglist.sh.in @@ -50,25 +50,34 @@ fi
<"$logfile" awk ' { - action = $3 - pkgname = $4 - pkgver = $5 - upgver = $7 + if ($3 ~ /^\[.*\]$/) { + # new style with caller name + action = $4 + pkgname = $5 + pkgver = $6 + upgver = $8 + } else { + action = $3 + pkgname = $4 + pkgver = $5 + upgver = $7 + NF = (NF + 1)
Would prefer using a different varname over modifying/lying about the value of an internal var.
This seems fine otherwise.
This and patch 1/2 look fine to me with this change. Allan
Signed-off-by: Andrew Gregory
Signed-off-by: Andrew Gregory
On 24/01/13 10:28, Andrew Gregory wrote:
Signed-off-by: Andrew Gregory
--- Let's try that again without the sneaky permission change this time...
Let's also pretend I did not ack the last one... :P
participants (3)
-
Allan McRae
-
Andrew Gregory
-
Dave Reisner