Comments (11)
Hi @Ry-Kode !
Could you give some more details? As there could be different solutions.
from plog.
Hello Sergius,
I'm not qutie sure what kind of details I can provide. Let me explain my use case: in my project I'm using your PLOG lib (thanks again for this!!) to create a rolling logfile. I'm also using some third party libraries which generate output that is written to stderr (and sometimes stdout). I'm looking for a way to 'capture' this output and save it to the PLOG rolling log file.
Thank you
from plog.
Can you recompile those libraries?
from plog.
So you can just add #define cerr cerr; PLOGI
and include plog?
from plog.
Yes, that would be one option.
Unfortuantely there are some libraries for which I do not have access to the source code so I cannot recompile them.
from plog.
Hello Sergius,
Can you give recommendations on best approach for the libraries which I cannot recompile?
Thank you
from plog.
@Ry-Kode Are they static libs (.lib) or dynamic libs (.dll)?
from plog.
Static libs (.lib)
from plog.
You can try the following approach:
union
{
struct
{
int readPipe;
int writePipe;
};
int pipeHandles[2];
} pipes;
_pipe(pipes.pipeHandles, 0, O_TEXT);
_dup2(pipes.writePipe, _fileno(stderr));
auto pipeFuture = std::async(launch::async, [&]()
{
std::array<char, 0x800> buf{};
for(;;)
{
int bytesRead = _read(pipes.readPipe, buf.data(), static_cast<int>(buf.size()));
if (bytesRead <= 0)
{
break;
}
buf[bytesRead] = 0;
LOGV << buf.data();
}
});
std::cerr << "test test";
_close(pipes.writePipe);
_close(_fileno(stderr));
It may work for your setup. But there is no guarantee.
from plog.
Thank you for the snippet Sergius.
However, It looks like this is Windows-only. _pipe, _dup2 etc are not supported on Posix. Do you an equivalent for Linux?
from plog.
Posix is the same, just without the underscore.
from plog.
Related Issues (20)
- [Feature Request] std::string to plog::nstring/plog::nchar HOT 2
- Why can I not create multiple loggers using dynamic instance id? HOT 1
- Function argument for use with plog HOT 2
- How can I dynamically create a Logger object? HOT 4
- always printf null HOT 2
- Roll log on application start HOT 2
- Log a packed argument list HOT 2
- Debug version using printf style alway cause Debug Assertion Failed! HOT 2
- Static linking of library HOT 2
- Release 1.1.10? HOT 6
- [Bug] When creating and assigning to logger - Compiler givers error: HOT 4
- [Feature Request] Single logger, but each appender has a different level HOT 4
- [Question] How to use Chained for multiple Classes within many DLL's
- \r\n for TxtFormatter in raw consoles HOT 4
- [Question] How to add custom prefix (record) information? HOT 2
- Can't add ConsoleAppender in a if statement HOT 2
- std::filesystem::path issue with new utf-8 mode on MSVC/Windows HOT 5
- How to use plog library in mac, its not working in mac for me HOT 5
- Please add instruction how to run samples HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plog.