[SERVER-43292] log() should handle std::string_view Created: 12/Sep/19  Updated: 29/Oct/23  Resolved: 07/Mar/20

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.7.0

Type: Task Priority: Major - P3
Reporter: Benjamin Caimano (Inactive) Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Dev Tools 2020-03-09
Participants:

 Description   

This seems an easy thing to write. I just stumbled upon something like this in a code review:

unittest::log() << "foo " << std::string(myStringView) << " bar";

Given our usually accommodating logger system, this seems a bit jarring.



 Comments   
Comment by Githook User [ 26/Mar/20 ]

Author:

{'name': 'Billy Donahue', 'username': 'BillyDonahue', 'email': 'billy.donahue@mongodb.com'}

Message: SERVER-43292 logv2 support for std::string_view

(cherry picked from commit 2f77fdb760d64e3776dcbeb1f947783fd97dd616)
Branch: v4.4
https://github.com/mongodb/mongo/commit/143f73dd9d578312b640d5342fdb691befcfec60

Comment by Githook User [ 07/Mar/20 ]

Author:

{'username': 'BillyDonahue', 'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com'}

Message: SERVER-43292 logv2 support for std::string_view
Branch: master
https://github.com/mongodb/mongo/commit/2f77fdb760d64e3776dcbeb1f947783fd97dd616

Comment by Billy Donahue [ 05/Mar/20 ]

CR https://mongodbcr.appspot.com/560810002

Comment by Billy Donahue [ 03/Mar/20 ]

Important bug.
Here's what happens when a std::string_view is logged directly:

          LOGV2(31379, "Removing prefix: {prefix}", "prefix"_attr = remainder.substr(0, pos));                                                                                                                                                       
 
[cpp_unit_test:stacktrace_libunwind_test] 2020-03-03T06:04:49.877+0000 | 2020-03-03T06:04:49.877Z I  -        31379   [main] "Removing prefix: {prefix}","attr":{"prefix":[66,65,67,75,84,82,65,67,69,58,32,123,34,98,97,99,107,116,114,97,99,101,34,58,91,123,34,97,34,58,34,53,53,55,54,57,52,50,53,68,55,51,49,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,51,55,67,55,51,49,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,49,56,115,116,97,99,107,95,116,114,97,99,101,95,100,101,116,97,105,108,49,50,95,71,76,79,66,65,76,95,95,78,95,49,49,57]}

Or, without lobster interference:

