fmtmsg.h - Linux


fmtmsg.h is a header file in the Linux operating system that provides a set of macros for formatting messages. It allows developers to specify the message format, such as the type of message, its severity level, and the corresponding text. This header file is commonly used in conjunction with the syslog() function to send formatted messages to the system logger.


#include <fmtmsg.h>


  • FMTMSG_NONE: No formatting applied.
  • FMTMSG_INFO: Informational message.
  • FMTMSG_WARNING: Warning message.
  • FMTMSG_ERROR: Error message.
  • FMTMSG_CRITICAL: Critical error message.


The following example shows how to use fmtmsg.h to send an informational message to the system logger:

#include <fmtmsg.h>
#include <syslog.h>

int main() {
    syslog(LOG_INFO | FMTMSG_INFO, "This is an informational message.");
    return 0;

Common Issues

One common issue with using fmtmsg.h is that the message format is not specified explicitly. If the message format is not specified, the default format will be used, which may not be appropriate for all situations. This issue can be avoided by explicitly specifying the message format using one of the FMTMSG_ macros.


fmtmsg.h can be integrated with other Linux commands or tools that use the syslog() function to send messages to the system logger. For example, the following command uses fmtmsg.h to format a message sent to the system logger by the logger command:

logger -p -t myapp -f /dev/stdout FMTMSG_INFO "This is an informational message from myapp."

Related Commands

  • syslog: Sends messages to the system logger.
  • logger: Sends messages directly to the system logger.