Page MenuHomeFreeBSD

[BHND] Add logging macroses
ClosedPublic

Authored by mizhka on May 6 2016, 5:22 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 26, 8:44 PM
Unknown Object (File)
Fri, Apr 26, 8:44 PM
Unknown Object (File)
Fri, Apr 26, 8:44 PM
Unknown Object (File)
Fri, Apr 26, 7:08 PM
Unknown Object (File)
Fri, Apr 26, 4:51 PM
Unknown Object (File)
Feb 23 2024, 11:57 AM
Unknown Object (File)
Feb 16 2024, 6:23 PM
Unknown Object (File)
Jan 9 2024, 6:43 PM
Subscribers

Details

Summary

There are 5 logging levels:

  • ERROR
  • WARN
  • INFO
  • DEBUG
  • TRACE

There are 2 logging context:

  • with
  • without device

DEBUG and TRACE records are printed only if bootverbose
Logging records are printed with source code line information if acceptable logging level is DEBUG or TRACE

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

mizhka retitled this revision from to [BHND] Add logging macroses.
mizhka updated this object.
mizhka edited the test plan for this revision. (Show Details)
mizhka added reviewers: landon_landonf.org, adrian.
mizhka set the repository for this revision to rS FreeBSD src repository - subversion.
landon_landonf.org edited edge metadata.

Can you do a style(9) rework of this one?

Relevant style(9) guidelines:

  • Put a single tab character between the #define and the macro name.
  • The comment for #endif should match the expression used in the corresponding #if or #ifdef (e.g. #endif /* BHND_LOGGING >= BHND_WARN_LEVEL */)
  • Try to wrap these longer defines to keep lines <= 80 chars
  • Multi-statement macros should be encapsulated in a do { } while(0) loop

Lastly, a non-style(9) request:

Can you rework these to use C string literal concatenation and varargs to allow format strings? e.g., something like:

#define	BHND_LOG_PRINT(level, fmt...)	\
    printf("[BHND " level "] => %s:%d: " fmt,, __func__, __LINE__, ## __VA_ARGS__)
This revision now requires changes to proceed.May 6 2016, 9:10 PM
sys/dev/bhnd/bhnd_debug.h
30 ↗(On Diff #15983)

I'm not sure style(9) actually defines this, but #if-style header guards should be used here (e.g. #ifndef _BHND_DEBUG_H_)

sys/dev/bhnd/bhnd_debug.h
30 ↗(On Diff #15983)

#pragma once isn't standardized.

And the tree is split between _FILE_ and _DIR_FILE_ for the guard name.

mizhka edited edge metadata.
mizhka marked 2 inline comments as done.
  • removed #pragma once
  • added VA_ARGS usage
  • level is C concatened instead printf formatting
landon_landonf.org edited edge metadata.
landon_landonf.org added inline comments.
sys/dev/bhnd/bhnd_debug.h
47 ↗(On Diff #16041)

These still need do {} while(0) loops around multiple statements, and line-breaks at 80 chars.

You can avoid the trailing printf("\n") (and the need for do {} while(0) on some of the defines) if you go with something like:

printf("bhnd: " fmt "\n", ## __VA_ARGS__);
This revision now requires changes to proceed.May 10 2016, 12:22 AM
mizhka edited edge metadata.
  • refactoring
  • fixed style(9) issues
  • described how to use macroses
landon_landonf.org edited edge metadata.

If @adrian is OK with the BHND_LOGLEVEL addition to sys/conf, the rest looks good to me.

This revision is now accepted and ready to land.May 11 2016, 1:31 AM
This revision was automatically updated to reflect the committed changes.