Configuration and loggging
parent
d35a0e630c
commit
6bc355b9ac
@ -0,0 +1,2 @@
|
||||
# Bot display name
|
||||
general.bot_name = DCF-enabled Bot
|
@ -1,2 +1,2 @@
|
||||
rootProject.name = 'dcm'
|
||||
rootProject.name = 'dcf'
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
package net.pingex.dcf;
|
||||
|
||||
import net.pingex.dcf.core.Configuration;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Main class for DCF
|
||||
*/
|
||||
public class DiscordCommandableFramework
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger(DiscordCommandableFramework.class);
|
||||
|
||||
/**
|
||||
* Main entry point
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
LOGGER.info("Hello World");
|
||||
Configuration.load();
|
||||
Configuration.init();
|
||||
|
||||
LOGGER.info("I'm " + Configuration.BOT_NAME);
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package net.pingex.dcf.core;
|
||||
|
||||
import org.apache.commons.configuration2.ConfigurationUtils;
|
||||
import org.apache.commons.configuration2.FileBasedConfiguration;
|
||||
import org.apache.commons.configuration2.ImmutableConfiguration;
|
||||
import org.apache.commons.configuration2.PropertiesConfiguration;
|
||||
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
|
||||
import org.apache.commons.configuration2.builder.fluent.Parameters;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Configuration manager
|
||||
*/
|
||||
public class Configuration
|
||||
{
|
||||
/**
|
||||
* File name to look for
|
||||
*/
|
||||
private static final String FILENAME = "dcf.properties";
|
||||
private static final Logger LOGGER = LogManager.getLogger(Configuration.class);
|
||||
|
||||
/**
|
||||
* Main configuration store
|
||||
*/
|
||||
private static org.apache.commons.configuration2.Configuration store;
|
||||
|
||||
/**
|
||||
* Load configuration file
|
||||
*/
|
||||
public static void load()
|
||||
{
|
||||
try
|
||||
{
|
||||
LOGGER.info("Loading configuration file");
|
||||
store = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
|
||||
.configure(new Parameters().fileBased().setFileName(FILENAME))
|
||||
.getConfiguration();
|
||||
} catch (ConfigurationException e)
|
||||
{
|
||||
LOGGER.fatal("Failed to load configuration", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the store in read-only mode
|
||||
* @return The read-only store
|
||||
*/
|
||||
public static ImmutableConfiguration getStore()
|
||||
{
|
||||
return ConfigurationUtils.unmodifiableConfiguration(store);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
|
||||
/**
|
||||
* Bot display name
|
||||
*/
|
||||
public static String BOT_NAME = "DCF-enabled Bot";
|
||||
|
||||
|
||||
/**
|
||||
* Load config keys
|
||||
*/
|
||||
public static void init()
|
||||
{
|
||||
BOT_NAME = store.getString("general.bot_name", BOT_NAME);
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Very core components: configuration, handlers, and so on
|
||||
*/
|
||||
package net.pingex.dcf.core;
|
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Main package of DCF, contains everything to make it run !
|
||||
*/
|
||||
package net.pingex.dcf;
|
@ -0,0 +1,9 @@
|
||||
name = LoggingConfig
|
||||
|
||||
appender.console.type = Console
|
||||
appender.console.name = STDOUT
|
||||
appender.console.layout.type = PatternLayout
|
||||
appender.console.layout.pattern = %d{dd/MM/yyyy HH:mm:ss} [%t/%p] %c:%M - %m%n
|
||||
|
||||
rootLogger.level = info
|
||||
rootLogger.appenderRef.stdout.ref = STDOUT
|
Reference in New Issue