2

I am trying to log the activities done by my rpm, but unable to find a way to do it. I am looking for some way to do it through the spec file itself. If there are 5 steps my rpm performs, I need a way to log these steps and their results to a log.

I found this after a brief google search - http://www.rpm.org/wiki/RpmLog . It seems like this work is still underway(?).

I was able to create a directory to save the logs following this, but how do I actually write something to a log file in this specially created directory? Some statements I should add to the spec file?

Community
  • 1
  • 1
Ravindra Mijar
  • 1,282
  • 2
  • 9
  • 17

2 Answers2

3

I was able to log the activities of my rpm by a little extension to a link I had mentioned earlier - Create log file when installing rpm. After creating this file, I started echo-ing my log messages to the file I created in the spec file.

echo "this is a log message" >> $RPM_BUILD_ROOT/var/log/mylogfile.txt

So, wherever I wanted to note an important activity done by the rpm, I was adding such statements. I also observed that this file got removed when I uninstalled the rpm.

Community
  • 1
  • 1
Ravindra Mijar
  • 1,282
  • 2
  • 9
  • 17
2

rpm registers all installation information in a /var/lib/rpm database. One can query the database at any time, format to taste (including the http://www.rpm.org/wiki/RpmLog format) and save the output wherever you wish. Use --queryformat (examples in /usr/lib/rpm/rpmpopt*) and sort the installed/queried packages by install time first.

Jeff Johnson
  • 2,310
  • 13
  • 23
  • Jeff, thanks for the answer. However, I had seen this link, and didn't find it useful. I wanted to have my own log statements for the steps taken during my rpm's installation / un-installation. Like you said, it will give information on which rpms got installed etc, right? – Ravindra Mijar Jan 07 '15 at 08:31
  • see "rpm -qa --last" if you want package names by install time. otherwise yum logs actions, and much of the information in the rpm log format can only be supplied by yum: its simply isn't available nor stored by rpm itself. – Jeff Johnson Jan 08 '15 at 19:23