Skip to content

Fix logger level defaulting to TRACE in CMake - #1212

Merged
iphydf merged 3 commits into
TokTok:masterfrom
nurupo:cmake-fix-logger-level
Oct 7, 2018
Merged

iphydf merged 3 commits into
TokTok:masterfrom
nurupo:cmake-fix-logger-level

Conversation

@nurupo

@nurupo nurupo commented Sep 27, 2018 •

Copy link
Copy Markdown
Member

Apparently we defaulted to TRACE logger level for v0.2.4, v0.2.5, v0.2.6 and v0.2.7 releases when using CMake. We default to INFO logger level when using autotools, since autotools doesn't set any and logger.h defaults to INFO if the level is undefined.

There is also this gem which is completely incorrect, logger level won't be set to DEBUG in this case, it will default to whatever logger.h defaults to -- INFO.

AC_MSG_WARN([Invalid logger level: $withval. Using default 'DEBUG'])


This change is Reviewable

@CLAassistant

CLAassistant commented Sep 27, 2018 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented Oct 3, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #1212 into master will decrease coverage by 0.1%.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1212     +/-   ##
========================================
- Coverage    82.9%   82.8%   -0.2%     
========================================
  Files          82      81      -1     
  Lines       14647   14564     -83     
========================================
- Hits        12153   12061     -92     
- Misses       2494    2503      +9
Impacted Files Coverage Δ
toxcore/network.c 79.5% <0%> (-2.7%) ⬇️
toxcore/friend_connection.c 93.6% <0%> (-2.3%) ⬇️
toxcore/onion_client.c 95.3% <0%> (-0.7%) ⬇️
toxcore/net_crypto.c 94.4% <0%> (-0.5%) ⬇️
auto_tests/network_test.c
toxcore/LAN_discovery.c 83.9% <0%> (+0.9%) ⬆️
toxcore/TCP_server.c 77.7% <0%> (+1.7%) ⬆️
toxcore/TCP_client.c 67.1% <0%> (+2.4%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5beb00c...56432a4. Read the comment docs.

@nurupo
nurupo force-pushed the cmake-fix-logger-level branch from 45f6644 to 7680574 Compare October 3, 2018 12:03
@nurupo nurupo changed the title [WIP] Fix logger level defaulting to TRACE in CMake Fix logger level defaulting to TRACE in CMake Oct 4, 2018

@iphydf iphydf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm_strong:

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @nurupo)


CMakeLists.txt, line 105 at r2 (raw file):

    add_definitions(-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_${MIN_LOGGER_LEVEL})
  else()
    message(FATAL_ERROR "Unknown value provided for MIN_LOGGER_LEVEL: \"${MIN_LOGGER_LEVEL}\", must be one of TRACE, DEBUG, INFO, WARNING or ERROR")

If you don't add this, you save 8 lines of cmake code and the (arguably small) maintenance burden of keeping the log levels here in sync with the ones in logger.h, and avoid increasing duplication of this enumeration by 2.

@nurupo

nurupo commented Oct 6, 2018

Copy link
Copy Markdown
Member Author

Right, it will fail to compile if user specifies the wrong logger level, but it's clearer if CMake catches that before compiling and tells what the issue in plain English, rather than deciphering compile error. Also, how often are we planning on modifying the logger level enum anyway for it to be a burden?

$ cmake .. -DMIN_LOGGER_LEVEL=FOO
...
CMake Error at CMakeLists.txt:105 (message):
  Unknown value provided for MIN_LOGGER_LEVEL: "FOO", must be one of TRACE,
  DEBUG, INFO, WARNING or ERROR


-- Configuring incomplete, errors occurred!

vs

