| 42 | import java.util.concurrent.*; |
| 43 | |
| 44 | public class Main { |
| 45 | static { |
| 46 | // ChatGPT wrote most of this logging config. Tested, tweaked, and overall looks fine |
| 47 | File logDir = LogConfigVars.getFile(LogConfigVars.LOG_DIR); |
| 48 | if (!logDir.exists() && !logDir.mkdirs()) { |
| 49 | throw new IllegalStateException("Could not create log directory: " + logDir.getAbsolutePath()); |
| 50 | } |
| 51 | |
| 52 | Configuration.set("writer", "console"); |
| 53 | Configuration.set("writer.level", LogConfigVars.getLogMode(LogConfigVars.LOG_MODE).name().toLowerCase()); |
| 54 | Configuration.set("writer.format", "{date: HH:mm:ss.SSS} [{level}] {message}"); |
| 55 | Configuration.set("writer.stream", "err@WARN"); |
| 56 | |
| 57 | Configuration.set("writer2", "rolling file"); |
| 58 | Configuration.set("writer2.level", "trace"); |
| 59 | Configuration.set("writer2.format", "{date: yyyy-MM-dd HH:mm:ss.SSS} {class}.{method}() [{level}] {message}"); |
| 60 | Configuration.set("writer2.file", new File(logDir, "fetcharr-{date:yyyy-MM-dd}-{count}.log").getAbsolutePath()); |
| 61 | Configuration.set("writer2.latest", new File(logDir, "fetcharr-latest.log").getAbsolutePath()); |
| 62 | Configuration.set("writer2.charset", "UTF-8"); |
| 63 | Configuration.set("writer2.buffered", "true"); |
| 64 | Configuration.set("writer2.policies", "daily, size: 25mb"); |
| 65 | Configuration.set("writer2.convert", "gzip"); |
| 66 | Configuration.set("writer2.backups", "30"); |
| 67 | |
| 68 | Configuration.set("writingthread", "true"); |
| 69 | } |
| 70 | |
| 71 | private static final Logger LOGGER = LoggerFactory.getLogger(Main.class); |
| 72 | |
| 73 | private static volatile boolean running = true; |
| 74 | |
| 75 | public static void main(String[] args) { |
| 76 | LOGGER.info("Starting.."); |
| 77 | LOGGER.info("Logging mode set to {}", LogConfigVars.getLogMode(LogConfigVars.LOG_MODE).name()); |
| 78 | LOGGER.info("Thread pool size set to {}", Math.max(4, Runtime.getRuntime().availableProcessors() / 2)); // This math is actually done in FetcharrAPIImpl |
| 79 | |
| 80 | Tristate memoryCache = CacheConfigVars.getTristate(CacheConfigVars.USE_MEMORY_CACHE); |
| 81 | Tristate fileCache = CacheConfigVars.getTristate(CacheConfigVars.USE_FILE_CACHE); |
| 82 | boolean cacheWritable = isCacheWritable(); |
| 83 | |
| 84 | if ((fileCache == Tristate.AUTO && cacheWritable) || fileCache == Tristate.TRUE) { |
| 85 | LOGGER.info("Using disk-based cache"); |
| 86 | } else { |
| 87 | LOGGER.warn("Not using disk-based cache"); |
| 88 | } |
| 89 | if ((memoryCache == Tristate.AUTO && fileCache == Tristate.AUTO && !cacheWritable) || (memoryCache == Tristate.AUTO && fileCache == Tristate.FALSE) || memoryCache == Tristate.TRUE) { |
| 90 | LOGGER.info("Using memory-based cache"); |
| 91 | } else { |
| 92 | LOGGER.info("Not using memory-based cache"); |
| 93 | } |
| 94 | |
| 95 | setupUnirest(); |
| 96 | |
| 97 | LOGGER.info("---"); |
| 98 | |
| 99 | try { |
| 100 | Thread.sleep(3_000); |
| 101 | } catch (InterruptedException ignored) { |
nothing calls this directly
no test coverage detected