/
class_TraceEmitter.erl
1802 lines (1356 loc) · 58.2 KB
/
class_TraceEmitter.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% Copyright (C) 2007-2024 Olivier Boudeville
%
% This file is part of the Ceylan-Traces library.
%
% This library is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License or
% the GNU General Public License, as they are published by the Free Software
% Foundation, either version 3 of these Licenses, or (at your option)
% any later version.
% You can also redistribute it and/or modify it under the terms of the
% Mozilla Public License, version 1.1 or later.
%
% This library is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License and the GNU General Public License
% for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License, of the GNU General Public License and of the Mozilla Public License
% along with this library.
% If not, see <http://www.gnu.org/licenses/> and
% <http://www.mozilla.org/MPL/>.
%
% Author: Olivier Boudeville [olivier (dot) boudeville (at) esperide (dot) com]
% Creation date: July 1, 2007.
% @doc The <b>trace emitter</b> class, base class for all (WOOPER-based)
% emitters of traces.
%
-module(class_TraceEmitter).
-define( class_description,
"Base class for all (WOOPER-based) emitters of traces. "
"See class_TestTraceEmitter.erl and class_TraceEmitter_test.erl." ).
% Determines what are the direct mother classes of this class (if any):
%
% (preferred to be defined as empty rather than not be defined at all, as
% referenced by a static method)
%
-define( superclasses, [] ).
% Describes the class-specific attributes:
-define( class_attributes, [
{ name, bin_string(), "name of this trace emitter (not named "
"trace_name, in order to be more versatile)" },
% As this attribute should never be accessed directly (use emitter_init() at
% construction-time, and get_categorization/1 and set_categorization/2
% afterwards), in order to reduce the risk of clash 'trace_categorization'
% has been renamed in:
%
{ trace_emitter_categorization, bin_string(),
"categorization of this trace emitter" },
{ emitter_node, net_utils:bin_node_name(),
"the name of the Erlang node of this emitter" },
{ trace_aggregator_pid, aggregator_pid(),
"the PID of the trace aggregator collecting the traces emitted" },
{ trace_timestamp, maybe( app_timestamp() ),
"current application-specific timestamp" } ] ).
% Helper functions:
-export([ init/1, register_bridge/1,
get_categorization/1, set_categorization/2,
send/3, send_safe/3, send/4, send_safe/4, send/5, send_safe/5,
send_synchronised/3, send_synchronised/4, send_synchronised/5,
send_synchronisable/3, send_synchronisable/4, send_synchronisable/5,
wait_for_aggregator_synchronisation/0,
send_categorized_emitter/4, send_named_emitter/4,
get_trace_timestamp/1, get_trace_timestamp_as_binary/1,
get_plain_name/1, get_short_description/1,
sync/1, await_output_completion/0 ]).
% The class-specific trace_emitter_categorization define will be set in the
% trace_emitter_categorization attribute of each child class when coming down
% the inheritance hierarchy, so that the latest child class sets its targeted
% trace_emitter_categorization value).
-type emitter_name() :: text_utils:any_string().
% The name of a trace emitter.
%
% It is a plain string or a binary one, containing the name of a trace emitter.
%
% Note: dots are not allowed in an emitter name (they are used as naming
% separator).
%
% For example "MyObject 16", or `<<"First Talker">>'.
-type emitter_init() :: emitter_name()
| { emitter_name(), emitter_categorization() }.
% Initialising a trace emitter is specifying its name to the constructor of its
% actual class, which will augment that information with the correspond
% class-specific emitter categorization. Then, the pair resulting from this
% one-shot, initial operation will climb up the class hierarchy until reaching
% the class_TraceEmitter constructor.
%
% See also the trace_categorize/1 macro.
-type emitter_pid() :: wooper:instance_pid().
% PID of a trace emitter.
-type preformatted_trace() :: bin_string().
% A preformatted trace that can be sent to the trace aggregator and directly
% stored/written by it.
-export_type([ emitter_name/0,
emitter_categorization/0, bin_emitter_categorization/0,
emitter_init/0, emitter_pid/0, preformatted_trace/0 ]).
% Allows to define WOOPER base variables and methods for that class:
-include_lib("wooper/include/wooper.hrl").
% For send_from_* and all:
-include("class_TraceAggregator.hrl").
% For trace_aggregator_name:
-include("class_TraceEmitter.hrl").
-define( LogPrefix, "[Trace Emitter]" ).
% Implementation notes:
% A trace emitter used to have a specific notion of time (execution tick) as it
% needs to timestamp its traces. Now it relies on the content of an opaque
% 'trace_timestamp' attribute, which is stringified and used as it is, allowing
% for mostly any kind of application-level timestamp.
% To reduce the memory footprint in the trace aggregator mailbox and the size of
% messages sent over the network, most of the time binaries are used instead of
% plain strings.
%
% Notably the 'name' attribute is stored as a binary.
%
% Use text_utils:binary_to_string/1 to get back a plain string or, preferably,
% the class_TraceEmitter:get_plain_name/1 static method.
%
% The same applies for the 'trace_emitter_categorization' attribute.
% The constructor of this class is idempotent, in the sense that it can be
% applied more than once with no undesirable consequence.
%
% By default, a trace emitter locates its aggregator through a global naming
% look-up, but an arbitrary PID may be specified.
% The send_safe/{3,4,5} variations differ from their basic send/{3,4,5}
% counterparts on two aspects:
% - they are synchronous (blocking, hence safer)
% - they are echoed on the console as well
% Regarding the look-up scope of the trace aggregator:
%
% Its most common registration scope is global, yet in some (less common) cases,
% we prefer having one aggregator per node (e.g. multiple applications able to
% interact, yet each with its own autonomy and node); for scalability reasons,
% we do not want all trace emitters to have to specify an extra parameter at
% construction or to read each the configuration information in order to select
% a relevant look-up scope; so all go first for the general case ('global'
% registration of the aggregator) and fall back to 'local' in the other cases.
%
% To avoid any unnecessary global look-up or to designate a specific trace
% aggregator, use construct/3.
%
-define( emitter_look_up_scope, global_otherwise_local ).
% Shorthands:
-type ustring() :: text_utils:ustring().
-type bin_string() :: text_utils:bin_string().
-type emitter_info() :: traces:emitter_info().
-type trace_severity() :: traces:trace_severity().
-type message() :: traces:message().
-type message_categorization() :: traces:message_categorization().
-type emitter_categorization() :: traces:emitter_categorization().
-type bin_emitter_categorization() :: traces:bin_emitter_categorization().
-type emitter_any_categorization() :: traces:emitter_any_categorization().
-type app_timestamp() :: traces:app_timestamp().
-type priority() :: traces:priority().
-type aggregator_pid() :: class_TraceAggregator:aggregator_pid().
% @doc Constructs a trace emitter, from EmitterInit, which must be here a pair
% made of this name and another plain string, its emitter categorization,
% listing increasingly detailed sub-categories about this trace emitter,
% separated by dots (e.g. "topics.sports.basketball.coach").
%
% Note: this constructor should be idempotent, as a given instance might very
% well inherit (directly or not) from that class more than once.
%
-spec construct( wooper:state(),
{ emitter_name(), emitter_categorization() } ) -> wooper:state().
construct( State, _EmitterInit={ EmitterName, EmitterCategorization } ) ->
% Useless, as checks done just afterwards:
% when is_list( EmitterName ) andalso is_list( EmitterCategorization ) ->
%trace_utils:debug_fmt( "~ts Creating a trace emitter whose name is '~ts', "
% "whose PID is ~w and whose categorization is '~ts'.",
% [ ?LogPrefix, EmitterName, self(), EmitterCategorization ] ),
% Often classes inherit more than once from trace emitter; in this case, to
% avoid multiple initialisations, we consider that the first construction is
% the one that shall be retained, all next ones (if any) being then skipped:
%
case hasAttribute( State, trace_aggregator_pid ) of
% Already initialised:
true ->
State;
false ->
InitState = init( State ),
BinName = check_and_binarise_name( EmitterName ),
BinCategorization =
text_utils:ensure_binary( EmitterCategorization ),
setAttributes( InitState, [
{ name, BinName },
{ trace_emitter_categorization, BinCategorization },
% (emitter_node and trace_aggregator_pid set by init/1)
{ trace_timestamp, undefined } ] )
end;
% Should no mother class have set it:
construct( State, EmitterName ) ->
% Useless, as checked afterwards: when is_list( EmitterName ) ->
construct( State, _EmitterInit={ EmitterName,
?default_trace_emitter_categorization } ).
% Useless, as already checked:
%construct( _State, InvalidEmitterName ) ->
% throw( { invalid_emitter_name, InvalidEmitterName } ).
% @doc Constructs a trace emitter, from EmitterInit, which must be here a pair
% made of this name and another plain string, its emitter categorization,
% listing increasingly detailed sub-categories about this trace emitter,
% separated by dots (e.g. "topics.sports.basketball.coach"), and from the
% specified trace aggregator.
%
% Notes:
% - this constructor should be idempotent, as a given instance might very
% well inherit (directly or not) from that class more than once
%
% - being able to provide the PID of the target trace aggregator allows to use
% any aggregator of interest, regardless of choices in terms of naming
% registration
%
-spec construct( wooper:state(),
{ emitter_name(), emitter_categorization() }, aggregator_pid() ) ->
wooper:state().
construct( State, _EmitterInit={ EmitterName, EmitterCategorization },
TraceAggregatorPid ) ->
%trace_utils:debug_fmt( "~ts Creating a trace emitter whose name is '~ts', "
% "whose PID is ~w, whose categorization is '~ts' and using trace "
% "aggregator ~w.",
% [ ?LogPrefix, EmitterName, self(), EmitterCategorization,
% TraceAggregatorPid ] ),
BinName = check_and_binarise_name( EmitterName ),
BinCategorization = text_utils:ensure_binary( EmitterCategorization ),
setAttributes( State, [
{ name, BinName },
{ trace_emitter_categorization, BinCategorization },
{ trace_timestamp, undefined },
{ emitter_node, net_utils:localnode_as_binary() },
{ trace_aggregator_pid, TraceAggregatorPid } ] );
% Should no mother class have set it:
construct( State, EmitterName, TraceAggregatorPid ) ->
EmitterInit = { EmitterName, ?default_trace_emitter_categorization },
construct( State, EmitterInit, TraceAggregatorPid ).
% @doc Checks the emitter name, and, if needed, returns a binary version
% thereof.
%
% Note: we used to fail should at least one dot be found, now we convert the
% string name so that it becomes legit.
%
% (helper)
%
-spec check_and_binarise_name( emitter_name() ) -> bin_string().
check_and_binarise_name( StringName ) when is_list( StringName ) ->
LegitStringName = check_string_name( StringName ),
text_utils:string_to_binary( LegitStringName );
check_and_binarise_name( BinName ) when is_binary( BinName ) ->
StringName = text_utils:binary_to_string( BinName ),
check_and_binarise_name( StringName ).
% Helper:
check_string_name( Name ) ->
% Can be an io_list():
FlatName = text_utils:format( "~ts", [ Name ] ),
% Dots are not allowed in emitter names (as they are interpreted as
% subcategories), whereas for example FQDNs have such characters:
% text_utils:split_at_first( _Marker=$., Name ) =:= none_found orelse
% throw( { no_dot_allowed_in_emitter_name, FlatName }
text_utils:substitute( _Source=$., _Target=$:, FlatName ).
% Methods section.
% Generic interface.
% @doc Returns the name of this trace emitter, as a binary.
%
% Note: use text_utils:binary_to_string/1 to get back a plain string.
%
-spec getName( wooper:state() ) -> const_request_return( bin_string() ).
getName( State ) ->
wooper:const_return_result( ?getAttr(name) ).
% @doc Sets the name of this trace emitter from the specified string.
-spec setName( wooper:state(), emitter_name() ) -> oneway_return().
setName( State, NewName ) ->
BinName = text_utils:ensure_binary( NewName ),
%trace_utils:debug_fmt( "Renaming trace emitter from '~ts' to '~ts'.",
% [ ?getAttr(name), BinName ] ),
wooper:return_state( setAttribute( State, name, BinName ) ).
% @doc Sets the trace categorization for this trace emitter to specified plain
% string.
%
% Setting the trace categorization early in the constructor, before sending any
% trace, allows to have all traces for a given emitter correctly gathered in the
% same trace category, which is a lot clearer when browsing afterwards.
%
-spec setCategorization( wooper:state(), emitter_categorization() ) ->
oneway_return().
setCategorization( State, TraceCategorization ) ->
NewState = set_categorization( TraceCategorization, State ),
wooper:return_state( NewState ).
% @doc Displays the state of this instance in the console.
-spec display( wooper:state() ) -> const_oneway_return().
display( State ) ->
wooper:display_instance( State ),
wooper:const_return().
% @doc Returns a textual description of this trace emitter.
-spec toString( wooper:state() ) -> const_request_return( ustring() ).
toString( State ) ->
wooper:const_return_result( wooper:state_to_string( State ) ).
% @doc Callback triggered whenever a linked process stops, if this instance is
% to trap exits (not true by default).
%
-spec onWOOPERExitReceived( wooper:state(), pid(),
basic_utils:exit_reason() ) -> const_oneway_return().
onWOOPERExitReceived( State, PidOrPort, _ExitReason=normal ) ->
?debug_fmt( "The TraceEmitter default EXIT handler of this instance "
"ignored a normal EXIT message from ~w.", [ PidOrPort ] ),
wooper:const_return();
onWOOPERExitReceived( State, PidOrPort, ExitReason ) ->
?warning_fmt( "The TraceEmitter default EXIT handler of this instance "
"ignored the following EXIT message from ~w:~n'~p'.",
[ PidOrPort, ExitReason ] ),
wooper:const_return().
% @doc Callback triggered whenever a linked process stops, if this instance is
% to trap exits (not true by default).
%
-spec onWOOPERDownNotified( wooper:state(), monitor_utils:monitor_reference(),
monitor_utils:monitored_element_type(),
monitor_utils:monitored_element(), monitor_utils:monitor_info() ) ->
const_oneway_return().
onWOOPERDownNotified( State, MonitorRef, MonitoredType, MonitoredElement,
MonitorInfo ) ->
?warning_fmt( "The TraceEmitter default EXIT handler of this instance "
"ignored the following DOWN notification '~p' "
"for monitored element ~p of type '~p' (monitor reference: ~w).",
[ MonitorInfo, MonitoredElement, MonitoredType, MonitorRef ] ),
wooper:const_return().
% @doc Callback triggered if this instance requested to be notified whenever a
% new node is connected.
%
-spec onWOOPERNodeConnection( wooper:state(), net_utils:atom_node_name(),
monitor_utils:monitor_node_info() ) -> const_oneway_return().
onWOOPERNodeConnection( State, Node, MonitorNodeInfo ) ->
?warning_fmt( "The TraceEmitter default node up handler of this instance "
"ignored the connection notification for node '~ts' (information: ~p).",
[ Node, MonitorNodeInfo ] ),
wooper:const_return().
% @doc Callback triggered if this instance requested to be notified whenever a
% node disconnects.
%
-spec onWOOPERNodeDisconnection( wooper:state(), net_utils:atom_node_name(),
monitor_utils:monitor_node_info() ) -> const_oneway_return().
onWOOPERNodeDisconnection( State, Node, MonitorNodeInfo ) ->
?warning_fmt( "The TraceEmitter default node down handler of this instance "
"ignored the disconnection notification for node '~ts' "
"(information: ~p).", [ Node, MonitorNodeInfo ] ),
wooper:const_return().
% Static section.
% @doc Registers in the caller process a trace bridge suitable to integrate to
% this Traces subsystem.
%
% Dedicated to normal (non-TraceEmitter, probably not even non-WOOPER) processes
% that nevertheless need to send traces, to centralise them.
%
% See also the register_bridge/1 helper for trace emitter instances that need to
% define additionally their trace bridge, in order that the lower-level
% libraries/functions that they call can send such traces as well.
%
% Note: no bridge is expected to be already set, otherwise an exception is
% thrown.
%
-spec register_as_bridge( emitter_name(), emitter_categorization() ) ->
static_void_return().
register_as_bridge( TraceEmitterName, TraceCategory ) ->
TraceAggregatorPid =
class_TraceAggregator:get_aggregator( _LaunchAggregator=false ),
register_as_bridge( TraceEmitterName, TraceCategory, TraceAggregatorPid ),
wooper:return_static_void().
% @doc Registers in the caller process a trace bridge suitable to integrate to
% this Traces subsystem.
%
% Dedicated to normal (non-TraceEmitter, probably not even non-WOOPER) processes
% that nevertheless need to send traces, to centralise them.
%
% See also the register_as_bridge/1 helper for trace emitter instances that need
% to define additionally their trace bridge, in order that the lower-level
% libraries/functions that they call can send such traces as well.
%
% Note: no bridge is expected to be already set, otherwise an exception is
% thrown.
%
-spec register_as_bridge( emitter_name(), emitter_categorization(),
aggregator_pid() ) -> static_void_return().
register_as_bridge( TraceEmitterName, TraceCategory, TraceAggregatorPid ) ->
trace_bridge:register( _BridgeSpec={
check_and_binarise_name( TraceEmitterName ),
text_utils:ensure_binary( TraceCategory ), TraceAggregatorPid } ),
wooper:return_static_void().
% @doc Returns the name of the trace emitter corresponding to the specified
% constructor-level information.
%
% Supersedes for the best the trace_name/1 macro.
%
-spec get_trace_name( emitter_name() | emitter_info() ) ->
static_return( emitter_name() ).
get_trace_name( { TraceName, _TraceCategorization } ) ->
wooper:return_static( TraceName );
get_trace_name( TraceName ) ->
wooper:return_static( TraceName ).
% @doc Subcategorizes a given emitter name, by introducing an additional
% grouping level, based on the first character of the trace emitter name.
%
% This is typically useful to avoid that too many emitters are listed at a given
% categorization level, if using a trace supervisor that groups the emitter
% names based on the dots that they include.
%
% For example if the specified emitter name is "foobar", returns "f.foobar",
% resulting in this name to be sorted among all entries whose name starts with
% "f".
%
-spec subcategorize( emitter_name() ) -> static_return( emitter_name() );
( emitter_info() ) -> static_return( emitter_info() ).
% We do not alter the name, as any dot in it will be replaced with ':'; we
% update the categorization instead:
%
%subcategorize( _EmitterInfo={ Name, Categ } ) ->
% wooper:return_static( { subcategorize_name( Name ), Categ } );
%subcategorize( EmitterName ) ->
% wooper:return_static( subcategorize_name( EmmiterName ) ).
subcategorize( _EmitterInfo={ EmitterName=[ FirstChar | _T ], Categ } ) ->
NewCateg = text_utils:format( "~ts.~c", [ Categ, FirstChar ] ),
wooper:return_static( { EmitterName, NewCateg } );
subcategorize( EmmiterName ) ->
wooper:return_static( EmmiterName ).
% (helper)
%subcategorize_name( EmitterName=[ FirstChar | _T ] ) ->
% text_utils:format( "~c.~ts", [ FirstChar, EmitterName ] ).
% @doc Returns the names of all the base state attributes (be they defined by
% this class or inherited).
%
-spec get_all_base_attribute_names() ->
static_return( [ wooper:attribute_name() ] ).
get_all_base_attribute_names() ->
AttrNames =
wooper_introspection:get_class_specific_attribute_names( ?MODULE )
++ list_utils:flatten_once(
[ wooper_introspection:get_class_specific_attribute_names( C )
|| C <- ?superclasses ] ),
wooper:return_static( AttrNames ).
% @doc Sends all types of traces on behalf of a test, thus without requiring a
% class_TraceEmitter state.
%
% Uses the default trace aggregator, supposed to be already available and
% registered.
%
-spec send_from_test( trace_severity(), message() ) -> static_void_return().
send_from_test( TraceSeverity, Message ) ->
send_from_test( TraceSeverity, Message,
?default_test_emitter_categorization ),
wooper:return_static_void().
% @doc Sends all types of traces on behalf of a test, thus without requiring a
% class_TraceEmitter state.
%
% Uses the default trace aggregator, supposed to be already available and
% registered.
%
-spec send_from_test( trace_severity(), message(), emitter_categorization() ) ->
static_void_return().
send_from_test( TraceSeverity, Message, EmitterCategorization ) ->
% Follows the order of our trace format; oneway call:
case naming_utils:get_registered_pid_for( ?trace_aggregator_name,
?emitter_look_up_scope ) of
undefined ->
trace_utils:error( "class_TraceEmitter:send_from_test/3: "
"trace aggregator not found." ),
throw( trace_aggregator_not_found );
AggregatorPid ->
cond_utils:if_defined( traces_are_preformatted,
AggregatorPid ! { sendPreformatted, [
class_TraceAggregator:format_as_advanced_trace(
_TraceEmitterPid=self(),
_TraceEmitterName= <<"test">>,
_TraceEmitterCategorization=
text_utils:string_to_binary(
EmitterCategorization ),
_AppTimestamp=none,
_Time=time_utils:get_bin_textual_timestamp(),
% No State available here
_Location=net_utils:localnode_as_binary(),
_MessageCategorization=
?default_test_message_categorization,
_Priority=trace_utils:get_priority_for( TraceSeverity ),
_Message=text_utils:string_to_binary( Message ) ) ] },
AggregatorPid ! { send, [
_TraceEmitterPid=self(),
_TraceEmitterName= <<"test">>,
_TraceEmitterCategorization=
text_utils:string_to_binary( EmitterCategorization ),
_AppTimestamp=none,
_Time=time_utils:get_bin_textual_timestamp(),
% No State available here
_Location=net_utils:localnode_as_binary(),
_MessageCategorization=?default_test_message_categorization,
_Priority=trace_utils:get_priority_for( TraceSeverity ),
_Message=text_utils:string_to_binary( Message ) ] } )
end,
wooper:return_static_void().
% @doc Sends all types of traces on behalf of a case, thus without requiring a
% class_TraceEmitter state.
%
% Uses the default trace aggregator, supposed to be already available and
% registered.
%
-spec send_from_case( trace_severity(), message() ) -> static_void_return().
send_from_case( TraceSeverity, Message ) ->
send_from_case( TraceSeverity, Message,
?default_case_emitter_categorization ),
wooper:return_static_void().
% @doc Sends all types of traces on behalf of a case, thus without requiring a
% class_TraceEmitter state.
%
% Uses default trace aggregator, supposed to be already available and
% registered.
%
-spec send_from_case( trace_severity(), message(), emitter_categorization() ) ->
static_void_return().
send_from_case( TraceSeverity, Message, EmitterCategorization ) ->
% Follows the order of our trace format; oneway call:
case naming_utils:get_registered_pid_for( ?trace_aggregator_name,
?emitter_look_up_scope ) of
undefined ->
trace_utils:error( "class_TraceEmitter:send_from_case/3: "
"trace aggregator not found." ),
throw( trace_aggregator_not_found );
AggregatorPid ->
cond_utils:if_defined( traces_are_preformatted,
AggregatorPid ! { sendPreformatted, [
class_TraceAggregator:format_as_advanced_trace(
_TraceEmitterPid=self(),
_TraceEmitterName= <<"case">>,
_TraceEmitterCategorization=
text_utils:string_to_binary(
EmitterCategorization ),
_AppTimestamp=none,
_Time=time_utils:get_bin_textual_timestamp(),
% No State available here
_Location=net_utils:localnode_as_binary(),
_MessageCategorization=
?default_case_message_categorization,
_Priority=trace_utils:get_priority_for( TraceSeverity ),
_Message=text_utils:string_to_binary( Message ) ) ] },
AggregatorPid ! { send, [
_TraceEmitterPid=self(),
_TraceEmitterName= <<"case">>,
_TraceEmitterCategorization=
text_utils:string_to_binary( EmitterCategorization ),
_AppTimestamp=none,
_Time=time_utils:get_bin_textual_timestamp(),
% No State available here
_Location=net_utils:localnode_as_binary(),
_MessageCategorization=?default_case_message_categorization,
_Priority=trace_utils:get_priority_for( TraceSeverity ),
_Message=text_utils:string_to_binary( Message ) ] } )
end,
wooper:return_static_void().
% @doc Sends all types of traces without requiring a class_TraceEmitter state.
%
% Uses the default trace aggregator, supposed to be already available and
% registered.
%
-spec send_standalone( trace_severity(), message() ) -> static_void_return().
send_standalone( TraceSeverity, Message ) ->
send_standalone( TraceSeverity, Message,
?default_standalone_emitter_categorization ),
wooper:return_static_void().
% @doc Sends all types of traces without requiring a class_TraceEmitter state.
%
% Uses the default trace aggregator, supposed to be already available and
% registered.
%
-spec send_standalone( trace_severity(), message(),
emitter_categorization() ) -> static_void_return().
send_standalone( TraceSeverity, Message, EmitterCategorization ) ->
% Follows the order of our trace format; oneway call:
case naming_utils:get_registered_pid_for( ?trace_aggregator_name,
?emitter_look_up_scope ) of
undefined ->
trace_utils:error( "class_TraceEmitter:send_standalone/3: "
"trace aggregator not found." ),
throw( trace_aggregator_not_found );
AggregatorPid ->
PidName = get_emitter_name_from_pid(),
cond_utils:if_defined( traces_are_preformatted,
AggregatorPid ! { sendPreformatted, [
class_TraceAggregator:format_as_advanced_trace(
_TraceEmitterPid=self(),
_TraceEmitterName=
text_utils:string_to_binary( PidName ),
_TraceEmitterCategorization=
text_utils:string_to_binary(
EmitterCategorization ),
_AppTimestamp=none,
_Time=time_utils:get_bin_textual_timestamp(),
% No State available here
_Location=net_utils:localnode_as_binary(),
_MessageCategorization=
?default_standalone_message_categorization,
_Priority=trace_utils:get_priority_for( TraceSeverity ),
_Message=text_utils:string_to_binary( Message ) ) ] },
AggregatorPid ! { send, [
_TraceEmitterPid=self(),
_TraceEmitterName=text_utils:string_to_binary( PidName ),
_TraceEmitterCategorization=
text_utils:string_to_binary( EmitterCategorization ),
_AppTimestamp=none,
_Time=time_utils:get_bin_textual_timestamp(),
% No State available here
_Location=net_utils:localnode_as_binary(),
_MessageCategorization=
?default_standalone_message_categorization,
_Priority=trace_utils:get_priority_for( TraceSeverity ),
_Message=text_utils:string_to_binary( Message ) ] } )
end,
wooper:return_static_void().
% @doc Sends all types of traces without requiring a class_TraceEmitter state.
%
% Uses the default trace aggregator, supposed to be already available and
% registered.
%
-spec send_standalone( trace_severity(), message(), emitter_name(),
emitter_categorization() ) -> static_void_return().
send_standalone( TraceSeverity, Message, EmitterName, EmitterCategorization ) ->
send_standalone( TraceSeverity, Message, EmitterName, EmitterCategorization,
_MessageCategorization=uncategorized ),
wooper:return_static_void().
% @doc Sends all types of traces without requiring a class_TraceEmitter state.
%
% Uses the default trace aggregator, supposed to be already available and
% registered.
%
-spec send_standalone( trace_severity(), message(), emitter_name(),
emitter_categorization(), message_categorization() ) ->
static_void_return().
send_standalone( TraceSeverity, Message, EmitterName, EmitterCategorization,
MessageCategorization ) ->
% Follows the order of our trace format; oneway call:
case naming_utils:get_registered_pid_for( ?trace_aggregator_name,
?emitter_look_up_scope ) of
undefined ->
trace_utils:error( "class_TraceEmitter:send_standalone/5: "
"trace aggregator not found." ),
throw( trace_aggregator_not_found );
AggregatorPid ->
ActualMsgCateg = case is_atom( MessageCategorization ) of
true ->
MessageCategorization;
_False ->
text_utils:string_to_binary( MessageCategorization )
end,
cond_utils:if_defined( traces_are_preformatted,
AggregatorPid ! { sendPreformatted, [
class_TraceAggregator:format_as_advanced_trace(
_TraceEmitterPid=self(),
_TraceEmitterName=
text_utils:string_to_binary( EmitterName ),
_TraceEmitterCategorization=
text_utils:string_to_binary(
EmitterCategorization ),
_AppTimestamp=none,
_Time=time_utils:get_bin_textual_timestamp(),
% No State available here
_Location=net_utils:localnode_as_binary(),
_MessageCategorization=ActualMsgCateg,
_Priority=trace_utils:get_priority_for( TraceSeverity ),
_Message=text_utils:string_to_binary( Message ) ) ] },
AggregatorPid ! { send, [
_TraceEmitterPid=self(),
_TraceEmitterName=
text_utils:string_to_binary( EmitterName ),
_TraceEmitterCategorization=
text_utils:string_to_binary( EmitterCategorization ),
_AppTimestamp=none,
_Time=time_utils:get_bin_textual_timestamp(),
% No State available here
_Location=net_utils:localnode_as_binary(),
_MessageCategorization=ActualMsgCateg,
_Priority=trace_utils:get_priority_for( TraceSeverity ),
_Message=text_utils:string_to_binary( Message ) ] } )
end,
wooper:return_static_void().
% @doc Sends all types of traces without requiring a class_TraceEmitter state,
% in a safe manner (synchronously and, if their severity is error-like, echoed
% on the console).
%
% Uses the default trace aggregator, supposed to be already available and
% registered.
%
-spec send_standalone_safe( trace_severity(), message() ) ->
static_void_return().
send_standalone_safe( TraceSeverity, Message ) ->
EmitterCategorization = ?trace_emitter_categorization,
ApplicationTimestamp = time_utils:get_textual_timestamp(),
send_standalone_safe( TraceSeverity, Message, EmitterCategorization,
ApplicationTimestamp ),
wooper:return_static_void().
% @doc Sends all types of traces without requiring a class_TraceEmitter state,
% in a safe manner (synchronously and, if their severity is error-like, echoed
% on the console).
%
% Uses the default trace aggregator, supposed to be already available and
% registered.
%
-spec send_standalone_safe( trace_severity(), message(),
emitter_categorization() ) -> static_void_return().
send_standalone_safe( TraceSeverity, Message, EmitterCategorization ) ->
ApplicationTimestamp = time_utils:get_textual_timestamp(),
send_standalone_safe( TraceSeverity, Message, EmitterCategorization,
ApplicationTimestamp ),
wooper:return_static_void().
% @doc Sends all types of traces without requiring a class_TraceEmitter state,
% in a safe manner (synchronously and, if their severity is error-like, echoed
% on the console).
%
% Uses the default trace aggregator, supposed to be already available and
% registered.
%
-spec send_standalone_safe( trace_severity(), message(),
emitter_categorization(), app_timestamp() ) -> static_void_return().
send_standalone_safe( TraceSeverity, Message, EmitterCategorization,
ApplicationTimestamp ) ->
EmitterName = get_emitter_name_from_pid(),
send_standalone_safe( TraceSeverity, Message, EmitterName,
EmitterCategorization, ?default_standalone_message_categorization,
ApplicationTimestamp ),
wooper:return_static_void().
% @doc Sends all types of traces without requiring a class_TraceEmitter state,
% in a safe manner (synchronously and, if their severity is error-like, echoed
% on the console).
%
% Uses the default trace aggregator, supposed to be already available and
% registered.
%
-spec send_standalone_safe( trace_severity(), message(), emitter_name(),
emitter_categorization(), message_categorization() ) ->
static_void_return().
send_standalone_safe( TraceSeverity, Message, EmitterName,
EmitterCategorization, MessageCategorization ) ->
ApplicationTimestamp = time_utils:get_textual_timestamp(),