/**
* Initializes logging to a file.
* @param loggerNames the names of the loggers (usually names of packages
* or classes or ancestors of packages or classes). Can't be null.
* @param argMap command line arguments.
*/
public static synchronized void initFileLogging(String[] loggerNames, ArgumentMap argMap, String filename)
throws IOException
{
Level level = DEFAULT_FILE_LOGGING_LEVEL;
if (argMap.isSet(Argument.LOG_QUIET_SHORT) || argMap.isSet(Argument.LOG_QUIET)) level = Level.ERROR;
if (argMap.isSet(Argument.LOG_VERBOSE_SHORT) || argMap.isSet(Argument.LOG_VERBOSE)) level = Level.INFO;
if (argMap.isSet(Argument.LOG_DEBUG_SHORT) || argMap.isSet(Argument.DEBUG)) level = Level.DEBUG;
FileAppender fileAppender = new FileAppender(new PatternLayout(), filename);
boolean append = true;
Writer fileWriter = new FileWriter(filename, append);
for (String loggerName : loggerNames)
Log4jInit.setLevel(loggerName, level, fileWriter);
}
java类org.apache.log4j.PatternLayout的实例源码
Util.java 文件源码
项目:caom2
阅读 22
收藏 0
点赞 0
评论 0
Action.java 文件源码
项目:charles-rest
阅读 32
收藏 0
点赞 0
评论 0
/**
* Setup the Log4J logger for this action thread.
* @return String path to log file
* @throws IOException If there's something wrong with the FileAppender.
*/
private void setupLog4jForAction() throws IOException {
String loggerName = "Action_" + this.id;
org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger("Action_" + this.id);
String logRoot = System.getProperty("LOG_ROOT");
if(logRoot == null) {
logRoot = ".";
}
String logFilePath = logRoot + "/charles-rest/ActionsLogs/" + this.id + ".log";
File logFile = new File(logFilePath);
logFile.getParentFile().mkdirs();
logFile.createNewFile();//you have to create the file yourself since FileAppender acts funny under linux if the file doesn't already exist.
FileAppender fa = new FileAppender(new PatternLayout("%d %p - %m%n"), logFilePath);
fa.setName(this.id + "_appender");
fa.setThreshold(Level.DEBUG);
log4jLogger.addAppender(fa);
log4jLogger.setLevel(Level.DEBUG);
this.logger = LoggerFactory.getLogger(loggerName);
}
Logging.java 文件源码
项目:eagle
阅读 24
收藏 0
点赞 0
评论 0
/**
* Sets up audit logging to log to a file named based on the current time (in
* ms).
*
* The logger is configured to effectively ignore the log level.
*
* @throws IOException
* if the audit log file could not be opened for writing.
*/
public static void configureAuditLogging() throws IOException {
PatternLayout layout = new PatternLayout(AUDIT_LOG_FORMAT);
// This assumes that no other daemon will be started within 1 millisecond.
String filename = String.format(AUDIT_LOG_FILENAME_FORMAT,
System.currentTimeMillis(), new Random().nextInt(Integer.MAX_VALUE));
FileAppender fileAppender = new FileAppender(layout, filename);
Logger auditLogger = Logger.getLogger(Logging.AUDIT_LOGGER_NAME);
auditLogger.addAppender(fileAppender);
auditLogger.setLevel(Level.ALL);
/*
* We don't want audit messages to be appended to the main appender, which
* is intended for potentially user-facing messages.
*/
auditLogger.setAdditivity(false);
}
ClientConnectorBeanWIKIHom.java 文件源码
项目:CloudCryptoSearch
阅读 17
收藏 0
点赞 0
评论 0
public static void main (String[] args) {
log.addAppender(new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %-5p [%c{1}] %m%n")));
log.setLevel(Level.INFO);
ClientConnectorLocal client = new ClientConnectorBeanWIKIHom();
log.info("Setup done. Building index...");
// client.addFirstDocuments("/home/bernardo/Desktop/enwiki-latest-pages-articles.xml");
// client.addFirstDocuments("/home/bernardo/Desktop/ptwiki-20121027-pages-articles.xml");
// client.addFirstDocuments("/home/bernardo/Desktop/eswiki-20121018-pages-articles.xml");
// log.info("Index Finished!");
client.rebuildIndex();
log.info("Starting query...");
query(client, "IETF payload optimize retransmit threshold RFC protocol trusted network address");
// query(client, "IETF payload optimize retransmit threshold");
// query(client, "IETF payload");
log.info("Query finished!");
}
PrototypeClientConnector.java 文件源码
项目:CloudCryptoSearch
阅读 19
收藏 0
点赞 0
评论 0
public static void main (String[] args) throws Exception{
log.addAppender(new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %-5p [%c{1}] %m%n")));
log.setLevel(Level.INFO);
PrototypeClientConnector client = new PrototypeClientConnector();
log.info("Setup done. Building index...");
File f = new File("/Users/bernardo/Dropbox/WorkspacePHD/CryptoSearchCloud/docs");
client.addFirstDocuments(f.listFiles());
log.info("Index Finished!");
client.rebuildIndex();
log.info("Starting query...");
// query(client, "IETF payload optimize retransmit threshold RFC protocol trusted network address");
// query(client, "IETF payload optimize retransmit threshold");
// query(client, "IETF payload");
query(client, "rTp");
log.info("Query finished!");
}
ClientConnectorBeanWIKI.java 文件源码
项目:CloudCryptoSearch
阅读 16
收藏 0
点赞 0
评论 0
public static void main (String[] args) {
log.addAppender(new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %-5p [%c{1}] %m%n")));
log.setLevel(Level.INFO);
ClientConnectorLocal client = new ClientConnectorBeanWIKI();
log.info("Setup done. Building index...");
// client.addFirstDocuments("/home/bernardo/Desktop/enwiki-latest-pages-articles.xml");
// client.addFirstDocuments("/home/bernardo/Desktop/ptwiki-20121027-pages-articles.xml");
// client.addFirstDocuments("/home/bernardo/Desktop/eswiki-20121018-pages-articles.xml");
// log.info("Index Finished!");
client.rebuildIndex();
log.info("Starting query...");
query(client, "IETF payload optimize retransmit threshold RFC protocol trusted network address");
// query(client, "IETF payload optimize retransmit threshold");
// query(client, "IETF payload");
log.info("Query finished!");
}
OdenOSAdapterServiceImplTest.java 文件源码
项目:mlo-net
阅读 24
收藏 0
点赞 0
评论 0
/**
* Test method for {@link org.o3project.mlo.server.impl.rpc.service.OdenOSAdapterServiceImpl#notifyLinkDeleted(java.lang.String)}.
*/
@Test
public void testNotifyFlowDeleted_unmatch() {
StringWriter writer = new StringWriter();
WriterAppender appender = new WriterAppender(new PatternLayout("%p, %m%n"),writer);
getLogger().addAppender(appender);
getLogger().setAdditivity(false);
try{
// Outputs any log
try {
obj.setDeleteFlowQueue("test");
obj.notifyFlowDeleted("test2");
} catch (Exception e) {
fail();
}
// Checks error log
String logString = writer.toString();
assertTrue(logString.contains("notifyFlowDeleted Incorrect response : " + "test2"));
}finally{
// Removes log appender
getLogger().removeAppender(appender);
getLogger().setAdditivity(true);
}
}
TestAuditLogs.java 文件源码
项目:hadoop-2.6.0-cdh5.4.3
阅读 24
收藏 0
点赞 0
评论 0
private void configureAuditLogs() throws IOException {
// Shutdown the LogManager to release all logger open file handles.
// Unfortunately, Apache commons logging library does not provide
// means to release underlying loggers. For additional info look up
// commons library FAQ.
LogManager.shutdown();
File file = new File(auditLogFile);
if (file.exists()) {
assertTrue(file.delete());
}
Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
// disable logging while the cluster startup preps files
logger.setLevel(Level.OFF);
PatternLayout layout = new PatternLayout("%m%n");
RollingFileAppender appender = new RollingFileAppender(layout, auditLogFile);
logger.addAppender(appender);
}
ProductRecipeParser.java 文件源码
项目:VirtaMarketAnalyzer
阅读 16
收藏 0
点赞 0
评论 0
public static void main(final String[] args) throws IOException {
BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%r %d{ISO8601} [%t] %p %c %x - %m%n")));
// final Document doc = Downloader.getDoc(Wizard.host + "olga/main/industry/unit_type/info/15751");
// final Document doc = Downloader.getDoc(Wizard.host + "olga/main/industry/unit_type/info/422209");
// final Document doc = Downloader.getDoc(Wizard.host + "olga/main/industry/unit_type/info/2425");
// final Document doc = Downloader.getDoc(Wizard.host + "olga/main/industry/unit_type/info/2417");
final String host = Wizard.host;
final String realm = "olga";
final String url = host + realm + "/main/industry/unit_type/info/";
final List<Manufacture> manufactures = new ArrayList<>();
// manufactures.add(new Manufacture("423140", "manufactureCategory", "caption"));
// manufactures.add(new Manufacture("2425", "manufactureCategory", "caption"));
manufactures.add(new Manufacture("2438", "manufactureCategory", "caption", new ArrayList<>()));
final Map<String, List<ProductRecipe>> result = getProductRecipes(host, realm, manufactures);
logger.info(Utils.getPrettyGson(result));
}
ShopParser.java 文件源码
项目:VirtaMarketAnalyzer
阅读 18
收藏 0
点赞 0
评论 0
public static void main(String[] args) throws Exception {
BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%r %d{ISO8601} [%t] %p %c %x - %m%n")));
// final String url = Wizard.host + "olga/main/unit/view/5788675";
final String host = Wizard.host;
// final String realm = "mary";
// final String url = host + realm + "/main/unit/view/3943258";
final String realm = "olga";
final String url = host + realm + "/main/unit/view/6519771";
// Downloader.invalidateCache(url);
final List<City> cities = new ArrayList<>();
cities.add(new City("422653", "422655", "422682", "Вашингтон", 0.0, 0.0, 0.0, 0,0, null));
final List<Product> products = new ArrayList<>();
products.add(ProductInitParser.getTradingProduct(host, realm, "422547"));
products.add(ProductInitParser.getTradingProduct(host, realm, "3838"));
final Map<String, List<Product>> productsByImgSrc = products.stream().collect(Collectors.groupingBy(Product::getImgUrl));
System.out.println(Utils.getPrettyGson(parse(realm, url, cities, productsByImgSrc, "Вашингтон")));
}