Skip to content

Conflicting definitions of LOG_ERR in logging/log.h and posix/syslog.h #93321

@besmarsh

Description

@besmarsh

Describe the bug

LOG_ERR is a constant defined by POSIX and defined in include/zephyr/posix/syslog.h. Zephyr's logging subsystem also defines LOG_ERR as a macro to write an error level message to the log.

These definitions are conflicting. This causes a compile-time warning. This also causes a compile-time error if the version of LOG_ERR that is included first is used by an application. The order of includes ends up determining whether an application using LOG_ERR and including both logging/log.h and syslog.h (directly or indirectly) will compile.

Applications using the POSIX API that would otherwise be compatible with Zephyr can fail to compile due to this issue.

I noticed in the XSI system logging test this issue being worked around by undefining LOG_ERR and manually defining _LOG_ERR. This isn't really a generally acceptable solution when compiling POSIX-based code for Zephyr.

Since LOG_ERR is specified by POSIX, the Zephyr logging macro would probably need to be renamed to fix this issue.

Regression

  • This is a regression.

Steps to reproduce

  1. Add the following to samples/hello_world/prj.conf:
CONFIG_POSIX_API=y
CONFIG_LOG=y
CONFIG_XSI_SYSTEM_LOGGING=y
  1. Add the following to the includes section of samples/hello_world/src/main.c:
#include <syslog.h>
#include <zephyr/logging/log.h>
  1. Add the following to samples/hello_world/src/main.c:main():
syslog(LOG_ERR, "Error");
  1. west build -b <board> samples/hello_world

Relevant log output

In file included from <...>/zephyrproject/zephyr/samples/hello_world/src/main.c:10:
<...>/zephyrproject/zephyr/include/zephyr/logging/log.h:48: warning: "LOG_ERR" redefined
   48 | #define LOG_ERR(...)    Z_LOG(LOG_LEVEL_ERR, __VA_ARGS__)
      |
In file included from <...>/zephyrproject/zephyr/samples/hello_world/src/main.c:9:
<...>/zephyrproject/zephyr/include/zephyr/posix/syslog.h:42: note: this is the location of the previous definition
   42 | #define LOG_ERR     3
      |
<...>/zephyrproject/zephyr/samples/hello_world/src/main.c: In function 'main':
<...>/zephyrproject/zephyr/samples/hello_world/src/main.c:15:16: error: 'LOG_ERR' undeclared (first use in this function)
   15 |         syslog(LOG_ERR, "Error");
      |                ^~~~~~~

Impact

Functional Limitation – Some features not working as expected, but system usable.

Environment

  • OS: Windows
  • Toolchain: Zephyr SDK (arm-zephyr-eabi)
  • Commit SHA: 31ef45e

Additional Context

No response

Metadata

Metadata

Assignees

Labels

area: LoggingbugThe issue is a bug, or the PR is fixing a bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions