Skip to content

provide logging macro signature that accepts std::string #570

Closed

Description

@wjwwood

Feature request

Feature description

I'd like to have std::string (and possibly other common string containter) friendly logging macros.

For example, right now you must make logging calls like this:

std::string msg = "some error message from elsewhere";
RCLCPP_INFO(logger, ("some suffix: " + msg).c_str());

But I'd like to write:

std::string msg = "some error message from elsewhere";
RCLCPP_INFO(logger, "some suffix: " + msg);
// or just...
RCLCPP_INFO(logger, msg);

Implementation considerations

I think a helper function could make the macros simple, something like:

#include <string>

using namespace std::string_literals;

const char *
get_c_string(const char * string_in)
{
  return string_in;
}

const char *
get_c_string(const std::string & string_in)
{
  return string_in.c_str();
}

#define LOG_INFO(msg) printf("%s\n", get_c_string(msg));

int main()
{
  LOG_INFO("plain c string");
  std::string a_str("a local std::string");
  LOG_INFO(a_str);
  LOG_INFO(std::string("a temporary std::string"));
  LOG_INFO("a std::string literal"s);
}

Activity

  1. added
    enhancement
    help wanted
    good first issue
    on Oct 16, 2018
  2. fmrico commented on Oct 21, 2018

    @fmrico
    Contributor

    Hi all,

    I think I have a possible solution, in 9a99a84

    Best
    Francisco

  3. wjwwood commented on Oct 22, 2018

    @wjwwood
    MemberAuthor

    Thanks @fmrico, is that part of a pull request? If not could open one to that effect?

  4. wjwwood commented on Oct 22, 2018

    @wjwwood
    MemberAuthor

    Disregard my previous comment, I found the pull request (#573) :D

  5. added
    in review
    on Oct 24, 2018
  6. added a commit that references this issue on Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issuehelp wantedin review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions