Output newlines for each progress indicator when not on a tty.
This commit is contained in:
parent
17c32f5ce7
commit
eb12c16fd6
@ -27,6 +27,8 @@
|
|||||||
- Added support for turn penalties
|
- Added support for turn penalties
|
||||||
- Internals
|
- Internals
|
||||||
- Internal/Shared memory datafacades now share common memory layout and data loading code
|
- Internal/Shared memory datafacades now share common memory layout and data loading code
|
||||||
|
- Misc
|
||||||
|
- Progress indicators now print newlines when stdout is not a TTY
|
||||||
|
|
||||||
# 5.4.3
|
# 5.4.3
|
||||||
- Changes from 5.4.2
|
- Changes from 5.4.2
|
||||||
|
32
include/util/isatty.hpp
Normal file
32
include/util/isatty.hpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef ISATTY_HPP
|
||||||
|
#define ISATTY_HPP
|
||||||
|
|
||||||
|
// For isatty()
|
||||||
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||||
|
#include <unistd.h>
|
||||||
|
#else
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#define isatty _isatty
|
||||||
|
#define fileno _fileno
|
||||||
|
#else
|
||||||
|
#error Unknown platform - don't know which header to include for isatty()
|
||||||
|
#endif // win32
|
||||||
|
#endif // unix
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
namespace osrm
|
||||||
|
{
|
||||||
|
namespace util
|
||||||
|
{
|
||||||
|
|
||||||
|
// Returns true if stdout is a tty, false otherwise
|
||||||
|
// Useful for when you want to do something different when
|
||||||
|
// output is redirected to a logfile
|
||||||
|
inline bool IsStdoutATTY() { return isatty(fileno(stdout)); }
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
} // namespace osrm
|
||||||
|
|
||||||
|
#endif
|
@ -4,6 +4,8 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "util/isatty.hpp"
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
namespace util
|
namespace util
|
||||||
@ -71,6 +73,12 @@ class Percent
|
|||||||
{
|
{
|
||||||
std::cout << ".";
|
std::cout << ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When not on a TTY, print newlines after each progress indicator so
|
||||||
|
// so that progress is visible to line-buffered logging systems
|
||||||
|
if (!IsStdoutATTY())
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
#include "util/simple_logger.hpp"
|
#include "util/simple_logger.hpp"
|
||||||
#ifdef _MSC_VER
|
#include "util/isatty.hpp"
|
||||||
#include <io.h>
|
|
||||||
#define isatty _isatty
|
|
||||||
#define fileno _fileno
|
|
||||||
#else
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@ -77,7 +71,7 @@ SimpleLogger::~SimpleLogger()
|
|||||||
std::lock_guard<std::mutex> lock(get_mutex());
|
std::lock_guard<std::mutex> lock(get_mutex());
|
||||||
if (!LogPolicy::GetInstance().IsMute())
|
if (!LogPolicy::GetInstance().IsMute())
|
||||||
{
|
{
|
||||||
const bool is_terminal = static_cast<bool>(isatty(fileno(stdout)));
|
const bool is_terminal = IsStdoutATTY();
|
||||||
switch (level)
|
switch (level)
|
||||||
{
|
{
|
||||||
case logWARNING:
|
case logWARNING:
|
||||||
|
Loading…
Reference in New Issue
Block a user