public class Setup extends Object
An instance of this class is passed into Sirius.start(Setup)
to launch the framework. Alternatively
createAndStartEnvironment(ClassLoader)
can be called which configures and starts SIRIUS based on
system properties. This is utilized by the sirius-ipl framework which provides an application container
(effectively a main class and some control scripts to make it behave like a daemon or Windows Service).
To further customize settings, subclass and override the appropriate methods.
By default, this class does the following:
Modifier and Type | Class and Description |
---|---|
static class |
Setup.Mode
Determines the mode in which the framework should run.
|
Modifier and Type | Field and Description |
---|---|
protected String |
consoleLogFormat |
protected org.apache.log4j.Level |
defaultLevel |
protected String |
fileLogFormat |
protected ClassLoader |
loader |
protected boolean |
logToConsole |
protected boolean |
logToFile |
protected Setup.Mode |
mode |
Constructor and Description |
---|
Setup(Setup.Mode mode,
ClassLoader loader)
Creates a new setup for the given mode and class loader.
|
Modifier and Type | Method and Description |
---|---|
com.typesafe.config.Config |
applyDeveloperConfig(com.typesafe.config.Config config)
Applies the developer configuration to the given config object.
|
com.typesafe.config.Config |
applyTestConfig(com.typesafe.config.Config config)
Applies the test configuration to the given config object.
|
com.typesafe.config.Config |
applyTestScenarioConfig(String scenarioFile,
com.typesafe.config.Config config)
Loads the configuration of the current test scenario which will overwrite the settings
in test.conf.
|
void |
cleanOldLogFiles(long retentionInMillis)
Invoked by Sirius itself on a regular basis to clean old log files.
|
static void |
createAndStartEnvironment(ClassLoader loader)
Creates and starts a new setup based on system properties.
|
long |
estimateLogFilesSize()
Estimates the total size of all log files.
|
ClassLoader |
getLoader()
Returns the loader to use for component discovery.
|
protected String |
getLogFileName()
Returns the name of the log file.
|
protected String |
getLogFilePath()
Computes the effective name for the log file.
|
protected String |
getLogsDirectory()
Returns the name of the log directory.
|
Setup.Mode |
getMode()
Returns the mode the framework was started in.
|
protected static Value |
getProperty(String property)
Reads the given system property.
|
void |
init()
Initializes the Virtual Machine.
|
com.typesafe.config.Config |
loadApplicationConfig()
Loads the main application configuration which is shipped with the app.
|
com.typesafe.config.Config |
loadInstanceConfig()
Loads the instance configuration which configures the app for the machine it is running on.
|
static void |
main(String[] args)
Provides a main method for debugging purposes.
|
protected void |
outputJVMInfo()
Outputs the name of the underlying JVM to verify that the correct one was used to start the application
|
protected void |
redirectJavaLoggerToLog4j()
Redirects all java.logging output to Log4j
|
protected void |
setupDNSCache()
Sets the DNS cache to a sane value.
|
protected void |
setupEncoding()
Sets UTF-8 as default encoding
|
protected void |
setupLogging()
Initializes log4j as logging framework.
|
protected boolean |
shouldLogToConsole()
Determines if a console appender should be installed
|
protected boolean |
shouldLogToFile()
Determines if a file appender should be installed
|
Setup |
withConsoleLogFormat(String format)
Specifies the pattern used to format log messages in the console.
|
Setup |
withDefaultLogLevel(org.apache.log4j.Level level)
Used to set the default log level used by the root logger.
|
Setup |
withFileLogFormat(String format)
Specifies the pattern used to format log messages in the log file.
|
Setup |
withLogToConsole(boolean flag)
Overwrites the settings for the console appender.
|
Setup |
withLogToFile(boolean flag)
Overwrites the settings for the file appender.
|
protected ClassLoader loader
protected Setup.Mode mode
protected boolean logToConsole
protected boolean logToFile
protected org.apache.log4j.Level defaultLevel
protected String consoleLogFormat
protected String fileLogFormat
public Setup(Setup.Mode mode, ClassLoader loader)
mode
- the mode to run the framework inloader
- the class loader used for component discoverypublic Setup withLogToConsole(boolean flag)
flag
- determines if logging to the console is enabled or not.public Setup withLogToFile(boolean flag)
flag
- determines if logging to the log file is enabled or not.public Setup withDefaultLogLevel(org.apache.log4j.Level level)
Note that each logger can be configured by specifying logging.[NAME] in the system configuration
level
- the level to usepublic Setup withConsoleLogFormat(String format)
Refer to PatternLayout
for available options.
format
- the template string to usepublic Setup withFileLogFormat(String format)
Refer to PatternLayout
for available options.
format
- the template string to usepublic static void createAndStartEnvironment(ClassLoader loader)
Essentially this is debug which switches from PROD to DEV and console which enables log output to the console even if running in PROD mode.
loader
- the class loader to usepublic static void main(String[] args)
args
- the command line arguments (currently ignored)public void init()
This modifies the DNS cache, encoding and logging setup...
This method is automatically called by Sirius.start(Setup)
protected void outputJVMInfo()
public ClassLoader getLoader()
public Setup.Mode getMode()
protected void setupEncoding()
protected void setupDNSCache()
By default java infinitely caches all DNS entries. Will be changed to 10 seconds...
protected static Value getProperty(String property)
property
- the property to readValue
protected void setupLogging()
In development mode, we log everything to the console. In production mode, we use a rolling file appender and log into the logs directory.
protected String getLogsDirectory()
protected String getLogFilePath()
public void cleanOldLogFiles(long retentionInMillis)
retentionInMillis
- the desired retention time in milli seconds before a file is deleted.public long estimateLogFilesSize()
protected String getLogFileName()
protected boolean shouldLogToConsole()
protected boolean shouldLogToFile()
protected void redirectJavaLoggerToLog4j()
@Nonnull public com.typesafe.config.Config loadApplicationConfig()
By default this loads "application.conf" from the classpath. Also "application-*.conf are loaded in case it is splitted into several parts.
@Nonnull public com.typesafe.config.Config applyTestConfig(@Nonnull com.typesafe.config.Config config)
By default this loads and applies "test.conf" from the classpath.
config
- the config to enhance@Nonnull public com.typesafe.config.Config applyTestScenarioConfig(@Nullable String scenarioFile, @Nonnull com.typesafe.config.Config config)
scenarioFile
- the scenario config file to loadconfig
- the config to enhance@Nonnull public com.typesafe.config.Config applyDeveloperConfig(@Nonnull com.typesafe.config.Config config)
By default this loads and applies "develop.conf" from the file system.
config
- the config to enhance@Nullable public com.typesafe.config.Config loadInstanceConfig()
By default this loads "instance.conf" from the file system
This will later be applied to the overall system configuration and will override all other settings.
Copyright © 2018. All rights reserved.