$ cmake .. -DMIN_LOGGER_LEVEL=FOO
$ make
Scanning dependencies of target toxcore_static
[  1%] Building C object CMakeFiles/toxcore_static.dir/toxcore/crypto_core.c.o
[  1%] Building C object CMakeFiles/toxcore_static.dir/toxcore/crypto_core_mem.c.o
[  2%] Building C object CMakeFiles/toxcore_static.dir/toxcore/logger.c.o
[  2%] Building C object CMakeFiles/toxcore_static.dir/toxcore/mono_time.c.o
[  3%] Building C object CMakeFiles/toxcore_static.dir/toxcore/network.c.o
./c-toxcore/toxcore/network.c: In function ‘loglogdata’:
<command-line>: error: ‘LOGGER_LEVEL_FOO’ undeclared (first use in this function); did you mean ‘LOGGER_LEVEL_INFO’?
./c-toxcore/toxcore/logger.h:82:22: note: in expansion of macro ‘MIN_LOGGER_LEVEL’
         if (level >= MIN_LOGGER_LEVEL) { \
                      ^~~~~~~~~~~~~~~~
./c-toxcore/toxcore/logger.h:88:34: note: in expansion of macro ‘LOGGER_WRITE’
 #define LOGGER_TRACE(log, ...)   LOGGER_WRITE(log, LOGGER_LEVEL_TRACE  , __VA_ARGS__)
                                  ^~~~~~~~~~~~
./c-toxcore/toxcore/network.c:428:9: note: in expansion of macro ‘LOGGER_TRACE’
         LOGGER_TRACE(log, "[%2u] %s %3u%c %s:%u (%u: %s) | %04x%04x",
         ^~~~~~~~~~~~
<command-line>: note: each undeclared identifier is reported only once for each function it appears in
./c-toxcore/toxcore/logger.h:82:22: note: in expansion of macro ‘MIN_LOGGER_LEVEL’
         if (level >= MIN_LOGGER_LEVEL) { \
                      ^~~~~~~~~~~~~~~~
./c-toxcore/toxcore/logger.h:88:34: note: in expansion of macro ‘LOGGER_WRITE’
 #define LOGGER_TRACE(log, ...)   LOGGER_WRITE(log, LOGGER_LEVEL_TRACE  , __VA_ARGS__)
                                  ^~~~~~~~~~~~
./c-toxcore/toxcore/network.c:428:9: note: in expansion of macro ‘LOGGER_TRACE’
         LOGGER_TRACE(log, "[%2u] %s %3u%c %s:%u (%u: %s) | %04x%04x",
         ^~~~~~~~~~~~
./c-toxcore/toxcore/network.c: In function ‘sendpacket’:
<command-line>: error: ‘LOGGER_LEVEL_FOO’ undeclared (first use in this function); did you mean ‘LOGGER_LEVEL_INFO’?
./c-toxcore/toxcore/logger.h:82:22: note: in expansion of macro ‘MIN_LOGGER_LEVEL’
         if (level >= MIN_LOGGER_LEVEL) { \
                      ^~~~~~~~~~~~~~~~
./c-toxcore/toxcore/logger.h:92:34: note: in expansion of macro ‘LOGGER_WRITE’
 #define LOGGER_ERROR(log, ...)   LOGGER_WRITE(log, LOGGER_LEVEL_ERROR  , __VA_ARGS__)
                                  ^~~~~~~~~~~~
./c-toxcore/toxcore/network.c:477:9: note: in expansion of macro ‘LOGGER_ERROR’
         LOGGER_ERROR(net->log, "attempted to send message of length %u on uninitialised socket", (unsigned)length);
         ^~~~~~~~~~~~
./c-toxcore/toxcore/network.c: In function ‘receivepacket’:
<command-line>: error: ‘LOGGER_LEVEL_FOO’ undeclared (first use in this function); did you mean ‘LOGGER_LEVEL_INFO’?
./c-toxcore/toxcore/logger.h:82:22: note: in expansion of macro ‘MIN_LOGGER_LEVEL’
         if (level >= MIN_LOGGER_LEVEL) { \
                      ^~~~~~~~~~~~~~~~
./c-toxcore/toxcore/logger.h:92:34: note: in expansion of macro ‘LOGGER_WRITE’
 #define LOGGER_ERROR(log, ...)   LOGGER_WRITE(log, LOGGER_LEVEL_ERROR  , __VA_ARGS__)
                                  ^~~~~~~~~~~~
./c-toxcore/toxcore/network.c:558:13: note: in expansion of macro ‘LOGGER_ERROR’
             LOGGER_ERROR(log, "Unexpected error reading from socket: %u, %s", error, strerror);
             ^~~~~~~~~~~~
./c-toxcore/toxcore/network.c: In function ‘networking_poll’:
<command-line>: error: ‘LOGGER_LEVEL_FOO’ undeclared (first use in this function); did you mean ‘LOGGER_LEVEL_INFO’?
./c-toxcore/toxcore/logger.h:82:22: note: in expansion of macro ‘MIN_LOGGER_LEVEL’
         if (level >= MIN_LOGGER_LEVEL) { \
                      ^~~~~~~~~~~~~~~~
./c-toxcore/toxcore/logger.h:91:34: note: in expansion of macro ‘LOGGER_WRITE’
 #define LOGGER_WARNING(log, ...) LOGGER_WRITE(log, LOGGER_LEVEL_WARNING, __VA_ARGS__)
                                  ^~~~~~~~~~~~
./c-toxcore/toxcore/network.c:629:13: note: in expansion of macro ‘LOGGER_WARNING’
             LOGGER_WARNING(net->log, "[%02u] -- Packet has no handler", data[0]);
             ^~~~~~~~~~~~~~
./c-toxcore/toxcore/network.c: In function ‘new_networking_ex’:
<command-line>: error: ‘LOGGER_LEVEL_FOO’ undeclared (first use in this function); did you mean ‘LOGGER_LEVEL_INFO’?
./c-toxcore/toxcore/logger.h:82:22: note: in expansion of macro ‘MIN_LOGGER_LEVEL’
         if (level >= MIN_LOGGER_LEVEL) { \
                      ^~~~~~~~~~~~~~~~
./c-toxcore/toxcore/logger.h:92:34: note: in expansion of macro ‘LOGGER_WRITE’
 #define LOGGER_ERROR(log, ...)   LOGGER_WRITE(log, LOGGER_LEVEL_ERROR  , __VA_ARGS__)
                                  ^~~~~~~~~~~~
./c-toxcore/toxcore/network.c:731:9: note: in expansion of macro ‘LOGGER_ERROR’
         LOGGER_ERROR(log, "invalid address family: %u\n", ip.family.value);
         ^~~~~~~~~~~~
make[2]: *** [CMakeFiles/toxcore_static.dir/build.make:115: CMakeFiles/toxcore_static.dir/toxcore/network.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:909: CMakeFiles/toxcore_static.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
...

@nurupo

nurupo commented Oct 6, 2018

Copy link
Copy Markdown
Member Author

There, added a small script that regexes out logger levels and diffs them.

@nurupo
nurupo force-pushed the cmake-fix-logger-level branch 2 times, most recently from 66fe264 to 67320b8 Compare October 6, 2018 07:51

@iphydf iphydf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm_strong:

Reviewed 6 of 7 files at r2, 3 of 3 files at r3.
Reviewable status: :shipit: complete! 2 of 1 approvals obtained (waiting on @nurupo)

@iphydf iphydf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 2 of 1 approvals obtained

@iphydf

iphydf commented Oct 7, 2018

Copy link
Copy Markdown
Member

@nurupo lgtm.

@iphydf

iphydf commented Oct 7, 2018

Copy link
Copy Markdown
Member

Feel free to merge when ready.

nurupo added 3 commits October 7, 2018 15:15
That way CMake's behavior matches what autotools does -- letting
toxcore/logger.h handle the default case.
@nurupo
nurupo force-pushed the cmake-fix-logger-level branch from 67320b8 to 56432a4 Compare October 7, 2018 19:16
@nurupo

nurupo commented Oct 7, 2018

Copy link
Copy Markdown
Member Author

Is ready, please merge. Just rebased on master. I can squash first two commits if desired. I'd like to keep the 2nd one and 3rd one separate though.

@iphydf
iphydf merged commit 56432a4 into TokTok:master Oct 7, 2018
@robinlinden robinlinden modified the milestones: v0.2.x, v0.2.8 Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants