params) throws JsonProcessingException
147 | {
148 | return OBJECT_MAPPER.writer().writeValueAsString(params);
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/src/main/java/com/nixsolutions/logging/common/WordUtils.java:
--------------------------------------------------------------------------------
1 | package com.nixsolutions.logging.common;
2 |
3 | import static org.apache.commons.lang3.StringUtils.EMPTY;
4 | import static org.apache.commons.lang3.text.WordUtils.capitalizeFully;
5 | import static org.apache.commons.lang3.text.WordUtils.uncapitalize;
6 | import java.text.BreakIterator;
7 | import org.apache.commons.lang3.StringUtils;
8 |
9 | public class WordUtils
10 | {
11 | /**
12 | * Truncate string on closest word boundary.
13 | *
14 | *
15 | * WordUtils.truncateWithWordBoundary(null, *) = ""
16 | * WordUtils.truncateWithWordBoundary(*, 0) = ""
17 | * WordUtils.truncateWithWordBoundary(*, -1) = ""
18 | * WordUtils.truncateWithWordBoundary("abc", 5) = "abc"
19 | * WordUtils.truncateWithWordBoundary("abc dfe", 5) = "abc"
20 | * WordUtils.truncateWithWordBoundary("abc,:;dfc", 5) = "abc
21 | *
22 | *
23 | * @param string - the String to be truncated, may be null
24 | * @param maxLength - max length of truncated string
25 | * @return same string if string length less then max length or truncated string
26 | */
27 | public static String truncateWithWordBoundary(String string, int maxLength)
28 | {
29 | if (StringUtils.isBlank(string) || maxLength <= 0)
30 | {
31 | return EMPTY;
32 | }
33 |
34 | if (string.length() < maxLength)
35 | {
36 | return string;
37 | }
38 |
39 | BreakIterator breakIterator = BreakIterator.getWordInstance();
40 | breakIterator.setText(string);
41 |
42 | int currentWordStart = breakIterator.preceding(maxLength);
43 |
44 | return string.substring(0, breakIterator.following(currentWordStart - 2));
45 | }
46 |
47 | /**
48 | * Converts {@code sourceString} to a camelCase string using {@code delimiters}
49 | * Examples:
50 | *
51 | * - toCamelCase("Load renewal"," ") - loadRenewal
52 | * - toCamelCase("Load renewal! Now"," !") - loadRenewalNow
53 | * - toCamelCase("Load ReNEwaL"," ") - loadRenewal
54 | * - toCamelCase("Loadrenewal","") - loadrenewal
55 | *
56 | *
57 | * @param sourceString
58 | * @param delimiters - delimiters in a single string
59 | */
60 | public static String toCamelCase(String sourceString, String delimiters)
61 | {
62 | String result = capitalizeFully(sourceString, delimiters.toCharArray());
63 | for (String delimiter : delimiters.split(EMPTY))
64 | {
65 | result = result.replaceAll(delimiter, EMPTY);
66 | }
67 | return uncapitalize(result);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/nixsolutions/logging/configuration/ContextExtractorFactoryConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.nixsolutions.logging.configuration;
2 |
3 | import static java.util.Collections.EMPTY_MAP;
4 | import java.util.List;
5 | import java.util.Map;
6 | import java.util.Objects;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.context.annotation.Configuration;
11 | import com.nixsolutions.logging.parameters.extractor.ContextParamExtractor;
12 | import com.nixsolutions.logging.parameters.extractor.ContextParamExtractorFactory;
13 |
14 | @Configuration
15 | public class ContextExtractorFactoryConfiguration
16 | {
17 | private static final ContextParamExtractor