本文整理匯總了Java中org.apache.logging.log4j.LogManager類的典型用法代碼示例。如果您正苦於以下問題:Java LogManager類的具體用法?Java LogManager怎麽用?Java LogManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LogManager類屬於org.apache.logging.log4j包,在下文中一共展示了LogManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
@Test
public void test() {
{
Logger logger = LogManager.getLogger("test.logger");
logger.error("This is an error!");
logger.error("This is another error!");
logger.error("This is a third error!");
}
assertThat(collector.getLogs()).hasSize(3)
.contains("This is an error!", "This is another error!", "This is a third error!");
List<LogEvent> rawLogs = (List<LogEvent>) collector.getRawLogs();
assertThat(rawLogs).hasSize(3);
assertTrue(rawLogs.stream().allMatch(l -> l.getLevel() == Level.ERROR));
}
示例2: toggleCleanLogging
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
private void toggleCleanLogging() {
this.cleanLogging = !cleanLogging;
interactionHandler.sendText("clean logging: " + cleanLogging);
String appenderToAdd = cleanLogging ? "Clean" : "Console";
String appenderToRemove = cleanLogging ? "Console" : "Clean";
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
for (org.apache.logging.log4j.core.Logger logger : ctx.getLoggers()) {
logger.removeAppender(config.getAppender(appenderToRemove));
config.addLoggerAppender(logger, config.getAppender(appenderToAdd));
}
ctx.updateLoggers();
}
示例3: init
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
@Override
public boolean init(String botId, Map<String, String> configs, String[] channels) {
logger = LogManager.getLogger(TelegramBot.class.getSimpleName() + ":" + botId);
this.configs = configs;
try {
telegramBotsApi.registerBot(this);
} catch (TelegramApiRequestException e) {
logger.error(e);
return false;
}
this.botId = botId;
return true;
}
示例4: DebeziumPipeLine
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
public DebeziumPipeLine(Context cxt, SourceConfig conf, String topic) throws BiremeException {
super(cxt, conf, "Debezium-" + conf.name + "-" + topic);
this.conf = conf;
List<TopicPartition> topicPartition =
consumer.partitionsFor(topic)
.stream()
.map(p -> new TopicPartition(p.topic(), p.partition()))
.collect(Collectors.toList());
consumer.subscribe(Arrays.asList(topic));
logger = LogManager.getLogger("Bireme." + myName);
logger.info("Create new Debezium PipeLine. Name: {}", myName);
if (topicPartition.size() > 1) {
logger.error("Topic {} has {} partitions", topic, topicPartition.size());
String message = "Topic has more than one partitions";
throw new BiremeException(message);
}
}
示例5: mapChartData
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
public List<PoloniexChartData> mapChartData(String chartDataResult) {
if (INVALID_CHART_DATA_DATE_RANGE_RESULT.equals(chartDataResult) || INVALID_CHART_DATA_CURRENCY_PAIR_RESULT.equals(chartDataResult)) {
return Collections.EMPTY_LIST;
}
List<PoloniexChartData> results;
try {
PoloniexChartData[] chartDataResults = gson.fromJson(chartDataResult, PoloniexChartData[].class);
results = Arrays.asList(chartDataResults);
} catch (JsonSyntaxException | DateTimeParseException ex) {
LogManager.getLogger().error("Exception mapping chart data {} - {}", chartDataResult, ex.getMessage());
results = Collections.EMPTY_LIST;
}
return results;
}
示例6: main
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
public static void main(String[] args) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
config.getLoggerConfig(strategy.Portfolio.class.getName()).setLevel(Level.WARN);
ctx.updateLoggers(config);
final CommonParam cp = ParamManager.getCommonParam("m", TIME_FRAME.MIN60, "19980101 000000", "20160101 170000");
StrategyOptimizer so = new StrategyOptimizer(tester.RealStrategyTester.class);
so.setInstrumentParam(cp.instrument, cp.tf);
so.setTestDateRange((int) DateTimeHelper.Ldt2Long(cp.start_date), (int) DateTimeHelper.Ldt2Long(cp.end_date));
int num = so.setStrategyParamRange(DblMaPsarStrategy.class, new Integer[]{3, 5, 1}, new Integer[]{10, 100, 2}, MA.MA_MODES, new APPLIED_PRICE[] {APPLIED_PRICE.PRICE_CLOSE, APPLIED_PRICE.PRICE_TYPICAL}, new Float[]{0.01f, 0.02f, 0.01f}, new Float[]{0.12f, 0.2f, 0.02f});
System.out.println(num);
so.StartOptimization();
Set<Entry<Object[],Performances>> entryset = so.result_db.entrySet();
for (Entry<Object[],Performances> entry : entryset) {
for (Object obj : entry.getKey()) {
System.out.print(obj + ",\t");
}
System.out.println("ProfitRatio: " + String.format("%.5f", entry.getValue().ProfitRatio) + "\tMaxDrawDown: " + entry.getValue().MaxDrawDown);
}
}
示例7: toggleAutoRenew
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
@Override
public PoloniexLendingResult toggleAutoRenew(String orderNumber)
{
long start = System.currentTimeMillis();
PoloniexLendingResult result = null;
try
{
String res = tradingClient.toggleAutoRenew(orderNumber);
result = mapper.mapLendingResult(res);
LogManager.getLogger(PoloniexLendingService.class).trace("Executed and mapped toggleAutoRenew for {} in {} ms", orderNumber, System.currentTimeMillis() - start);
}
catch (Exception ex)
{
LogManager.getLogger(PoloniexLendingService.class).error("Error executing toggleAutoRenew for {} - {}", orderNumber, ex.getMessage());
}
return result;
}
示例8: init
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
@Override
public boolean init(String botId, Map<String, String> configs, String[] channels) {
logger = LogManager.getLogger(IrcBot.class.getSimpleName() + ":" + botId);
if (!configs.containsKey(USERNAME_KEY))
return false;
if (!configs.containsKey(HOST_KEY))
return false;
client = Client.builder()
.nick(configs.get(USERNAME_KEY))
.serverHost(configs.get(HOST_KEY))
.listenInput(line -> logger.debug("[I]: " + line))
.listenOutput(line -> logger.debug("[O]: " + line))
.listenException(logger::error)
.defaultMessageMap(new SimpleDefaultMessageMap())
.build();
client.getEventManager().registerEventListener(this);
this.botId = botId;
this.configs = configs;
this.channels = channels;
return true;
}
示例9: func_181670_b
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
private void func_181670_b(int p_181670_1_)
{
if (p_181670_1_ > this.rawIntBuffer.remaining())
{
int i = this.byteBuffer.capacity();
int j = i % 2097152;
int k = j + (((this.rawIntBuffer.position() + p_181670_1_) * 4 - j) / 2097152 + 1) * 2097152;
LogManager.getLogger().warn("Needed to grow BufferBuilder buffer: Old size " + i + " bytes, new size " + k + " bytes.");
int l = this.rawIntBuffer.position();
ByteBuffer bytebuffer = GLAllocation.createDirectByteBuffer(k);
this.byteBuffer.position(0);
bytebuffer.put(this.byteBuffer);
bytebuffer.rewind();
this.byteBuffer = bytebuffer;
this.rawFloatBuffer = this.byteBuffer.asFloatBuffer().asReadOnlyBuffer();
this.rawIntBuffer = this.byteBuffer.asIntBuffer();
this.rawIntBuffer.position(l);
this.field_181676_c = this.byteBuffer.asShortBuffer();
this.field_181676_c.position(l << 1);
}
}
示例10: setUp
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
registry = RegistryService.getMetricRegistry();
meters = new HashMap<>();
meters.put("total", getMeter(APPENDS_BASE_NAME.submetric("total")));
meters.put("trace", getMeter(APPENDS_BASE_NAME.withTags("level", "trace")));
meters.put("debug", getMeter(APPENDS_BASE_NAME.withTags("level", "debug")));
meters.put("info", getMeter(APPENDS_BASE_NAME.withTags("level", "info")));
meters.put("warn", getMeter(APPENDS_BASE_NAME.withTags("level", "warn")));
meters.put("error", getMeter(APPENDS_BASE_NAME.withTags("level", "error")));
meters.put("fatal", getMeter(APPENDS_BASE_NAME.withTags("level", "fatal")));
meters.put("throwCount", getMeter(THROWABLES_BASE_NAME.submetric("total")));
meters.put("throw[RuntimeException]", getMeter(THROWABLES_BASE_NAME
.withTags("class", RuntimeException.class.getName())
));
logger = LogManager.getLogger(Log4J2InstrumentationTest.class.getName());
origLevel = logger.getLevel();
setLogLevel(logger, Level.ALL);
}
示例11: write
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
private void write(String data) {
try {
FileUtils.writeStringToFile(logFile, data + Character.LINE_SEPARATOR, "UTF-8", true);
} catch (IOException e) {
LogManager.getLogger(getClass()).error("Failed writing to raffle log", e);
}
}
示例12: main
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
public static void main(String[] args) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
config.getLoggerConfig(strategy.Portfolio.class.getName()).setLevel(Level.WARN);
ctx.updateLoggers(config);
final CommonParam cp = ParamManager.getCommonParam("i", TIME_FRAME.MIN15, "20080101 000000", "20160101 170000");
StrategyOptimizer so = new StrategyOptimizer(tester.RealStrategyTester.class);
so.setInstrumentParam(cp.instrument, cp.tf);
so.setTestDateRange((int) DateTimeHelper.Ldt2Long(cp.start_date), (int) DateTimeHelper.Ldt2Long(cp.end_date));
int num = so.setStrategyParamRange(MaPsarStrategy.class, new Integer[]{12, 500, 2}, new String[]{MA.MODE_EMA, MA.MODE_SMMA}, new APPLIED_PRICE[] {APPLIED_PRICE.PRICE_CLOSE, APPLIED_PRICE.PRICE_TYPICAL}, new Float[]{0.01f, 0.02f, 0.01f}, new Float[]{0.1f, 0.2f, 0.02f});
System.out.println(num);
so.StartOptimization();
Set<Entry<Object[],Performances>> entryset = so.result_db.entrySet();
for (Entry<Object[],Performances> entry : entryset) {
for (Object obj : entry.getKey()) {
System.out.print(obj + ",\t");
}
System.out.println("ProfitRatio: " + String.format("%.5f", entry.getValue().ProfitRatio) + "\tMaxDrawDown: " + entry.getValue().MaxDrawDown);
}
}
示例13: initLog
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
protected static void initLog(){
if (AschSDK.Config.isDebugMode()) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
ctx.getConfiguration()
.getRootLogger()
.setLevel(Level.ALL);
}
}
示例14: getContext
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
/**
* Gets the {@link LoggerContext} associated with the given caller class.
*
* @param callerClass the caller class
* @return the LoggerContext for the calling class
*/
protected LoggerContext getContext(final Class<?> callerClass) {
ClassLoader cl = null;
if (callerClass != null) {
cl = callerClass.getClassLoader();
}
if (cl == null) {
cl = LoaderUtil.getThreadContextClassLoader();
}
return LogManager.getContext(cl, false);
}
示例15: onLogLevelChanged
import org.apache.logging.log4j.LogManager; //導入依賴的package包/類
/**
* When the user changes the log level and new {@link Runnable} command is added to {@link Settings}.
* <p>
* Command run when the user applies the change in setting.
*
* @param event action event
*/
@FXML
public void onLogLevelChanged(final ActionEvent event) {
settings.addRunnable(() -> {
final String logLevel = choiceBox.getSelectionModel().getSelectedItem();
final Logger logger = LogManager.getRootLogger();
Configurator.setLevel(logger.getName(), Level.toLevel(logLevel));
LOGGER.info("Log level was set to: " + Level.toLevel(logLevel));
});
event.consume();
}