Menu

Logs encrypting

2014-09-20
2014-09-20
  • Vasyl Shestak

    Vasyl Shestak - 2014-09-20

    You have advised here to use sink with own out stream. I tried to add my own stream but add_ostream method takes shared_ptr<basic_ostream> and my overloads were ignored.

    Can You help me? I need to encrypt all formatted message before it will be written to the target file.

     
  • Andrey Semashev

    Andrey Semashev - 2014-09-20

    There is only one add_stream method in the text_ostream_backend. It takes a pointer to the stream that you have to create. Your stream will have to do the encryption before writing to the file. This will likely require you to write an encrypting streambuf. Boost.IOStreams may help you with that.

     
  • Vasyl Shestak

    Vasyl Shestak - 2014-09-20

    Thank You so much for a such fast response!
    I've found another one solution: I've used my own record formatter and a local copy of formatting_ostream.

    void RecordFormatter(logging::record_view const& rec, logging::formatting_ostream& strm)
    {
    std::string logEntryString;
    logging::formatting_ostream formattingStream(logEntryString);
    formattingStream << rec[expr::message];
    Encrypt(logEntryString);
    strm << logEntryString;
    }

    //and apply it in Init function
    boost::shared_ptr< sink_t > sink(new sink_t(backend));
    sink->set_formatter(&RecordFormatter);
    boostLogger->add_sink(sink);
    
     

    Last edit: Vasyl Shestak 2014-09-20

Log in to post a comment.