[cpp_unit_test:stacktrace_libunwind_test] 2020-03-03T06:04:49.877+0000 {"t":{"$date":"2020-03-03T06:04:49.877Z"},"s":"I", "c":"-",       "id":31429,"ctx":"main","msg":"trace: {trace}","attr":{"trace":[66,65,67,75,84,82,65,67,69,58,32,123,34,98,97,99,107,116,114,97,99,101,34,58,91,123,34,97,34,58,34,53,53,55,54,57,52,50,53,68,55,51,49,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,51,55,67,55,51,49,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,49,56,115,116,97,99,107,95,116,114,97,99,101,95,100,101,116,97,105,108,49,50,95,71,76,79,66,65,76,95,95,78,95,49,49,57,112,114,105,110,116,83,116,97,99,107,84,114,97,99,101,73,109,112,108,69,82,75,78,83,49,95,55,79,112,116,105,111,110,115,69,80,78,83,95,49,52,83,116,97,99,107,84,114,97,99,101,83,105,110,107,69,46,99,111,110,115,116,112,114,111,112,46,53,55,53,34,44,34,115,43,34,58,34,49,69,49,34,125,44,123,34,97,34,58,34,53,53,55,54,57,52,50,53,69,69,53,65,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,51,55,68,69,53,65,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,49,53,112,114,105,110,116,83,116,97,99,107,84,114,97,99,101,69,82,83,111,34,44,34,115,43,34,58,34,51,65,34,125,44,123,34,97,34,58,34,53,53,55,54,57,52,49,50,69,68,52,57,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,68,68,52,57,34,44,34,115,34,58,34,95,90,76,49,52,115,116,97,116,105,99,70,117,110,99,116,105,111,110,82,83,111,34,44,34,115,43,34,58,34,57,34,125,44,123,34,97,34,58,34,53,53,55,54,57,52,49,50,69,68,53,57,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,68,68,53,57,34,44,34,115,34,58,34,95,90,78,49,50,95,71,76,79,66,65,76,95,95,78,95,49,50,54,97,110,111,110,121,109,111,117,115,78,97,109,101,115,112,97,99,101,70,117,110,99,116,105,111,110,69,82,83,111,34,44,34,115,43,34,58,34,57,34,125,44,123,34,97,34,58,34,53,53,55,54,57,52,49,50,69,68,54,57,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,68,68,54,57,34,44,34,115,34,58,34,95,90,49,52,104,105,100,100,101,110,70,117,110,99,116,105,111,110,82,83,111,34,44,34,115,43,34,58,34,57,34,125,44,123,34,97,34,58,34,53,53,55,54,57,52,49,50,69,68,55,57,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,68,68,55,57,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,49,56,117,110,119,105,110,100,95,116,101,115,116,95,100,101,116,97,105,108,49,52,110,111,114,109,97,108,70,117,110,99,116,105,111,110,69,82,83,111,34,44,34,115,43,34,58,34,57,34,125,44,123,34,97,34,58,34,53,53,55,54,57,52,49,50,70,56,66,54,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,69,56,66,54,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,49,56,117,110,119,105,110,100,95,116,101,115,116,95,100,101,116,97,105,108,51,57,85,110,105,116,84,101,115,116,95,83,117,105,116,101,78,97,109,101,85,110,119,105,110,100,84,101,115,116,78,97,109,101,76,105,110,107,97,103,101,55,95,100,111,84,101,115,116,69,118,34,44,34,115,43,34,58,34,52,54,34,125,44,123,34,97,34,58,34,53,53,55,54,57,52,49,52,69,67,57,51,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,54,68,67,57,51,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,56,117,110,105,116,116,101,115,116,52,84,101,115,116,51,114,117,110,69,118,34,44,34,115,43,34,58,34,50,51,34,125,44,123,34,97,34,58,34,53,53,55,54,57,52,49,51,48,66,57,51,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,70,66,57,51,34,44,34,115,34,58,34,95,90,78,83,116,49,55,95,70,117,110,99,116,105,111,110,95,104,97,110,100,108,101,114,73,70,118,118,69,90,78,53,109,111,110,103,111,56,117,110,105,116,116,101,115,116,52,84,101,115,116,49,55,82,101,103,105,115,116,114,97,116,105,111,110,65,103,101,110,116,73,78,83,49,95,49,56,117,110,119,105,110,100,95,116,101,115,116,95,100,101,116,97,105,108,51,57,85,110,105,116,84,101,115,116,95,83,117,105,116,101,78,97,109,101,85,110,119,105,110,100,84,101,115,116,78,97,109,101,76,105,110,107,97,103,101,69,69,67,52,69,78,83,49,95,49,48,83,116,114,105,110,103,68,97,116,97,69,83,56,95,83,56,95,69,85,108,118,69,95,69,57,95,77,95,105,110,118,111,107,101,69,82,75,83,116,57,95,65,110,121,95,100,97,116,97,34,44,34,115,43,34,58,34,52,51,34,125,44,123,34,97,34,58,34,53,53,55,54,57,52,49,53,48,51,57,52,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,54,70,51,57,52,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,56,117,110,105,116,116,101,115,116,53,83,117,105,116,101,51,114,117,110,69,82,75,78,83,116,55,95,95,99,120,120,49,49,49,50,98,97,115,105,99,95,115,116,114,105,110,103,73,99,83,116,49,49,99,104,97,114,95,116,114,97,105,116,115,73,99,69,83,97,73,99,69,69,69,83,57,95,105,34,44,34,115,43,34,58,34,52,49,52,34,125,44,123,34,97,34,58,34,53,53,55,54,57,52,49,53,49,70,54,57,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,55,48,70,54,57,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,56,117,110,105,116,116,101,115,116,53,83,117,105,116,101,51,114,117,110,69,82,75,83,116,54,118,101,99,116,111,114,73,78,83,116,55,95,95,99,120,120,49,49,49,50,98,97,115,105,99,95,115,116,114,105,110,103,73,99,83,116,49,49,99,104,97,114,95,116,114,97,105,116,115,73,99,69,83,97,73,99,69,69,69,83,97,73,83,56,95,69,69,82,75,83,56,95,83,69,95,105,34,44,34,115,43,34,58,34,51,57,57,34,125,44,123,34,97,34,58,34,53,53,55,54,57,52,49,50,53,57,52,68,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,52,57,52,68,34,44,34,115,34,58,34,109,97,105,110,34,44,34,115,43,34,58,34,57,51,68,34,125,44,123,34,97,34,58,34,55,70,52,70,56,57,65,56,57,66,57,55,34,44,34,98,34,58,34,55,70,52,70,56,57,65,54,56,48,48,48,34,44,34,111,34,58,34,50,49,66,57,55,34,44,34,115,34,58,34,95,95,108,105,98,99,95,115,116,97,114,116,95,109,97,105,110,34,44,34,115,43,34,58,34,69,55,34,125,44,123,34,97,34,58,34,53,53,55,54,57,52,49,50,69,67,55,65,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,68,67,55,65,34,44,34,115,34,58,34,95,115,116,97,114,116,34,44,34,115,43,34,58,34,50,65,34,125,93,44,34,112,114,111,99,101,115,115,73,110,102,111,34,58,123,34,109,111,110,103,111,100,98,86,101,114,115,105,111,110,34,58,34,117,110,107,110,111,119,110,34,44,34,103,105,116,86,101,114,115,105,111,110,34,58,34,110,111,110,101,34,44,34,99,111,109,112,105,108,101,100,77,111,100,117,108,101,115,34,58,91,34,117,110,107,110,111,119,110,34,93,44,34,117,110,97,109,101,34,58,123,34,115,121,115,110,97,109,101,34,58,34,76,105,110,117,120,34,44,34,114,101,108,101,97,115,101,34,58,34,52,46,49,53,46,48,45,49,48,52,52,45,97,119,115,34,44,34,118,101,114,115,105,111,110,34,58,34,35,52,54,45,85,98,117,110,116,117,32,83,77,80,32,84,104,117,32,74,117,108,32,52,32,49,51,58,51,56,58,50,56,32,85,84,67,32,50,48,49,57,34,44,34,109,97,99,104,105,110,101,34,58,34,120,56,54,95,54,52,34,125,44,34,115,111,109,97,112,34,58,91,123,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,101,108,102,84,121,112,101,34,58,51,44,34,98,117,105,108,100,73,100,34,58,34,68,70,51,50,52,52,69,50,56,52,53,48,54,53,52,54,54,70,50,68,57,66,65,55,69,50,56,54,69,55,48,69,68,67,53,56,53,49,50,48,34,125,44,123,34,98,34,58,34,55,70,52,70,56,57,65,54,56,48,48,48,34,44,34,112,97,116,104,34,58,34,47,108,105,98,47,120,56,54,95,54,52,45,108,105,110,117,120,45,103,110,117,47,108,105,98,99,46,115,111,46,54,34,44,34,101,108,102,84,121,112,101,34,58,51,44,34,98,117,105,108,100,73,100,34,58,34,66,52,49,55,67,48,66,65,55,67,67,53,67,70,48,54,68,49,68,49,66,69,68,54,54,53,50,67,69,68,66,57,50,53,51,67,54,48,68,48,34,125,93,125,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,53,53,55,54,57,52,50,53,68,55,51,49,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,51,55,67,55,51,49,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,49,56,115,116,97,99,107,95,116,114,97,99,101,95,100,101,116,97,105,108,49,50,95,71,76,79,66,65,76,95,95,78,95,49,49,57,112,114,105,110,116,83,116,97,99,107,84,114,97,99,101,73,109,112,108,69,82,75,78,83,49,95,55,79,112,116,105,111,110,115,69,80,78,83,95,49,52,83,116,97,99,107,84,114,97,99,101,83,105,110,107,69,46,99,111,110,115,116,112,114,111,112,46,53,55,53,34,44,34,115,43,34,58,34,49,69,49,34,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,53,53,55,54,57,52,50,53,69,69,53,65,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,51,55,68,69,53,65,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,49,53,112,114,105,110,116,83,116,97,99,107,84,114,97,99,101,69,82,83,111,34,44,34,115,43,34,58,34,51,65,34,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,53,53,55,54,57,52,49,50,69,68,52,57,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,68,68,52,57,34,44,34,115,34,58,34,95,90,76,49,52,115,116,97,116,105,99,70,117,110,99,116,105,111,110,82,83,111,34,44,34,115,43,34,58,34,57,34,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,53,53,55,54,57,52,49,50,69,68,53,57,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,68,68,53,57,34,44,34,115,34,58,34,95,90,78,49,50,95,71,76,79,66,65,76,95,95,78,95,49,50,54,97,110,111,110,121,109,111,117,115,78,97,109,101,115,112,97,99,101,70,117,110,99,116,105,111,110,69,82,83,111,34,44,34,115,43,34,58,34,57,34,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,53,53,55,54,57,52,49,50,69,68,54,57,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,68,68,54,57,34,44,34,115,34,58,34,95,90,49,52,104,105,100,100,101,110,70,117,110,99,116,105,111,110,82,83,111,34,44,34,115,43,34,58,34,57,34,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,53,53,55,54,57,52,49,50,69,68,55,57,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,68,68,55,57,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,49,56,117,110,119,105,110,100,95,116,101,115,116,95,100,101,116,97,105,108,49,52,110,111,114,109,97,108,70,117,110,99,116,105,111,110,69,82,83,111,34,44,34,115,43,34,58,34,57,34,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,53,53,55,54,57,52,49,50,70,56,66,54,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,69,56,66,54,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,49,56,117,110,119,105,110,100,95,116,101,115,116,95,100,101,116,97,105,108,51,57,85,110,105,116,84,101,115,116,95,83,117,105,116,101,78,97,109,101,85,110,119,105,110,100,84,101,115,116,78,97,109,101,76,105,110,107,97,103,101,55,95,100,111,84,101,115,116,69,118,34,44,34,115,43,34,58,34,52,54,34,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,53,53,55,54,57,52,49,52,69,67,57,51,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,54,68,67,57,51,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,56,117,110,105,116,116,101,115,116,52,84,101,115,116,51,114,117,110,69,118,34,44,34,115,43,34,58,34,50,51,34,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,53,53,55,54,57,52,49,51,48,66,57,51,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,70,66,57,51,34,44,34,115,34,58,34,95,90,78,83,116,49,55,95,70,117,110,99,116,105,111,110,95,104,97,110,100,108,101,114,73,70,118,118,69,90,78,53,109,111,110,103,111,56,117,110,105,116,116,101,115,116,52,84,101,115,116,49,55,82,101,103,105,115,116,114,97,116,105,111,110,65,103,101,110,116,73,78,83,49,95,49,56,117,110,119,105,110,100,95,116,101,115,116,95,100,101,116,97,105,108,51,57,85,110,105,116,84,101,115,116,95,83,117,105,116,101,78,97,109,101,85,110,119,105,110,100,84,101,115,116,78,97,109,101,76,105,110,107,97,103,101,69,69,67,52,69,78,83,49,95,49,48,83,116,114,105,110,103,68,97,116,97,69,83,56,95,83,56,95,69,85,108,118,69,95,69,57,95,77,95,105,110,118,111,107,101,69,82,75,83,116,57,95,65,110,121,95,100,97,116,97,34,44,34,115,43,34,58,34,52,51,34,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,53,53,55,54,57,52,49,53,48,51,57,52,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,54,70,51,57,52,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,56,117,110,105,116,116,101,115,116,53,83,117,105,116,101,51,114,117,110,69,82,75,78,83,116,55,95,95,99,120,120,49,49,49,50,98,97,115,105,99,95,115,116,114,105,110,103,73,99,83,116,49,49,99,104,97,114,95,116,114,97,105,116,115,73,99,69,83,97,73,99,69,69,69,83,57,95,105,34,44,34,115,43,34,58,34,52,49,52,34,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,53,53,55,54,57,52,49,53,49,70,54,57,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,55,48,70,54,57,34,44,34,115,34,58,34,95,90,78,53,109,111,110,103,111,56,117,110,105,116,116,101,115,116,53,83,117,105,116,101,51,114,117,110,69,82,75,83,116,54,118,101,99,116,111,114,73,78,83,116,55,95,95,99,120,120,49,49,49,50,98,97,115,105,99,95,115,116,114,105,110,103,73,99,83,116,49,49,99,104,97,114,95,116,114,97,105,116,115,73,99,69,83,97,73,99,69,69,69,83,97,73,83,56,95,69,69,82,75,83,56,95,83,69,95,105,34,44,34,115,43,34,58,34,51,57,57,34,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,53,53,55,54,57,52,49,50,53,57,52,68,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,52,57,52,68,34,44,34,115,34,58,34,109,97,105,110,34,44,34,115,43,34,58,34,57,51,68,34,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,55,70,52,70,56,57,65,56,57,66,57,55,34,44,34,98,34,58,34,55,70,52,70,56,57,65,54,56,48,48,48,34,44,34,111,34,58,34,50,49,66,57,55,34,44,34,115,34,58,34,95,95,108,105,98,99,95,115,116,97,114,116,95,109,97,105,110,34,44,34,115,43,34,58,34,69,55,34,125,10,32,32,70,114,97,109,101,58,32,123,34,97,34,58,34,53,53,55,54,57,52,49,50,69,67,55,65,34,44,34,98,34,58,34,53,53,55,54,57,51,69,69,49,48,48,48,34,44,34,111,34,58,34,50,52,68,67,55,65,34,44,34,115,34,58,34,95,115,116,97,114,116,34,44,34,115,43,34,58,34,50,65,34,125]}}

Generated at Thu Feb 08 05:02:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.