1

I have a kernel module that uses printk() for debugging. printk() logs to /var/log/messages. /var/log/messages contains information of other modules too. I am trying to implement dynamic tracing for my module. My plan is to use ioctl calls to set different logging/tracing level and then, log the information from the module to a different path (my_module.log).

I am not getting information on how to write logs from kernel space (inside kernel module) to a specific file? I have checked for rsyslog but couldn't find any information if this can be used inside a kernel module.

I see a similar question, but it is not helping. Linux kernel : logging to a specific file

Could you suggest any leads?

vek
  • 11
  • 2
  • printk does not write to a file. It writes to a buffer. klogd reads the buffer and sends it to syslog. Your syslog configuration decides where kernel messages go. – stark Aug 02 '21 at 11:06
  • Yes, thanks for the correction @stark. I am looking for a way to log from a specific kernel modules to a different file (like /var/log/my_module.log). Can you suggest some leads? In syslog, I don't find anything related that allows logs from specific module to a different file. – vek Aug 02 '21 at 11:32
  • 1
    Most kernel prints are prefixed with the function name. syslog supports filtering. – stark Aug 02 '21 at 11:37

0 Answers0