Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glog logging issue with Eigen3 #695

Closed
zyuzhi opened this issue Aug 6, 2021 · 1 comment · Fixed by #731
Closed

Glog logging issue with Eigen3 #695

zyuzhi opened this issue Aug 6, 2021 · 1 comment · Fixed by #731

Comments

@zyuzhi
Copy link

zyuzhi commented Aug 6, 2021

when i use glog with Eigen3 matrix, i found that every value in Eigen3 matrix is pad with '0'.

I run some tests, and find that

  1. glog with Eigen3 matrix: NOT fine
  2. glog with Eigen3 matrix and std::setfill(' '): fine
  3. cout with Eigen3 matrix works: fine
  4. reset stream fill char with LogMessage::stream().fill(' ') works: fine
  5. glog with double value and std::setw(4): NOT fine
  6. glog with double value, std::setfill(' ') and std::setw(4): fine

and i check the logging.cc, found stream().fill('0') calling here, why fill('0')?.

shoud we change to stream().fill(' ') or let user to customize padding character?

https://github.com/google/glog/blob/master/src/logging.cc#L1588

stream().fill('0');


here's the test code and env

glog version: 0.3.5-1

Eigen version: 3.3.4-4

cpp file

#include <iostream>
#include <iomanip>
#include <Eigen/Core>
#include <glog/logging.h>

int main(int /*argc*/, char** /*argv*/) {
  Eigen::Vector3d a = Eigen::Vector3d::Random();
  Eigen::Matrix3d m = Eigen::Matrix3d::Random();
  LOG(INFO) << a.transpose();
  LOG(INFO) << std::setfill(' ') << a.transpose();
  std::cout << a.transpose() << std::endl;
  LOG(INFO) << std::setw(4) << 1.0;
  LOG(INFO) << std::setfill(' ') << std::setw(4) << 1.0;
  google::LogMessage l(__FILE__, __LINE__, google::INFO);
  l.stream().fill(' ');
  l.stream() << a.transpose();

  return 0;
}

cmake file

project(test)
cmake_minimum_required(VERSION 3.17)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "-O2 -march=native -no-pie")
find_package(Eigen3 REQUIRED)

add_definitions(-DEIGEN_NO_DEBUG)
include_directories(${EIGEN3_INCLUDE_DIR})

add_executable(test1 test1.cpp)
target_link_libraries(test1 
    glog)

output

$ ./test1
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0806 17:56:02.290221   583 test1.cpp:9] 00.680375 -0.211234 00.566198
I0806 17:56:02.290475   583 test1.cpp:10]  0.680375 -0.211234  0.566198
 0.680375 -0.211234  0.566198
I0806 17:56:02.290553   583 test1.cpp:12] 0001
I0806 17:56:02.290572   583 test1.cpp:13]    1
I0806 17:56:02.290589   583 test1.cpp:14]  0.680375 -0.211234  0.566198
@sergiud
Copy link
Collaborator

sergiud commented Aug 9, 2021

We should save the previous fill character and restore it afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants