From e523a5d466cbe6d75a66881e74f2f3d359abcdc0 Mon Sep 17 00:00:00 2001 From: Simon Rasmussen Date: Wed, 8 Feb 2017 10:32:01 +0100 Subject: [PATCH] Newline parity between printf and ros logging --- include/ur_modern_driver/log.h | 10 +++++----- src/ur/producer.cpp | 6 +++--- src/ur/state.cpp | 6 +++--- src/ur/stream.cpp | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/ur_modern_driver/log.h b/include/ur_modern_driver/log.h index 0d96b88..3837402 100644 --- a/include/ur_modern_driver/log.h +++ b/include/ur_modern_driver/log.h @@ -12,10 +12,10 @@ #else - #define LOG_DEBUG(format, ...) printf("DEBUG: " format, ##__VA_ARGS__) - #define LOG_WARN(format, ...) printf("WARNING: " format, ##__VA_ARGS__) - #define LOG_INFO(format, ...) printf("INFO: " format, ##__VA_ARGS__) - #define LOG_ERROR(format, ...) printf("ERROR: " format, ##__VA_ARGS__) - #define LOG_FATAL(format, ...) printf("FATAL: " format, ##__VA_ARGS__) + #define LOG_DEBUG(format, ...) printf("DEBUG: " format "\n", ##__VA_ARGS__) + #define LOG_WARN(format, ...) printf("WARNING: " format "\n", ##__VA_ARGS__) + #define LOG_INFO(format, ...) printf("INFO: " format "\n", ##__VA_ARGS__) + #define LOG_ERROR(format, ...) printf("ERROR: " format "\n", ##__VA_ARGS__) + #define LOG_FATAL(format, ...) printf("FATAL: " format "\n", ##__VA_ARGS__) #endif \ No newline at end of file diff --git a/src/ur/producer.cpp b/src/ur/producer.cpp index f1ca009..bd51dae 100644 --- a/src/ur/producer.cpp +++ b/src/ur/producer.cpp @@ -29,7 +29,7 @@ std::unique_ptr URProducer::try_get() { ssize_t len = _stream.receive(pos, size); if(len < 1) { - LOG_DEBUG("Read nothing from stream\n"); + LOG_DEBUG("Read nothing from stream"); return std::unique_ptr(nullptr); } @@ -40,13 +40,13 @@ std::unique_ptr URProducer::try_get() { packet_size = bp.peek(); //TODO: check other wrong packet sizes? if(packet_size > sizeof(buf)) { - LOG_ERROR("A packet with 'len' larger than buffer was received, discarding...\n"); + LOG_ERROR("A packet with 'len' (%d) larger than buffer was received, discarding...", packet_size); return std::unique_ptr(nullptr); } } if(total < packet_size){ - LOG_DEBUG("Partial packet recieved\n"); + LOG_DEBUG("Partial packet recieved"); continue; } return std::move(_parser.parse(bp)); diff --git a/src/ur/state.cpp b/src/ur/state.cpp index 460bdf1..3631992 100644 --- a/src/ur/state.cpp +++ b/src/ur/state.cpp @@ -6,13 +6,13 @@ bool RobotState::parse_with(BinParser &bp) { //continue as long as there are bytes to read while(bp.check_size(sizeof(uint8_t))) { if(!bp.check_size(sizeof(uint32_t))){ - LOG_ERROR("Failed to read sub-package length, there's likely a parsing error\n"); + LOG_ERROR("Failed to read sub-package length, there's likely a parsing error"); return false; } uint32_t sub_size = bp.peek(); if(!bp.check_size(static_cast(sub_size))) { - LOG_WARN("Invalid sub-package size of %" PRIu32 " received!\n", sub_size); + LOG_WARN("Invalid sub-package size of %" PRIu32 " received!", sub_size); return false; } @@ -48,7 +48,7 @@ bool RobotState_V1_6__7::parse_package(BinParser &bp) { //TODO break; default: - LOG_ERROR("Invalid package type parsed: %" PRIu8 "\n", type); + LOG_ERROR("Invalid package type parsed: %" PRIu8 "", type); return false; } diff --git a/src/ur/stream.cpp b/src/ur/stream.cpp index a7c53a8..fad5ef9 100644 --- a/src/ur/stream.cpp +++ b/src/ur/stream.cpp @@ -9,7 +9,7 @@ bool URStream::connect() { if(_initialized) return false; - LOG_INFO("Connecting to UR @ %s:%d\n", _host.c_str(), _port); + LOG_INFO("Connecting to UR @ %s:%d", _host.c_str(), _port); //gethostbyname() is deprecated so use getadderinfo() as described in: //http://www.beej.us/guide/bgnet/output/html/multipage/syscalls.html#getaddrinfo @@ -23,7 +23,7 @@ bool URStream::connect() { hints.ai_flags = AI_PASSIVE; if(getaddrinfo(_host.c_str(), service.c_str(), &hints, &result) != 0) { - LOG_ERROR("Failed to get host name\n"); + LOG_ERROR("Failed to get host name"); return false; } @@ -45,13 +45,13 @@ bool URStream::connect() { int flag = 1; setsockopt(_socket_fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)); _initialized = true; - LOG_INFO("Connection successfully established\n"); + LOG_INFO("Connection successfully established"); break; } freeaddrinfo(result); if(!_initialized) - LOG_ERROR("Connection failed\n"); + LOG_ERROR("Connection failed"); return _initialized; }