0

I followed this post: http://www.boost.org/doc/libs/1_59_0/libs/log/doc/html/log/detailed/attributes.html

log( string nameValue) {
    attrs::mutable_constant< string > Name(nameValue);
    logger::get().add_attribute("Name", Name);
    Name.set(nameValue);
    cout << "name is: " << Name;
}

Only one time the Name attribute is set with nameValue and remains as contant for every. So I using set() method to set new value.But the Name is not getting updated with new nameValue when we pass a new value in log() method.

Boost version: 1.59 and OS: Ubuntu 15.04

Any solution to this problem.

Thanks in advance.

SGPJ
  • 25
  • 7

1 Answers1

1

The problem is that you attempt to add the attribute on every call, and only the first call actually succeeds.

The add_attribute method of loggers act similarly to insert on associative containers. It returns an iterator and a bool that indicates whether the new attribute has been added or an attribute with the same name already existed in the attribute set of the logger. In the latter case the insertion did not happen and the returned iterator points to the existing attribute in the set.

You should use the returned iterator to set the new value. You will need to use attribute_cast to convert the generic attribute wrapper obtained through the iterator to mutable_constant.

Andrey Semashev
  • 10,046
  • 1
  • 17
  • 27
  • thanks Andrey this issue is solved. But I am still facing issue with boost log rotation is not working when we set append mode, I have raised in separate question: http://stackoverflow.com/questions/34037325/problems-with-file-rotation-after-adding-append-flag-in-boost-1-59-log-v2 – SGPJ Dec 09 '15 at 08:56