Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a log?

Tags:

c

linux

logging

I am finding a way to implement a log mechanism that several processes write their behaviors (mainly for error and execution sequence of processes) to it by C with Linux?

Just open a file that shared for multi-processes and let processes fprintf() to it? Any smart way to implement an option/mechanism that controls the level of log such as error/detail/high or something like it?

It would be better if you could refer me to a light opensource for this?

Thanks.

like image 587
Joe.Z Avatar asked Jun 13 '26 22:06

Joe.Z


2 Answers

Use syslog, it's the standard (POSIX) logging solution.

like image 172
Fred Foo Avatar answered Jun 16 '26 09:06

Fred Foo


In other languages, log4c is very popular (log4j, log4net). It has a lot of functionality just baked in, and since it is so common, other developers who work on your code will be familiar with it.

like image 24
DOK Avatar answered Jun 16 '26 08:06

DOK