小编DiB*_*DiB的帖子

设置 Python 丰富日志记录 (RichHandler) 的最小宽度

我正在使用RichHanderPython 内部格式化日志输出。虽然这在本地工作得很好,但当我在 GitLab 中运行时,它似乎默认使用 80 个字符宽的终端。这使得输出相当难以快速阅读和扫描。我想更改 RichHandler 的默认宽度,但我没有找到方法。

有没有办法为 Python RichHandler 日志处理程序设置最小控制台宽度?

# Pseudocode:
    
import logging
from rich.logging import RichHandler

def setup_logging():
  logger = logging.getLogger('myLogger')
  richFormatter = logging.Formatter('%(message)s')
  richHandler = RichHandler()
  # Something like: richHandler.setMinimumWidth(255)
  richHandler.setFormatter(richFormatter)
  logger.addHandler(richHandler)
Run Code Online (Sandbox Code Playgroud)

python python-3.x gitlab python-logging rich

5
推荐指数
1
解决办法
1816
查看次数

使用Boost Karma将std :: stringstream替换为double到std :: string的转换

为了提高性能,我希望更换:

template<class T> std::string ToStringFixed(const T x, const unsigned int width = 8)
{
  std::stringstream ss;
  ss << std::setprecision(width) << std::fixed << x;
  return ss.str();
}
Run Code Online (Sandbox Code Playgroud)

有了Boost Karma的实现,因为我们的项目已经使用了Boost,它看起来比上面的天真解决方案有显着的性能提升.

就像是:

std::string ToString(double d)
{
  using boost::spirit::karma::double_;
  using boost::spirit::ascii::space;
  using boost::spirit::karma::generate;

  std::string s
  std::back_insert_iterator<std::string> sink(s);
  generate(sink, double_, d);
  return s;
}
Run Code Online (Sandbox Code Playgroud)

这是从以下网站采用的:http://thisthread.blogspot.com/2011/04/generating-text-with-spirit-karma.html似乎走在正确的轨道上,但我不清楚如何控制精度,或者如果这样的解决方案对于浮点类型可以是模板友好的而不使用类型特征.(通过C++ 14使用的答案是可以接受的.)

c++ performance std boost-spirit

2
推荐指数
1
解决办法
293
查看次数