5

I am currently working on implementing my own UNIX shell in C. The basis of the shell is working, you could find the source code here.

Right now my next task is to implement a logging feature for the shell. So here's my question:

What are the UNIX/Linux best practices to do that? The simple way would be to open a file and write to it every time. But I was wondering if there is a function that would take care of that for me, helping me produce ... "cleaner"... code.

Thank you in advance for your help, I'm quite new to programming, but I want to do things right.

PS: If you have any general remarks about the rest of the code, they'd be greatly appreciated :-)

rahmu
  • 19,673
  • 28
  • 87
  • 128

2 Answers2

4

Typically command history is saved to a hidden file in the user's home directory. Other than that, you can log to stderr or syslog.

Shawn J. Goff
  • 45,338
  • 25
  • 134
  • 145
1

Common practice for logging is to use syslog. It's quite simple and does not require much code. If you need something else - look at logging libraries like liblogging or log4c

gelraen
  • 6,667
  • 2
  • 19
  • 16
  • Thank you for your answer. I'm going with syslog, since I don't need anything extravagant and don't want to include any extra dependency. Can you tell me if syslog() is available on other Unices like BSD or Solaris? – rahmu Jan 23 '11 at 23:42
  • It's available on FreeBSD from libc.so and I'm 95% sure that Solaris has syslog() too. – gelraen Jan 24 '11 at 10:51
  • I checked yesterday at work, it is indeed available on Solaris 10. Thanks! – rahmu Jan 25 '11 at 07:22