Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Glog logging issue with Eigen3 #695

@zyuzhi

Description

@zyuzhi

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions