46
46
import org .jboss .logmanager .handlers .FileHandler ;
47
47
import org .jboss .logmanager .handlers .PeriodicSizeRotatingFileHandler ;
48
48
import org .jboss .logmanager .handlers .SizeRotatingFileHandler ;
49
+ import org .jboss .logmanager .handlers .SocketHandler ;
49
50
import org .jboss .logmanager .handlers .SyslogHandler ;
50
51
51
52
import io .quarkus .bootstrap .logging .InitialConfigurator ;
63
64
import io .quarkus .runtime .logging .LogRuntimeConfig .CleanupFilterConfig ;
64
65
import io .quarkus .runtime .logging .LogRuntimeConfig .ConsoleConfig ;
65
66
import io .quarkus .runtime .logging .LogRuntimeConfig .FileConfig ;
67
+ import io .quarkus .runtime .logging .LogRuntimeConfig .SocketConfig ;
66
68
import io .quarkus .runtime .shutdown .ShutdownListener ;
67
69
import io .smallrye .config .SmallRyeConfig ;
68
70
import io .smallrye .config .SmallRyeConfigBuilder ;
@@ -116,7 +118,7 @@ public String getName() {
116
118
new LoggingSetupRecorder (new RuntimeValue <>(consoleRuntimeConfig )).initializeLogging (logRuntimeConfig ,
117
119
logBuildTimeConfig ,
118
120
DiscoveredLogComponents .ofEmpty (), emptyMap (), false , null , emptyList (), emptyList (), emptyList (), emptyList (),
119
- emptyList (), banner , LaunchMode .DEVELOPMENT , false );
121
+ emptyList (), emptyList (), banner , LaunchMode .DEVELOPMENT , false );
120
122
}
121
123
122
124
public ShutdownListener initializeLogging (
@@ -131,6 +133,7 @@ public ShutdownListener initializeLogging(
131
133
final List <RuntimeValue <Optional <Formatter >>> possibleConsoleFormatters ,
132
134
final List <RuntimeValue <Optional <Formatter >>> possibleFileFormatters ,
133
135
final List <RuntimeValue <Optional <Formatter >>> possibleSyslogFormatters ,
136
+ final List <RuntimeValue <Optional <Formatter >>> possibleSocketFormatters ,
134
137
final RuntimeValue <Optional <Supplier <String >>> possibleBannerSupplier ,
135
138
final LaunchMode launchMode ,
136
139
final boolean includeFilters ) {
@@ -211,6 +214,14 @@ public void close() throws SecurityException {
211
214
}
212
215
}
213
216
217
+ if (config .socket ().enable ()) {
218
+ final Handler socketHandler = configureSocketHandler (config .socket (), errorManager , cleanupFiler ,
219
+ namedFilters , possibleSocketFormatters , includeFilters );
220
+ if (socketHandler != null ) {
221
+ handlers .add (socketHandler );
222
+ }
223
+ }
224
+
214
225
if ((launchMode .isDevOrTest () || enableWebStream )
215
226
&& streamingDevUiConsoleHandler != null
216
227
&& streamingDevUiConsoleHandler .getValue ().isPresent ()) {
@@ -229,7 +240,7 @@ public void close() throws SecurityException {
229
240
230
241
Map <String , Handler > namedHandlers = shouldCreateNamedHandlers (config , additionalNamedHandlers )
231
242
? createNamedHandlers (config , consoleRuntimeConfig .getValue (), additionalNamedHandlers ,
232
- possibleConsoleFormatters , possibleFileFormatters , possibleSyslogFormatters ,
243
+ possibleConsoleFormatters , possibleFileFormatters , possibleSyslogFormatters , possibleSocketFormatters ,
233
244
errorManager , cleanupFiler , namedFilters , launchMode ,
234
245
shutdownNotifier , includeFilters )
235
246
: emptyMap ();
@@ -328,7 +339,7 @@ public static void initializeBuildTimeLogging(
328
339
}
329
340
330
341
Map <String , Handler > namedHandlers = createNamedHandlers (config , consoleConfig , emptyList (),
331
- emptyList (), emptyList (), emptyList (), errorManager , logCleanupFilter ,
342
+ emptyList (), emptyList (), emptyList (), emptyList (), errorManager , logCleanupFilter ,
332
343
emptyMap (), launchMode , dummy , false );
333
344
334
345
setUpCategoryLoggers (buildConfig , categoryDefaultMinLevels , categories , logContext , errorManager , namedHandlers );
@@ -388,6 +399,7 @@ private static Map<String, Handler> createNamedHandlers(
388
399
List <RuntimeValue <Optional <Formatter >>> possibleConsoleFormatters ,
389
400
List <RuntimeValue <Optional <Formatter >>> possibleFileFormatters ,
390
401
List <RuntimeValue <Optional <Formatter >>> possibleSyslogFormatters ,
402
+ List <RuntimeValue <Optional <Formatter >>> possibleSocketFormatters ,
391
403
ErrorManager errorManager , LogCleanupFilter cleanupFilter ,
392
404
Map <String , Filter > namedFilters , LaunchMode launchMode ,
393
405
ShutdownNotifier shutdownHandler , boolean includeFilters ) {
@@ -422,6 +434,17 @@ private static Map<String, Handler> createNamedHandlers(
422
434
addToNamedHandlers (namedHandlers , syslogHandler , sysLogConfigEntry .getKey ());
423
435
}
424
436
}
437
+ for (Entry <String , SocketConfig > socketConfigEntry : config .socketHandlers ().entrySet ()) {
438
+ SocketConfig namedSocketConfig = socketConfigEntry .getValue ();
439
+ if (!namedSocketConfig .enable ()) {
440
+ continue ;
441
+ }
442
+ final Handler socketHandler = configureSocketHandler (namedSocketConfig , errorManager , cleanupFilter ,
443
+ namedFilters , possibleSocketFormatters , includeFilters );
444
+ if (socketHandler != null ) {
445
+ addToNamedHandlers (namedHandlers , socketHandler , socketConfigEntry .getKey ());
446
+ }
447
+ }
425
448
426
449
Map <String , Handler > additionalNamedHandlersMap ;
427
450
if (additionalNamedHandlers .isEmpty ()) {
@@ -770,6 +793,53 @@ private static Handler configureSyslogHandler(final LogRuntimeConfig.SyslogConfi
770
793
}
771
794
}
772
795
796
+ private static Handler configureSocketHandler (final LogRuntimeConfig .SocketConfig config ,
797
+ final ErrorManager errorManager ,
798
+ final LogCleanupFilter logCleanupFilter ,
799
+ final Map <String , Filter > namedFilters ,
800
+ final List <RuntimeValue <Optional <Formatter >>> possibleSocketFormatters ,
801
+ final boolean includeFilters ) {
802
+ try {
803
+ final SocketHandler handler = new SocketHandler (config .endpoint ().getHostString (), config .endpoint ().getPort ());
804
+ handler .setProtocol (config .protocol ());
805
+ handler .setBlockOnReconnect (config .blockOnReconnect ());
806
+ handler .setLevel (config .level ());
807
+
808
+ Formatter formatter = null ;
809
+ boolean formatterWarning = false ;
810
+ for (RuntimeValue <Optional <Formatter >> value : possibleSocketFormatters ) {
811
+ if (formatter != null ) {
812
+ formatterWarning = true ;
813
+ }
814
+ final Optional <Formatter > val = value .getValue ();
815
+ if (val .isPresent ()) {
816
+ formatter = val .get ();
817
+ }
818
+ }
819
+ if (formatter == null ) {
820
+ formatter = new PatternFormatter (config .format ());
821
+ }
822
+ handler .setFormatter (formatter );
823
+
824
+ handler .setErrorManager (errorManager );
825
+ handler .setFilter (logCleanupFilter );
826
+ applyFilter (includeFilters , errorManager , logCleanupFilter , config .filter (), namedFilters , handler );
827
+
828
+ if (formatterWarning ) {
829
+ handler .getErrorManager ().error ("Multiple socket formatters were activated" , null ,
830
+ ErrorManager .GENERIC_FAILURE );
831
+ }
832
+
833
+ if (config .async ().enable ()) {
834
+ return createAsyncHandler (config .async (), config .level (), handler );
835
+ }
836
+ return handler ;
837
+ } catch (IOException e ) {
838
+ errorManager .error ("Failed to create socket handler" , e , ErrorManager .OPEN_FAILURE );
839
+ return null ;
840
+ }
841
+ }
842
+
773
843
private static AsyncHandler createAsyncHandler (LogRuntimeConfig .AsyncConfig asyncConfig , Level level , Handler handler ) {
774
844
final AsyncHandler asyncHandler = new AsyncHandler (asyncConfig .queueLength ());
775
845
asyncHandler .setOverflowAction (asyncConfig .overflow ());
0 commit comments