@@ -21,6 +21,7 @@ This repository is the cornerstone of BBData. It contains:
2121 * [ Executing the jar] ( #executing-the-jar )
2222 * [ Caching] ( #caching )
2323 * [ Async] ( #async )
24+ * [ Logging] ( #logging )
2425 * [ Monitoring] ( #monitoring )
2526- [ Permission system] ( #permission-system )
2627- [ Actuators] ( #actuators )
@@ -150,6 +151,12 @@ java -jar bbdata-api-*.jar
150151java -Dspring.profiles.active=unsecured,noc -jar bbdata-api-* .jar
151152```
152153
154+ If you want to use a properties file that do not match the default names (e.g. ` development.properties ` ),
155+ set the ` spring.config.additional-location ` (so it is loaded * alongside* and not * instead of* the default properties):
156+ ``` bash
157+ ./bbdata-api-* .jar --spring.config.additional-location=development.properties
158+ ```
159+
153160### Caching
154161
155162Caching is interesting in one part of the application, namely the input endpoint ` POST /values ` .
@@ -210,6 +217,100 @@ in this repo for default values). You can of course override any of those in you
210217
211218If you want to ** TURN OFF** asynchronous processing, simply set the custom property ` async.enabled=false ` .
212219
220+ ### Logging
221+
222+ * NOTE* : in the default application.properties, I set the following, wich removes the spring banner, forces the
223+ use of ansi colors, so the output is highlighted even when using ` tee ` and always log resolved exceptions
224+ (feel free to change them if you need to):
225+ ``` properties
226+ spring.main.banner-mode =off
227+ spring.output.ansi.enabled =ALWAYS
228+ spring.mvc.log-resolved-exception =true
229+ ```
230+
231+ By default, Spring Boot uses logback. Here are some relevant links and resources:
232+
233+ * [ Spring Boot: How-to logging] ( https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-logging )
234+ * [ Spring Boot: logback src files] ( https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback )
235+ * [ Logback layouts] ( http://logback.qos.ch/manual/layouts.html )
236+ * [ Logback syslogAppender] ( http://logback.qos.ch/manual/appenders.html#SyslogAppender )
237+
238+ Typically, in production you want to save everything to a rolling file, and maybe use syslog. You also want to be
239+ able to change the logging configuration without restarting the app. Here is an example on how to achieve that:
240+ ``` xml
241+ <?xml version =" 1.0" encoding =" UTF-8" ?>
242+ <!-- FILE: logback-spring.xml -->
243+ <!-- scan and scanPeriod define if and how often this configuration should be scanned for change at runtime -->
244+ <configuration scan =" true" scanPeriod =" 1 minutes" >
245+
246+ <!-- override default springboot properties -->
247+ <!-- To see which are available, scan throught the files at
248+ https://github.com/spring-projects/spring-boot/tree/master/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback -->
249+ <property name =" LOG_FILE" value =" ./logs/bbdata-api.log" />
250+ <property name =" LOG_EXCEPTION_CONVERSION_WORD" value =" %rEx{5}" />
251+
252+ <!-- use Spring default values, making CONSOLE and FILE readily available -->
253+ <include resource =" org/springframework/boot/logging/logback/base.xml" />
254+
255+ <!-- Add syslog logging TODO: ensure you change the host and port ! -->
256+ <appender name =" SYSLOG" class =" ch.qos.logback.classic.net.SyslogAppender" >
257+ <syslogHost >127.0.0.1</syslogHost >
258+ <facility >SYSLOG</facility >
259+ <port >514</port >
260+ <throwableExcluded >false</throwableExcluded >
261+ <!-- <suffixPattern>bbdata %m thread:%t priority:%p category:%c exception:%exception</suffixPattern>-->
262+ <suffixPattern >bbdata: %p [%logger, %t] %m%n${LOG_EXCEPTION_CONVERSION_WORD}</suffixPattern >
263+ </appender >
264+
265+ <!-- LOG everything at INFO level -->
266+ <root level =" info" >
267+ <appender-ref ref =" CONSOLE" />
268+ <appender-ref ref =" FILE" />
269+ <appender-ref ref =" SYSLOG" />
270+ </root >
271+
272+ <!-- LOG app at TRACE level -->
273+ <logger name =" ch.derlin.bbdata" level =" trace" additivity =" false" >
274+ <appender-ref ref =" CONSOLE" />
275+ <appender-ref ref =" FILE" />
276+ <appender-ref ref =" SYSLOG" />
277+ </logger >
278+
279+ </configuration >
280+ ```
281+
282+ In order to load this configuration at runtime, use the option ` logging.config ` , for example:
283+ ``` bash
284+ # either using java
285+ java -jar -Dlogging.config=logback-spring.xml
286+ # or executing the jar directly
287+ ./bbdata-api-* .jar --logging.config=logback-spring.xml
288+ ```
289+
290+ ** rsyslog configuration**
291+
292+ When using ** SYSLOG** , you need a server with ` rsyslog ` running.
293+ To allow incoming udp requests, define the following in ` /etc/rsyslog.conf ` :
294+ ```
295+ $ModLoad imudp
296+ $UDPServerRun 514
297+ ```
298+
299+ To filter everything from bbdata create a file ` /etc/rsyslog.conf/10-bbdata.conf ` and add the following:
300+ ```
301+ if $programname == 'bbdata' then /var/log/bbdata.log
302+ & stop
303+ ```
304+ The rule will match any log beginning with ` bbdata: ` (the default * TAG* defined in SYSLOG, see ` <suffixPattern>TAG: ... ` ).
305+
306+ It is also possible to put the rule directly in ` rsyslog.conf ` _ at the beginning_ of the rules.
307+ If you put it at the end, everything will be logged in ` messages ` as well.
308+
309+ To deal with tabs, new lines and special characters, also define the following property in ` /etc/rsyslog.conf ` :
310+ ```
311+ $EscapeControlCharactersOnReceive off
312+ ```
313+
213314### Monitoring
214315
215316See [ Spring Boot Admin] ( #management-interface-spring-boot-admin ) .
0 commit comments