Is there any way to make a log file for maintaining some data in /var/log/ with the help of some library function or system call in c language in linux. And I also want to know the standards that we should follow to write and process log. Thanks
|
|
The standard way to log from a C program is Start by including the header file:
Then early in your program, you should configure syslog by calling
The first argument is the identification or the tag, which is automatically added at the start of each message. Put your program's name here. The second argument is the options you want to use, or Then, each time you want to write a log message, you call
The first argument is the priority. The priority ranges from The second and third arguments are a format and a message, just like printf. Which log file this appears in depends on your syslog settings. With a default setup, it probably goes into You can set up a custom log file by using one of the facilities in the range You use them by changing:
to
or
etc. and adding a corresponding entry to
and restarting the syslog server, e.g.
The Or, if you have
Or, if you are planning on distributing your software to other people, it's probably not a good idea to rely on using In that case, you should use |
|||||||||||
|
|
There are lots of possibilities, what is your plan? Do you just need an option to log from command line? Take a look at
and it will log something like this to your
see also There are also some solutions for different programming languages, so please tell me what do you want to do ;-) |
|||
|
|
You will want to See the man page here. |
|||||
|
|
Filtering by program name is written differently from what is mentioned above, for recent versions of
For more info, look here |
|||
|
|