本文整理匯總了Java中org.apache.logging.log4j.core.config.Configurator類的典型用法代碼示例。如果您正苦於以下問題:Java Configurator類的具體用法?Java Configurator怎麽用?Java Configurator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Configurator類屬於org.apache.logging.log4j.core.config包,在下文中一共展示了Configurator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: configureLogging
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
private void configureLogging(LogLevel logLevel) {
Level log4jLogLevel;
switch (Objects.requireNonNull(logLevel)) {
case NORMAL: {
log4jLogLevel = Level.INFO;
break;
}
case VERBOSE: {
log4jLogLevel = Level.DEBUG;
break;
}
case TRACE: {
log4jLogLevel = Level.TRACE;
break;
}
default: {
throw new IllegalArgumentException("Unknown log level: " + logLevel.name());
}
}
Configurator.setLevel("bt", log4jLogLevel);
}
示例2: initLog4j
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
private static void initLog4j() {
String log4jConfigFolderPath = System.getProperty("motu-config-dir");
if (log4jConfigFolderPath != null && log4jConfigFolderPath.length() > 0) {
if (!log4jConfigFolderPath.endsWith("/")) {
log4jConfigFolderPath += "/";
}
} else {
System.err.println("Error while initializing log4j. Property is not set motu-config-dir or has a bad value");
}
// Do not use system property to avoid conflicts with other tomcat webapps
// System.setProperty("log4j.configurationFile", log4jConfigFolderPath + "log4j.xml");
try {
ConfigurationSource source = new ConfigurationSource(new FileInputStream(log4jConfigFolderPath + "log4j.xml"));
Configurator.initialize(null, source);
} catch (IOException e) {
System.err.println("Error while initializing log4j from file: " + log4jConfigFolderPath + "log4j.xml");
e.printStackTrace();
}
}
示例3: setUp
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
Configurator
.initialize("FastMQ", Thread.currentThread().getContextClassLoader(), "log4j2.xml");
Log log = new Log();
LogSegment logSegment = new LogSegment();
logSegment.setLedgerId(ledgerId);
logSegment.setTimestamp(System.currentTimeMillis());
log.setSegments(Collections.singletonList(logSegment));
when(logInfoStorage.getLogInfo(any())).thenReturn(log);
CuratorFramework curatorFramework = CuratorFrameworkFactory
.newClient("127.0.0.1:2181", new ExponentialBackoffRetry(1000, 3));
curatorFramework.start();
asyncCuratorFramework = AsyncCuratorFramework.wrap(curatorFramework);
offsetStorage = new ZkOffsetStorageImpl(logInfoStorage, asyncCuratorFramework);
}
示例4: buildLoggerContext
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
/**
* Build logger context logger context.
*
* @param environment the environment
* @param resourceLoader the resource loader
* @return the logger context
*/
public static Pair<Resource, LoggerContext> buildLoggerContext(final Environment environment, final ResourceLoader resourceLoader) {
try {
final String logFile = environment.getProperty("logging.config", "classpath:/log4j2.xml");
LOGGER.debug("Located logging configuration reference in the environment as [{}]", logFile);
if (ResourceUtils.doesResourceExist(logFile, resourceLoader)) {
final Resource logConfigurationFile = resourceLoader.getResource(logFile);
LOGGER.debug("Loaded logging configuration resource [{}]. Initializing logger context...", logConfigurationFile);
final LoggerContext loggerContext = Configurator.initialize("CAS", null, logConfigurationFile.getURI());
LOGGER.debug("Installing log configuration listener to detect changes and update");
loggerContext.getConfiguration().addListener(reconfigurable -> loggerContext.updateLoggers(reconfigurable.reconfigure()));
return Pair.of(logConfigurationFile, loggerContext);
}
LOGGER.warn("Logging configuration cannot be found in the environment settings");
} catch (final Exception e) {
throw Throwables.propagate(e);
}
return null;
}
示例5: ServiceCollector
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
public ServiceCollector( Application csapApplication, OsManager osManager,
int intervalSeconds, boolean publishSummary ) {
super( csapApplication, osManager, intervalSeconds, publishSummary );
httpCollector = new HttpCollector( csapApplication, this );
if ( Application.isRunningOnDesktop() && !csapApplication.isJunit() ) {
System.err.println( "\n ============= DESKTOP detected - setting logs to ERROR " );
Configurator.setLevel( ServiceCollector.class.getName(), Level.ERROR );
}
timeStampArray_m = jacksonMapper.createArrayNode();
totalCpuArray = jacksonMapper.createArrayNode();
setMaxCollectionAllowedInMs( csapApplication
.lifeCycleSettings()
.getMaxJmxCollectionMs() );
scheduleCollection( this );
}
示例6: applyDelegate
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
@Override
public void applyDelegate(Config config) {
Security.addProvider(new BouncyCastleProvider());
if (isDebug()) {
setLogLevel(Level.DEBUG);
}
Configurator.setRootLevel(getLogLevel());
Configurator.setAllLevels("de.rub.nds.modifiablevariable", Level.FATAL);
if (getLogLevel() == Level.ALL) {
Configurator.setAllLevels("de.rub.nds.tlsattacker.core", Level.ALL);
Configurator.setAllLevels("de.rub.nds.tlsattacker.transport", Level.DEBUG);
} else if (getLogLevel() == Level.TRACE) {
Configurator.setAllLevels("de.rub.nds.tlsattacker.core", Level.DEBUG);
Configurator.setAllLevels("de.rub.nds.tlsattacker.transport", Level.DEBUG);
} else {
Configurator.setAllLevels("de.rub.nds.tlsattacker.core", Level.OFF);
}
LOGGER.debug("Using the following security providers");
for (Provider p : Security.getProviders()) {
LOGGER.debug("Provider {}, version, {}", p.getName(), p.getVersion());
}
// remove stupid Oracle JDK security restriction (otherwise, it is not
// possible to use strong crypto with Oracle JDK)
UnlimitedStrengthEnabler.enable();
}
示例7: changeLogLevel
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
/**
* @param name
* the name of the java class or java package to set the log
* level for
* @param logLevelToSet
* the log level to set e.g. TRACE, DEBUG, INFO, WARN, ERROR and
* FATAL, providing any other value will lead to DEBUG as new log
* level
*/
@MCRCommand(syntax = "change log level of {0} to {1}",
help = "{0} the package or class name for which to change the log level, {1} the log level to set.",
order = 10)
public static synchronized void changeLogLevel(String name, String logLevelToSet) {
LOGGER.info("Setting log level for \"{}\" to \"{}\"", name, logLevelToSet);
Level newLevel = Level.getLevel(logLevelToSet);
if (newLevel == null) {
LOGGER.error("Unknown log level \"{}\"", logLevelToSet);
return;
}
Logger log = "ROOT".equals(name) ? LogManager.getRootLogger() : LogManager.getLogger(name);
if (log == null) {
LOGGER.error("Could not get logger for \"{}\"", name);
return;
}
LOGGER.info("Change log level from {} to {}", log.getLevel(), newLevel);
Configurator.setLevel(log.getName(), newLevel);
}
示例8: main
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
Configurator.initialize("CocaRMQBenchmark", Thread.currentThread().getContextClassLoader(), "rmq-log4j2.xml");
// init coca
CocaSample sub = new CocaSample("appSub", "syncGroup");
sub.initCoca(CONF);
int warmCount = CocaRMQBenchmark.warmCount;
int writeCount = CocaRMQBenchmark.writeCount;
int total = warmCount + writeCount;
long s0 = System.currentTimeMillis();
while (true) {
if (sub.countSub() >= total) {
break;
}
LOG.info("total-{} sub-{}", total, sub.countSub());
Thread.sleep(5000L);
}
long s1 = System.currentTimeMillis();
sub.close();
LOG.info("sub-{} time-{}", sub.countSub() - warmCount, s1 - s0);
}
示例9: main
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// System.setProperty("log4j.configurationFile", "");
Configurator.initialize("SampleMain", Thread.currentThread().getContextClassLoader(), "simple-log4j2.xml");
// initialize coca instance
CocaSample app1 = new CocaSample("app1", "syncGroup");
app1.initCoca(CONF);
CocaSample app2 = new CocaSample("app2", "syncGroup");
app2.initCoca(CONF);
// testRead(app1, app2);
testShareWrite(app1, app2);
// close
app1.close();
app2.close();
}
示例10: Log4J2Logger
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
/**
* Creates new logger with given configuration {@code path}.
*
* @param path Path to log4j2 configuration XML file.
* @throws IgniteCheckedException Thrown in case logger can't be created.
*/
public Log4J2Logger(String path) throws IgniteCheckedException {
if (path == null)
throw new IgniteCheckedException("Configuration XML file for Log4j2 must be specified.");
final URL cfgUrl = U.resolveIgniteUrl(path);
if (cfgUrl == null)
throw new IgniteCheckedException("Log4j2 configuration path was not found: " + path);
addConsoleAppenderIfNeeded(new C1<Boolean, Logger>() {
@Override public Logger apply(Boolean init) {
if (init)
Configurator.initialize(LogManager.ROOT_LOGGER_NAME, cfgUrl.toString());
return (Logger)LogManager.getRootLogger();
}
});
quiet = quiet0;
cfg = path;
}
示例11: main
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
ServerChannelManager.getInstance().startUp();
ClientChannelManager.getInstance().startUp();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
ClientChannelManager.getInstance().shutdown();
ServerChannelManager.getInstance().shutdown();
// Disables the "shutdownHook" attribute of the configuration element inside the log4j2.xml and manually shutdowns Log4j system
// Refer to http://stackoverflow.com/questions/17400136/how-to-log-within-shutdown-hooks-with-log4j2
Configurator.shutdown((LoggerContext) LogManager.getContext());
}
});
}
示例12: testInitialize
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
@Test
public void testInitialize() throws Exception {
final String log4jConfigString =
"<Configuration name=\"ConfigTest\" status=\"debug\" >" +
"<Appenders>" +
" <Console name=\"STDOUT\">" +
" <PatternLayout pattern=\"%m%n\"/>" +
" </Console>" +
"</Appenders>" +
"<Loggers>" +
" <Root level=\"error\">" +
" <AppenderRef ref=\"STDOUT\"/>" +
" </Root>" +
"</Loggers>" +
"</Configuration>";
final InputStream is = new ByteArrayInputStream(log4jConfigString.getBytes());
final ConfigurationFactory.ConfigurationSource source =
new ConfigurationFactory.ConfigurationSource(is);
final long begin = System.currentTimeMillis();
Configurator.initialize(null, source);
final long tookForInit = System.currentTimeMillis() - begin;
System.out.println("log4j 2.0 initialization took " + tookForInit + "ms");
}
示例13: main
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
public static void main(final String[] args) {
// System.out.println(System.getProperty("java.class.path"));
String config = args.length == 0 ? "target/test-classes/log4j2-319.xml" : args[0];
final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config);
try {
LOG.fatal("Fatal message.");
LOG.error("Error message.");
LOG.warn("Warning message.");
LOG.info("Information message.");
LOG.debug("Debug message.");
LOG.trace("Trace message.");
try {
throw new NullPointerException();
} catch (Exception e) {
LOG.error("Error message.", e);
LOG.catching(Level.ERROR, e);
}
LOG.warn("this is ok \n And all \n this have only\t\tblack colour \n and here is colour again?");
LOG.info("Information message.");
} finally {
Configurator.shutdown(ctx);
}
}
示例14: main
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
public static void main(final String[] args) {
// System.out.println(System.getProperty("java.class.path"));
String config = args.length == 0 ? "target/test-classes/log4j2-180.xml" : args[0];
final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config);
try {
LOG.fatal("Fatal message.");
LOG.error("Error message.");
LOG.warn("Warning message.");
LOG.info("Information message.");
LOG.debug("Debug message.");
LOG.trace("Trace message.");
try {
throw new NullPointerException();
} catch (Exception e) {
LOG.error("Error message.", e);
LOG.catching(Level.ERROR, e);
}
} finally {
Configurator.shutdown(ctx);
}
}
示例15: main
import org.apache.logging.log4j.core.config.Configurator; //導入依賴的package包/類
public static void main(final String[] args) {
// System.out.println(System.getProperty("java.class.path"));
String config = args.length == 0 ? "target/test-classes/log4j2-console-style-ansi.xml" : args[0];
final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config);
try {
LOG.fatal("Fatal message.");
LOG.error("Error message.");
LOG.warn("Warning message.");
LOG.info("Information message.");
LOG.debug("Debug message.");
LOG.trace("Trace message.");
LOG.error("Error message.", new IOException("test"));
} finally {
Configurator.shutdown(ctx);
}
}