我正在使用Run-> Run菜单从IntelliJ IDE运行一个简单的Java程序.它工作正常.现在我想添加log4j日志记录.
我在项目根目录下添加了一个资源文件夹.我在该文件夹中添加了一个log4j.properties文件.我更改了代码以记录某些内容.
告诉IntelliJ在类路径中包含resources文件夹以便看到属性文件的正确方法是什么?
使用IntelliJ 8,我可以猜到像醉猴一样,并最终让它工作.我现在有9个,而且我完全不成功.我已经尝试了一个小时.在某处"添加到类路径"选项怎么样?/烟/发泄/咆哮
状态的JavaDocsjava.util.logging.Level:
降序的级别是:
SEVERE (最高价值)WARNINGINFOCONFIGFINEFINERFINEST (最低价值) import java.util.logging.*;
class LoggingLevelsBlunder {
public static void main(String[] args) {
Logger logger = Logger.getAnonymousLogger();
logger.setLevel(Level.FINER);
System.out.println("Logging level is: " + logger.getLevel());
for (int ii=0; ii<3; ii++) {
logger.log(Level.FINE, ii + " " + (ii*ii));
logger.log(Level.INFO, ii + " " + (ii*ii));
}
}
}
Run Code Online (Sandbox Code Playgroud)
Logging level is: FINER
Jun 11, 2011 9:39:23 PM LoggingLevelsBlunder main
INFO: 0 0
Jun 11, 2011 9:39:24 PM …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Java Swing应用程序中调试一些与焦点相关的问题.有些时候某些组件似乎正在抓住焦点,我无法弄清楚代码在哪里发生.
A VetoableChangeListener与KeyboardFocusManager(for focusOwner).这确实为我提供了有关哪些组件丢失并获得焦点的信息,但它无法帮助我确定代码中请求焦点的位置.
一个习惯KeyboardFocusManager.但在这方面我也只能在收到事件时进行干预.到那时,调用的调用栈requestFocus已经丢失.
一个习惯EventQueue.但是我也能够干预dispatchEvent从EDT再次调用的方法.调用堆栈再次丢失(有趣的postEvent(AWTEvent)是没有调用).
我正在寻找的是调用时的调用堆栈requestFocusInWindow.是否有可能获得此信息.也许,如果我可以重新定义用于发布事件的方法EventQueue,那么我可以打印堆栈转储.但是EventQueue.postEvent(AWTEvent)不会被调用.
任何人都可以建议一个解决方案,它可以帮助我在拨打requestFocus或requestFocusInWIndow可能已经拨打电话时获得筹码状态吗?
我试图在运行时设置java util日志配置文件,以避免必须将其设置为VM参数.但这只是行不通.每当我尝试重新读取配置时,都会禁用日志记录.
请参阅以下代码段:
package test;
import java.io.FileInputStream;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
public class A {
private static final Logger LOGGER= Logger.getLogger(A.class.getName());
public static void main(String[] args) throws Exception {
System.out.println("--- start");
LOGGER.log(Level.SEVERE, "SEVERE 1");
LOGGER.log(Level.FINEST, "FINEST 1");
LogManager.getLogManager().readConfiguration();
LOGGER.log(Level.SEVERE, "SEVERE 2");
LOGGER.log(Level.FINEST, "FINEST 2");
LogManager.getLogManager().readConfiguration(new FileInputStream("/tmp/logging.properties"));
LOGGER.log(Level.SEVERE, "SEVERE 3");
LOGGER.log(Level.FINEST, "FINEST 3");
System.out.println("--- end");
}
}
Run Code Online (Sandbox Code Playgroud)
如果我运行没有任何VM参数的类,这是输出:
--- start
09.11.2012 09:59:25 test.A main
SCHWERWIEGEND: SEVERE 1
09.11.2012 09:59:25 test.A main
SCHWERWIEGEND: SEVERE 2
--- end
Run Code Online (Sandbox Code Playgroud)
如您所见,仅记录SEVERE级别,因为这是JREs logging.properties的默认值.通话LogManager#readConfiguration() …
我们的团队正在使用docker部署selenium网格.默认日志级别似乎设置为INFO.我想将它设置为更高,严重或完全关闭它们.我做了三次尝试,但到目前为止,没有任何效果.
方法一:
从selenium客户端,我试图在DesiredCapabilities中的RemoteWebDriver上设置LoggingPreferences:
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
LoggingPreferences logs = new LoggingPreferences();
logs.enable(LogType.BROWSER, Level.SEVERE);
logs.enable(LogType.CLIENT, Level.SEVERE);
ogs.enable(LogType.DRIVER, Level.SEVERE);
logs.enable(LogType.SERVER, Level.SEVERE);
desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, logs);
desiredCapabilities.setCapability(FirefoxDriver.PROFILE, profile);
WebDriver driver = new RemoteWebDriver(new URL(host:4444/wd/hub"),
desiredCapabilities);
Run Code Online (Sandbox Code Playgroud)
方法2:我尝试更改配置文件首选项:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("webdriver.log.driver", "OFF");
profile.setPreference("webdriver.log.file","/dev/null");
Run Code Online (Sandbox Code Playgroud)
方法3:我尝试修改位于/opt/selenium/config.json的容器中的config.json:
{
"capabilities": [
{
"browserName": "*firefox",
"maxInstances": 1,
"seleniumProtocol": "Selenium"
},
{
"browserName": "firefox",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
}
],
"configuration": {
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 1,
"port": 5555,
"register": true,
"registerCycle": 5000,
"logLevel":FATAL
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我一直无法做任何改变日志记录行为的事情.