You need to look at either /etc/rsyslog.conf or /etc/syslog.conf. If you have a line early on such as:
*.* -/var/log/syslog
Everything, including the stuff from dmesg, should go to that file. To target it better:
kernel.* -/var/log/dmesg
If that fails for some reason, you could periodically (e.g. via cron):
dmesg > /var/log/dmesg
Depending on how big the dmesg buffer is (this is compiled into the kernel, or set via the log_buf_len parameter) and how long your system has been up, that will keep a record of the kernel log since it started.
If you want to write the dmesg output continuously to a file use the -w (--follow) flag.
Best Answer
Write to
/dev/kmsg
(not/proc/kmsg
as suggested by @Nils). Seelinux/kernel/printk/printk.c
devkmsg_writev
for the kernel-side implementation andsystemd/src/journal/journald-kmsg.c
server_forward_kmsg
for an example of usage.