21
21
#define BEAST_UTILITY_JOURNAL_H_INCLUDED
22
22
23
23
#include < xrpl/beast/utility/instrumentation.h>
24
+
24
25
#include < rapidjson/document.h>
25
26
26
27
#include < deque>
27
- #include < utility >
28
+ #include < optional >
28
29
#include < source_location>
29
30
#include < sstream>
30
-
31
+ # include < utility >
31
32
32
33
namespace ripple ::log {
33
34
template <typename T>
@@ -75,7 +76,7 @@ operator<<(std::ostream& os, LogField<T> const& param);
75
76
template <typename T>
76
77
std::ostream&
77
78
operator <<(std::ostream& os, LogParameter<T> const & param);
78
- }
79
+ } // namespace ripple::log
79
80
80
81
namespace beast {
81
82
@@ -117,7 +118,9 @@ class Journal
117
118
public:
118
119
template <typename T>
119
120
friend std::ostream&
120
- ripple::log::operator <<(std::ostream& os, ripple::log::LogField<T> const & param);
121
+ ripple::log::operator <<(
122
+ std::ostream& os,
123
+ ripple::log::LogField<T> const & param);
121
124
122
125
template <typename T>
123
126
friend std::ostream&
@@ -198,17 +201,18 @@ class Journal
198
201
199
202
static thread_local JsonLogContext currentJsonLogContext_;
200
203
201
-
202
204
// Invariant: m_sink always points to a valid Sink
203
205
Sink* m_sink = nullptr ;
204
206
205
207
static void
206
208
initMessageContext (std::source_location location);
207
209
208
210
static std::string
209
- formatLog (std::string const & message,
211
+ formatLog (
212
+ std::string const & message,
210
213
severities::Severity severity,
211
214
std::optional<JsonLogAttributes> const & attributes = std::nullopt );
215
+
212
216
public:
213
217
// --------------------------------------------------------------------------
214
218
@@ -300,10 +304,7 @@ class Journal
300
304
{
301
305
public:
302
306
ScopedStream (ScopedStream const & other)
303
- : ScopedStream(
304
- other.m_attributes,
305
- other.m_sink,
306
- other.m_level)
307
+ : ScopedStream(other.m_attributes, other.m_sink, other.m_level)
307
308
{
308
309
}
309
310
@@ -390,10 +391,7 @@ class Journal
390
391
391
392
/* * Construct or copy another Stream. */
392
393
Stream (Stream const & other)
393
- : Stream(
394
- other.m_attributes,
395
- other.m_sink,
396
- other.m_level)
394
+ : Stream(other.m_attributes, other.m_sink, other.m_level)
397
395
{
398
396
}
399
397
@@ -471,8 +469,7 @@ class Journal
471
469
if (m_attributes.has_value ())
472
470
m_attributes = JsonLogAttributes::combine (
473
471
other.m_attributes ->contextValues_ ,
474
- m_attributes->contextValues_
475
- );
472
+ m_attributes->contextValues_ );
476
473
else
477
474
m_attributes = other.m_attributes ;
478
475
}
@@ -521,8 +518,7 @@ class Journal
521
518
Stream
522
519
stream (Severity level) const
523
520
{
524
- return Stream (
525
- m_attributes, *m_sink, level);
521
+ return Stream (m_attributes, *m_sink, level);
526
522
}
527
523
528
524
/* * Returns `true` if any message would be logged at this severity level.
@@ -542,67 +538,49 @@ class Journal
542
538
{
543
539
if (m_jsonLogsEnabled)
544
540
initMessageContext (location);
545
- return {
546
- m_attributes,
547
- *m_sink,
548
- severities::kTrace };
541
+ return {m_attributes, *m_sink, severities::kTrace };
549
542
}
550
543
551
544
Stream
552
545
debug (std::source_location location = std::source_location::current()) const
553
546
{
554
547
if (m_jsonLogsEnabled)
555
548
initMessageContext (location);
556
- return {
557
- m_attributes,
558
- *m_sink,
559
- severities::kDebug };
549
+ return {m_attributes, *m_sink, severities::kDebug };
560
550
}
561
551
562
552
Stream
563
553
info (std::source_location location = std::source_location::current()) const
564
554
{
565
555
if (m_jsonLogsEnabled)
566
556
initMessageContext (location);
567
- return {
568
- m_attributes,
569
- *m_sink,
570
- severities::kInfo };
557
+ return {m_attributes, *m_sink, severities::kInfo };
571
558
}
572
559
573
560
Stream
574
561
warn (std::source_location location = std::source_location::current()) const
575
562
{
576
- const char * a = " a" ;
563
+ char const * a = " a" ;
577
564
rapidjson::Value v{a, 1 };
578
565
if (m_jsonLogsEnabled)
579
566
initMessageContext (location);
580
- return {
581
- m_attributes,
582
- *m_sink,
583
- severities::kWarning };
567
+ return {m_attributes, *m_sink, severities::kWarning };
584
568
}
585
569
586
570
Stream
587
571
error (std::source_location location = std::source_location::current()) const
588
572
{
589
573
if (m_jsonLogsEnabled)
590
574
initMessageContext (location);
591
- return {
592
- m_attributes,
593
- *m_sink,
594
- severities::kError };
575
+ return {m_attributes, *m_sink, severities::kError };
595
576
}
596
577
597
578
Stream
598
579
fatal (std::source_location location = std::source_location::current()) const
599
580
{
600
581
if (m_jsonLogsEnabled)
601
582
initMessageContext (location);
602
- return {
603
- m_attributes,
604
- *m_sink,
605
- severities::kFatal };
583
+ return {m_attributes, *m_sink, severities::kFatal };
606
584
}
607
585
/* * @} */
608
586
@@ -614,7 +592,9 @@ class Journal
614
592
{
615
593
globalLogAttributes_ = JsonLogAttributes{};
616
594
}
617
- globalLogAttributes_ = JsonLogAttributes::combine (globalLogAttributes_->contextValues (), globalLogAttributes.contextValues ());
595
+ globalLogAttributes_ = JsonLogAttributes::combine (
596
+ globalLogAttributes_->contextValues (),
597
+ globalLogAttributes.contextValues ());
618
598
}
619
599
};
620
600
@@ -725,12 +705,12 @@ using logwstream = basic_logstream<wchar_t>;
725
705
726
706
} // namespace beast
727
707
728
-
729
708
namespace ripple ::log {
730
709
731
710
namespace detail {
732
711
template <typename T>
733
- void setJsonValue (
712
+ void
713
+ setJsonValue (
734
714
rapidjson::Value& object,
735
715
rapidjson::MemoryPoolAllocator<>& allocator,
736
716
char const * name,
@@ -739,7 +719,10 @@ void setJsonValue(
739
719
{
740
720
using ValueType = std::decay_t <T>;
741
721
rapidjson::Value jsonValue;
742
- if constexpr (std::constructible_from<rapidjson::Value, ValueType, rapidjson::MemoryPoolAllocator<>&>)
722
+ if constexpr (std::constructible_from<
723
+ rapidjson::Value,
724
+ ValueType,
725
+ rapidjson::MemoryPoolAllocator<>&>)
743
726
{
744
727
jsonValue = rapidjson::Value{value, allocator};
745
728
if (outStream)
@@ -777,12 +760,9 @@ void setJsonValue(
777
760
}
778
761
779
762
object.AddMember (
780
- rapidjson::StringRef (name),
781
- std::move (jsonValue),
782
- allocator
783
- );
784
- }
763
+ rapidjson::StringRef (name), std::move (jsonValue), allocator);
785
764
}
765
+ } // namespace detail
786
766
787
767
template <typename T>
788
768
std::ostream&
@@ -793,7 +773,9 @@ operator<<(std::ostream& os, LogParameter<T> const& param)
793
773
detail::setJsonValue (
794
774
beast::Journal::currentJsonLogContext_.messageParams ,
795
775
beast::Journal::currentJsonLogContext_.allocator ,
796
- param.name_ , param.value_ , &os);
776
+ param.name_ ,
777
+ param.value_ ,
778
+ &os);
797
779
return os;
798
780
}
799
781
@@ -806,7 +788,9 @@ operator<<(std::ostream& os, LogField<T> const& param)
806
788
detail::setJsonValue (
807
789
beast::Journal::currentJsonLogContext_.messageParams ,
808
790
beast::Journal::currentJsonLogContext_.allocator ,
809
- param.name_ , param.value_ , nullptr );
791
+ param.name_ ,
792
+ param.value_ ,
793
+ nullptr );
810
794
return os;
811
795
}
812
796
@@ -824,17 +808,19 @@ field(char const* name, T&& value)
824
808
return LogField<T>{name, std::forward<T>(value)};
825
809
}
826
810
827
- template <typename ... Pair>
811
+ template <typename ... Pair>
828
812
[[nodiscard]] beast::Journal::JsonLogAttributes
829
813
attributes (Pair&&... pairs)
830
814
{
831
815
beast::Journal::JsonLogAttributes result;
832
816
833
817
(detail::setJsonValue (
834
- result.contextValues (),
835
- result.allocator (),
836
- pairs.first ,
837
- pairs.second , nullptr ), ...);
818
+ result.contextValues (),
819
+ result.allocator (),
820
+ pairs.first ,
821
+ pairs.second ,
822
+ nullptr ),
823
+ ...);
838
824
839
825
return result;
840
826
}
@@ -846,6 +832,6 @@ attr(char const* name, T&& value)
846
832
return std::make_pair (name, std::forward<T>(value));
847
833
}
848
834
849
- }
835
+ } // namespace ripple::log
850
836
851
837
#endif
0 commit comments