@@ -45,7 +45,8 @@ class StdioLogger final : public Logger {
4545
4646 void log_impl (LogLevel level, const std::string &message,
4747 const std::source_location &location) final {
48- *m_output << format (m_name, level, message, location, m_format) << " \n " ;
48+ print_head (*m_output, m_name, level, location, m_format);
49+ *m_output << message << " \n " ;
4950 }
5051
5152 void flush () final { m_output->flush (); }
@@ -132,17 +133,14 @@ Logger::create_tee(const std::vector<std::shared_ptr<Logger>> &loggers) {
132133 return std::make_unique<TeeLogger>(loggers);
133134}
134135
135- std::string Logger::format (const std::string &name, LogLevel level,
136- const std::string &message,
137- const std::source_location &location,
138- const LogFormat &format) {
139- std::stringstream ss;
140-
136+ void Logger::print_head (std::ostream &out, const std::string &name,
137+ LogLevel level, const std::source_location &location,
138+ const LogFormat &format) {
141139 if (!format.time_format .empty ()) {
142140 auto now = std::chrono::system_clock::now ();
143141 auto time = std::chrono::system_clock::to_time_t (now);
144- ss << std::put_time (std::localtime (&time), format.time_format .c_str ())
145- << " " ;
142+ out << std::put_time (std::localtime (&time), format.time_format .c_str ())
143+ << " " ;
146144 }
147145
148146 if (format.level_width > 0 ) {
@@ -152,7 +150,7 @@ std::string Logger::format(const std::string &name, LogLevel level,
152150 level_ss << std::string (
153151 std::max<std::size_t >(0 , format.level_width - level_ss.str ().size ()),
154152 ' ' );
155- ss << level_ss.str () << " " ;
153+ out << level_ss.str () << " " ;
156154 }
157155
158156 if (format.name_width > 0 ) {
@@ -161,7 +159,7 @@ std::string Logger::format(const std::string &name, LogLevel level,
161159 name_ss << std::string (
162160 std::max<std::size_t >(0 , format.name_width - name_ss.str ().size ()),
163161 ' ' );
164- ss << name_ss.str () << " " ;
162+ out << name_ss.str () << " " ;
165163 }
166164
167165 if (format.location_width > 0 ) {
@@ -184,12 +182,8 @@ std::string Logger::format(const std::string &name, LogLevel level,
184182 std::max<std::size_t >(0 ,
185183 format.location_width - location_ss.str ().size ()),
186184 ' ' );
187- ss << location_ss.str () << " " ;
185+ out << location_ss.str () << " " ;
188186 }
189-
190- ss << message;
191-
192- return ss.str ();
193187}
194188
195189} // namespace odr
0 commit comments