tinylog is an universal logging library for all kind of Java applications. There is no native support for context lookups as it is a specific Java EE feature. However, you can load your custom tinylog configuration at startup via a ServletContextListener.
@WebListener
public class LoggingInitializer implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
String stage = (String) new InitialContext().lookup("java:comp/env/stage");
String file = "tinylog_" + stage + ".properties";
Properties configuration = new Properties();
try (InputStream stream = classLoader.getResourceAsStream(file)) {
configuration.load(stream);
}
Configuration.replace((Map) configuration);
} catch (IOException | NamingException ex) {
Logger.error(ex, "Failed to load tinylog configuration");
}
}
public void contextDestroyed(ServletContextEvent event) { }
}
The stage can be set as environment variable in your context.xml:
<Context>
<Environment name="stage" value="PROD" type="java.lang.String" />
<!-- Other Settings -->
</Context>