class LoggingService {

    public static void setupLogger() throws IOException {
        int maxFileSize = (int) (Configuration.getLogDiskLimit() * Constants.MiB);
        int logFileCount = Configuration.getLogFileCount();
        String logLevel = Configuration.getLogLevel().toUpperCase();
        final File logDirectory = new File(Configuration.getLogDiskDirectory());

        logDirectory.mkdirs();

        final String logFilePattern = logDirectory.getPath() + "/iofog-agent.%g.log";

        if (logger != null) {
            for (Handler f : logger.getHandlers())
                f.close();
        }

        if (maxFileSize < Constants.MiB) {
            System.out.println("[" + MODULE_NAME + "] Warning: current <log_disk_consumption_limit>" +
                    " config parameter's value is negative, using default 1 Mb limit");
            maxFileSize = Constants.MiB;
        }

        if (logFileCount < 1) {
            System.out.println("[" + MODULE_NAME + "] Warning: current <log_file_count> config parameter's" +
                    " value is below l, using default 1 log file value");
            logFileCount = 1;
        }

        long limit = (maxFileSize / logFileCount) * 1_000L;
        if (limit > Integer.MAX_VALUE) {
            System.out.println("[" + MODULE_NAME + "] Warning: current <log_disk_consumption_limit> config parameter's" +
                    " value is above 2GB, using max 2GB value");
            limit = 2L * Constants.MiB * 1_000L;
        }

        int intLimit = (int) limit;

        Handler logFileHandler = new FileHandler(logFilePattern, intLimit, logFileCount);

        logFileHandler.setFormatter(new LogFormatter());

        logger = Logger.getLogger("org.eclipse.iofog");
        logger.addHandler(logFileHandler);

        logger.setUseParentHandlers(false);
        // Disabling the log level off
        logger.setLevel(Level.parse(logLevel).equals(Level.OFF) ? Level.INFO : Level.parse(logLevel));

        logger.info("main, Logging Service, logger started.");

        loadSentryCache();
    }

    private  LoggingService();

}