|
1 | 1 | package org.schabi.newpipe.extractor.utils; |
2 | 2 |
|
| 3 | +/** |
| 4 | + * Logging class for outputting logs from the extractor to the desired output<br><br> |
| 5 | + * Intended to be used in the same manner as Android's {@code Log}:<br> |
| 6 | + * {@code ExtractorLogger.d("Hello my name Jeff")}<br> |
| 7 | + * <br> |
| 8 | + * Also supports formatted arguments:<br> |
| 9 | + * {@code ExtractorLogger.d("Hello my name is {Name} {}", name, surname)} |
| 10 | + */ |
3 | 11 | public final class ExtractorLogger { |
4 | 12 |
|
5 | 13 | private ExtractorLogger() { } |
6 | 14 |
|
7 | 15 | private static final Logger EMPTY_LOGGER = new EmptyLogger(); |
8 | 16 | private static volatile Logger logger = EMPTY_LOGGER; |
9 | 17 |
|
| 18 | + /** |
| 19 | + * Set the Logger that you want the extractor logs to be logged to |
| 20 | + * <br> |
| 21 | + * Provide an implementation of the {@code Logger} interface for each method and whenever the |
| 22 | + * extractor code calls {@code ExtractorLogger.d/w/e} |
| 23 | + * it will be routed through to {@code customLogger} |
| 24 | + * <br> |
| 25 | + * <br> |
| 26 | + * For NewPipe, this should be set at the start of the application ideally in |
| 27 | + * {@code MainActivity.onCreate}, but absolutely before any extractor code can run |
| 28 | + */ |
10 | 29 | public static void setLogger(final Logger customLogger) { |
11 | 30 | logger = customLogger != null ? customLogger : EMPTY_LOGGER; |
12 | 31 | } |
@@ -44,6 +63,9 @@ private static void log(final Level level, |
44 | 63 | } |
45 | 64 | } |
46 | 65 |
|
| 66 | + /*** |
| 67 | + * Internal method for logging with formatting |
| 68 | + */ |
47 | 69 | @SuppressWarnings("checkstyle:NeedBraces") |
48 | 70 | private static void logFormat(final Level level, |
49 | 71 | final String tag, |
|
0 commit comments