[Logging] Defining a to_string destination

Hi, I would like to log to a standard container like std::list<std::string> or something similar, so i can send my logs to another program over network. But i have problems defining my own destination. For now it would be ok, to log just to a string. But i don't understand how to define my own destination in the right way. I looked at http://torjo.com/log2/doc/html/namespaceboost_1_1logging_1_1manipulator.html... but i don't understand the "sharing data" part well. Maybe someone can help me out here? I have so far: struct to_string : boost::logging::destination::class_<to_string, boost::logging::destination::implement_op_equal::has_context> { std::string s; to_string(std::string s) : s(s) {} bool operator==(const to_string& other) { return s == other.s; } // param = const std::string& // (in other words, it's the arg_type from your destination base class) void operator()(param msg) const { // s.append(msg); } But even that is not compiling. Any help would be appreciated! :-) Greetings Manuel Jung

Hi Manuel, I will show you how to do it tomorrow the latest. Best, John
Hi,
I would like to log to a standard container like std::list<std::string> or something similar, so i can send my logs to another program over network. But i have problems defining my own destination. For now it would be ok, to log just to a string. But i don't understand how to define my own destination in the right way. I looked at http://torjo.com/log2/doc/html/namespaceboost_1_1logging_1_1manipulator.html... but i don't understand the "sharing data" part well. Maybe someone can help me out here?
I have so far: struct to_string : boost::logging::destination::class_<to_string, boost::logging::destination::implement_op_equal::has_context> { std::string s; to_string(std::string s) : s(s) {}
bool operator==(const to_string& other) { return s == other.s; }
// param = const std::string& // (in other words, it's the arg_type from your destination base class) void operator()(param msg) const { // s.append(msg); }
But even that is not compiling. Any help would be appreciated! :-) Greetings Manuel Jung
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- http://John.Torjo.com -- C++ expert http://blog.torjo.com ... call me only if you want things done right

Hi, Thanks! Thats great, im looking forward to it :-) Greetigns Manuel
Hi Manuel,
I will show you how to do it tomorrow the latest.
Best, John
Hi,
I would like to log to a standard container like std::list<std::string> or something similar, so i can send my logs to another program over network. But i have problems defining my own destination. For now it would be ok, to log just to a string. But i don't understand how to define my own destination in the right way. I looked at
http://torjo.com/log2/doc/html/namespaceboost_1_1logging_1_1manipulator.html...
but i don't understand the "sharing data" part well. Maybe someone can help me out here?
I have so far: struct to_string : boost::logging::destination::class_<to_string, boost::logging::destination::implement_op_equal::has_context> { std::string s; to_string(std::string s) : s(s) {}
bool operator==(const to_string& other) { return s == other.s; }
// param = const std::string& // (in other words, it's the arg_type from your destination base class) void operator()(param msg) const { // s.append(msg); }
But even that is not compiling. Any help would be appreciated! :-) Greetings Manuel Jung
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Hi Manuel, Sorry for the late reply. Here it is: struct string_logger { std::vector<std::string> strs; }; struct to_string : boost::logging::destination::class_<to_string, boost::logging::destination::implement_op_equal::has_context>, boost::logging::destination::non_const_context<string_logger> { bool operator==(const to_string& other) const { return &context() == &other.context(); } void operator()(param msg) const { context().strs.push_back(msg); } }; Best, John
Hi, Thanks! Thats great, im looking forward to it :-) Greetigns Manuel
-- http://John.Torjo.com -- C++ expert http://blog.torjo.com ... call me only if you want things done right

Hi John, thanks for the code. But im still missing one point. How do i access the data in the std::vector? I understand that it is in a shared pointer now. The context obeject is not accessible from outside. I have done this: to_string To_String; And than added this to my logger destinations: g_l()->writer().add_destination( To_String ); Is this right, or do i have to write g_l()->writer().add_destination( Bufferwriter.to_string() ); Greetings Manuel
Hi Manuel,
Sorry for the late reply. Here it is:
struct string_logger { std::vector<std::string> strs; };
struct to_string : boost::logging::destination::class_<to_string, boost::logging::destination::implement_op_equal::has_context>, boost::logging::destination::non_const_context<string_logger> {
bool operator==(const to_string& other) const { return &context() == &other.context(); } void operator()(param msg) const { context().strs.push_back(msg); } };
Best, John
Hi, Thanks! Thats great, im looking forward to it :-) Greetigns Manuel

Manuel Jung wrote:
Hi John,
thanks for the code. But im still missing one point. How do i access the data in the std::vector? I understand that it is in a shared pointer now. The context obeject is not accessible from outside. I have done this:
to_string To_String;
And than added this to my logger destinations:
g_l()->writer().add_destination( To_String );
This is fine. To access the vector, just add a member function of to_string. const std::vector<std::string> & strings() const { return context().strs; } Best, John -- http://John.Torjo.com -- C++ expert http://blog.torjo.com ... call me only if you want things done right

Hi, Thank you ver much. This is working now :-). Maybe a nice addition to the documentation? Cheers, Manuel John Torjo wrote:
Manuel Jung wrote:
Hi John,
thanks for the code. But im still missing one point. How do i access the data in the std::vector? I understand that it is in a shared pointer now. The context obeject is not accessible from outside. I have done this:
to_string To_String;
And than added this to my logger destinations:
g_l()->writer().add_destination( To_String );
This is fine. To access the vector, just add a member function of to_string.
const std::vector<std::string> & strings() const { return context().strs; }
Best, John

Manuel Jung wrote:
Hi, Thank you ver much. This is working now :-). Maybe a nice addition to the documentation?
Sure, why not? :) I can add it as an example. Best, John
Cheers, Manuel
-- http://John.Torjo.com -- C++ expert http://blog.torjo.com ... call me only if you want things done right

Hey John, You said, you would show me the next day latest, but you didn't. Can i kindly ask, if you are still willing to help? Thanks, Manu
Hi Manuel,
I will show you how to do it tomorrow the latest.
Best, John
Hi,
I would like to log to a standard container like std::list<std::string> or something similar, so i can send my logs to another program over network. But i have problems defining my own destination. For now it would be ok, to log just to a string. But i don't understand how to define my own destination in the right way. I looked at
http://torjo.com/log2/doc/html/namespaceboost_1_1logging_1_1manipulator.html...
but i don't understand the "sharing data" part well. Maybe someone can help me out here?
I have so far: struct to_string : boost::logging::destination::class_<to_string, boost::logging::destination::implement_op_equal::has_context> { std::string s; to_string(std::string s) : s(s) {}
bool operator==(const to_string& other) { return s == other.s; }
// param = const std::string& // (in other words, it's the arg_type from your destination base class) void operator()(param msg) const { // s.append(msg); }
But even that is not compiling. Any help would be appreciated! :-) Greetings Manuel Jung
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Hi Manuel, Sorry for the late reply - did you see my previous email? It contains the solution. Best, John
Hey John,
You said, you would show me the next day latest, but you didn't. Can i kindly ask, if you are still willing to help? Thanks, Manu
-- http://John.Torjo.com -- C++ expert http://blog.torjo.com ... call me only if you want things done right
participants (2)
-
John Torjo
-
Manuel Jung