Git Product home page Git Product logo

Comments (11)

SergiusTheBest avatar SergiusTheBest commented on August 12, 2024

Hi @Ry-Kode !

Could you give some more details? As there could be different solutions.

from plog.

Ry-Kode avatar Ry-Kode commented on August 12, 2024

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.

SergiusTheBest avatar SergiusTheBest commented on August 12, 2024

Can you recompile those libraries?

from plog.

SergiusTheBest avatar SergiusTheBest commented on August 12, 2024

So you can just add #define cerr cerr; PLOGI and include plog?

from plog.

Ry-Kode avatar Ry-Kode commented on August 12, 2024

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.

Ry-Kode avatar Ry-Kode commented on August 12, 2024

Hello Sergius,
Can you give recommendations on best approach for the libraries which I cannot recompile?
Thank you

from plog.

SergiusTheBest avatar SergiusTheBest commented on August 12, 2024

@Ry-Kode Are they static libs (.lib) or dynamic libs (.dll)?

from plog.

Ry-Kode avatar Ry-Kode commented on August 12, 2024

Static libs (.lib)

from plog.

SergiusTheBest avatar SergiusTheBest commented on August 12, 2024

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.

Ry-Kode avatar Ry-Kode commented on August 12, 2024

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.

SergiusTheBest avatar SergiusTheBest commented on August 12, 2024

Posix is the same, just without the underscore.

from plog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.