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 :-)

4
  • Logging as in the script command common in many shells or writing unusual conditions into /var/log, or what?CommentedJan 23, 2011 at 14:38
  • More like having a log of all the command entered in /var/log. I thought I was clear. Sorry.
    – rahmu
    CommentedJan 23, 2011 at 15:11
  • Then syslog is all you need.
    – imax
    CommentedJan 23, 2011 at 19:19
  • I liked your code. Clean, simple and well documented! (+1) :)
    – Rizo
    CommentedJan 24, 2011 at 14:04

2 Answers 2

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.

    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

    3
    • 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
      CommentedJan 23, 2011 at 23:42
    • It's available on FreeBSD from libc.so and I'm 95% sure that Solaris has syslog() too.
      – imax
      CommentedJan 24, 2011 at 10:51
    • I checked yesterday at work, it is indeed available on Solaris 10. Thanks!
      – rahmu
      CommentedJan 25, 2011 at 7:22

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.