本文整理匯總了Java中org.apache.log4j.BasicConfigurator類的典型用法代碼示例。如果您正苦於以下問題:Java BasicConfigurator類的具體用法?Java BasicConfigurator怎麽用?Java BasicConfigurator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BasicConfigurator類屬於org.apache.log4j包,在下文中一共展示了BasicConfigurator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
/**
* main.
*
* @param args
* {@link String}{@code []}
*/
public static void main(final String[] args) {
BasicConfigurator.configure();
org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);
MP3TestFiles.iterateOverTestFiles(new FileHandler() {
@Override
public void handle(final File file) {
if (AppTestMPEGAudioFrameInputStream.LOG.isInfoEnabled()) {
AppTestMPEGAudioFrameInputStream.LOG
.info("######## Try to decode new file [" + file.getAbsolutePath() + "]."); //$NON-NLS-1$ //$NON-NLS-2$
}
decodeMpegAudioFile(file);
}
});
}
示例2: main
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
BasicConfigurator.configure();
Configuration conf = new Configuration();
conf.setQuietMode(true);
Job job = Job.getInstance(conf, "WordCount");
job.setJarByClass(HadoopWordCount.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setMapperClass(Map.class);
job.setCombinerClass(Reduce.class);
job.setReducerClass(Reduce.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.setInputPaths(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1] + "_" + System.currentTimeMillis()));
long t = System.currentTimeMillis();
job.waitForCompletion(true);
System.out.println("TotalTime=" + (System.currentTimeMillis() - t));
}
示例3: getWriter
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
/**
* Get singleton instance of RdfWriter
*
* @return instance of RdfWriter
*/
public static RdfWriter getWriter() {
if (writer == null) {
BasicConfigurator.configure();
writer = new RdfWriter();
}
writer.model = ModelFactory.createDefaultModel();
writer.list = new LinkedBlockingQueue<>();
return writer;
}
示例4: setupLog4j
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
private void setupLog4j(String appName) {
// InputStream inStreamLog4j = getClass().getResourceAsStream("/log4j.properties");
String propFileName = appName + ".log4j.properties";
File f = new File("./" + propFileName);
if (f.exists()) {
try {
InputStream inStreamLog4j = new FileInputStream(f);
Properties propertiesLog4j = new Properties();
propertiesLog4j.load(inStreamLog4j);
PropertyConfigurator.configure(propertiesLog4j);
} catch (Exception e) {
e.printStackTrace();
BasicConfigurator.configure();
}
} else {
BasicConfigurator.configure();
}
// logger.setLevel(Level.TRACE);
logger.debug("log4j configured");
}
示例5: main
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
public static void main(String[] args) throws ParseException {
Options options = new Options();
Option nameOption = new Option("n", true, "Name to resolve");
nameOption.setRequired(true);
options.addOption(nameOption);
CommandLineParser parser = new BasicParser();
CommandLine cmd = parser.parse(options, args);
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.DEBUG);
PodCIDRToNodeMapping plugin = new PodCIDRToNodeMapping();
Configuration conf = new Configuration();
plugin.setConf(conf);
String nameToResolve = cmd.getOptionValue(nameOption.getOpt());
List<String> networkPathDirs = plugin.resolve(Lists.newArrayList(nameToResolve));
log.info("Resolved " + nameToResolve + " to " + networkPathDirs);
}
示例6: main
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
/**
* main.
* @param args {@link String}{@code []}
* @throws IOException due to file errors.
*/
@SuppressWarnings("nls")
public static void main(final String[] args) throws IOException {
BasicConfigurator.configure();
final File in = new File("src/test/mp3/1000Hz.mp3");
// assume there is just one id 3 tag at the very beginning...
final ID3Tag firstID3Tag = MPEGAudio.decodeFirstID3Tag(in);
if (LOG.isInfoEnabled()) {
LOG.info("" + firstID3Tag); //$NON-NLS-1$
}
final DecodingResult dr = MPEGAudio.decode(in, MPEGAudioContentFilter.MPEG_AUDIO_FRAMES);
// final File out = File.createTempFile("TestIntegrationReadWrite-TEST", ".mp3"); //$NON-NLS-1$ //$NON-NLS-2$
final File out = new File("out.mp3");
if (LOG.isInfoEnabled()) {
LOG.info("Created tmp file [" + out.getAbsolutePath() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
}
try (FileOutputStream fos = new FileOutputStream(out)) {
final WaveFormGainFilter filter = new CosineGainFilter();
filter.setWavelengthInSecs(20f);
// Filter filter = new FixFactorGainFIlter(0.9);
MPEGAudio.encode(dr.getContent(), filter, fos, true);
}
}
示例7: before
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
@Override
protected void before() throws Throwable {
//初始化 slf4j
BasicConfigurator.configure();
//讀取配置文件
try {
Config.setConfig(
new Gson().fromJson(
new BufferedReader(new InputStreamReader(Config.class.getResourceAsStream("/config.json"))),
Config.class
)
);
} catch (NullPointerException e) {
//拋出異常就可以取消測試
throw new RuntimeException("Please create config file before tests");
}
}
示例8: before
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
@Override
public void before() throws Throwable {
if (notConfigured) {
//Now configure Log4J with console appender
BasicConfigurator.configure();
System.out.println("Configure Log4J for basic output...");
System.out.println("Set root LOGGER loglevel to '" + rootLevel.toString() + "'!");
Logger.getRootLogger().setLevel(rootLevel);
}
if (logger == null) {
Logger.getRootLogger().setAdditivity(false);
logger = Logger.getLogger(InitLog4jLoggingRule.class);
logger.setAdditivity(false);
}
//Init FirstSpirit Logging with special logger
Logging.init(new FS2Log4JLogger());
}
示例9: main
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
public static void main(String[] args) {
try {
BasicConfigurator.configure();
Debug.info(" - Initializing Hibernate ... ");
_RootDAO.initialize();
ApplicationProperties.getConfigProperties().setProperty(
ApplicationProperty.CustomizationDefaultCourseUrl.key(),
"http://syllabuskrk.agh.edu.pl/:years/pl/magnesite/modules/:courseNbr");
ApplicationProperties.getConfigProperties().setProperty("unitime.custom.default.course_api_url",
"http://syllabuskrk.agh.edu.pl/api/:years/modules/:courseNbr");
ApplicationProperties.getDefaultProperties()
.setProperty(ApplicationProperty.CustomizationDefaultCourseDetailsDownload.key(), "true");
System.out.println("URL:" + new AGHCourseDetailsProvider()
.getCourseUrl(new AcademicSessionInfo(231379l, "2015", "Semestr zimowy", "AGH"), "BAND", "101"));
System.out.println("Details:\n" + new AGHCourseDetailsProvider()
.getDetails(new AcademicSessionInfo(231379l, "2015", "Semestr zimowy", "AGH"), "BAND", "101"));
} catch (Exception e) {
e.printStackTrace();
}
}
示例10: main
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
public static void main(String[] args) {
BasicConfigurator.configure();
port(4567);
if (getPassword() != null && getKeystorePath() != null) {
secure(getKeystorePath(), getPassword(), null, null);
}
staticFiles.location("/public");
staticFiles.expireTime(600L);
before("*", Filters.addTrailingSlashes);
before("*", Filters.handleLocaleChange);
get(Path.Web.INDEX, IndexController.serveIndexPage);
get(Path.Web.PARSE, DatalogController.parseDatalog);
after("*", Filters.addGzipHeader);
}
示例11: clockSkewFailure_CorrectsGlobalTimeOffset
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
/**
* In the following test, we purposely setting the time offset to trigger a clock skew error.
* The time offset must be fixed and then we validate the global value for time offset has been
* update.
*/
@Test
public void clockSkewFailure_CorrectsGlobalTimeOffset() throws Exception {
BasicConfigurator.configure();
final int originalOffset = SdkGlobalTime.getGlobalTimeOffset();
final int skew = 3600;
SdkGlobalTime.setGlobalTimeOffset(skew);
assertEquals(skew, SdkGlobalTime.getGlobalTimeOffset());
SQSAsyncClient sqsClient = createSqsAyncClient();
sqsClient.listQueues(ListQueuesRequest.builder().build()).thenCompose( __ -> {
assertThat("Clockskew is fixed!", SdkGlobalTime.getGlobalTimeOffset(), lessThan(skew));
// subsequent changes to the global time offset won't affect existing client
SdkGlobalTime.setGlobalTimeOffset(skew);
return sqsClient.listQueues(ListQueuesRequest.builder().build());
}).thenAccept( __ -> {
assertEquals(skew, SdkGlobalTime.getGlobalTimeOffset());
}).join();
sqsClient.close();
SdkGlobalTime.setGlobalTimeOffset(originalOffset);
}
示例12: initiateSynchronisationDialogue
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
@Override
public void initiateSynchronisationDialogue() {
BasicConfigurator.configure();
helper = new F2PSyncHelper();
Resource r = helper.getResourceSet().createResource(URI.createURI("sourceModel"));
FamilyRegister familiesRoot = FamiliesFactory.eINSTANCE.createFamilyRegister();
r.getContents().add(familiesRoot);
// Fix default preferences (which can be overwritten)
setConfigurator(new Configurator<Decisions>()
.makeDecision(Decisions.PREFER_CREATING_PARENT_TO_CHILD, true)
.makeDecision(Decisions.PREFER_EXISTING_FAMILY_TO_NEW, true));
// perform batch to establish consistent starting state
helper.setSrc(familiesRoot);
helper.integrateForward();
helper.setMute(true);
}
示例13: init
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init(ServletConfig config) throws ServletException {
// Put your code here
System.out.println("Log4jServlet 正在初始化log4j日誌設置信息");
String log4jLocation = config.getInitParameter("log4j-properties-location");
ServletContext sc = config.getServletContext();
if(log4jLocation == null){
System.out.println("** 沒有log4j-properties-location 初始化文件,所以使用BasicConfiguratorc初始化 **");
BasicConfigurator.configure();
}else{
String webAppPath = sc.getRealPath("/");
String log4jProp = webAppPath + log4jLocation;
File log4File = new File(log4jProp);
if(log4File.exists()){
System.out.println("使用:"+ log4jProp + "初始化日誌設置信息");
PropertyConfigurator.configure(log4jProp);
}else{
System.out.println("*****" + log4jProp + "文件沒有找到,所以使用BasicConfigurator初始化*****");
BasicConfigurator.configure();
}
}
super.init(config);
System.out.println("---------log4jServlet 初始化log4j日誌設置信息完成--------");
}
示例14: setLogerConfig
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
/**
* 設置日誌配置
* @param level
* @param fileName
* @param append
* @return this
*/
public SpiderApp setLogerConfig(int level,String fileName,boolean append,String configFilename){
logMap.put("level", level);
logMap.put("fileName", fileName);
logMap.put("append",append);
logMap.put("configFilename",configFilename);
logger = Logger.getLogger(SpiderApp.class);
Level logLevel = getLogLevel(level);
try {
FileAppender appender = new FileAppender(new SimpleLayout(), fileName,append);
if(null == configFilename){
BasicConfigurator.configure();
}else{
PropertyConfigurator.configure(configFilename);
}
logger.addAppender(appender);
logger.setLevel(logLevel);
} catch (IOException e) {
e.printStackTrace(System.err);
}
return this;
}
示例15: main
import org.apache.log4j.BasicConfigurator; //導入依賴的package包/類
public static void main(String[] args) {
BasicConfigurator.configure();
String mailTo = "[email protected]";
String mailToSms = "[email protected]";
String user = "my_username";
String password = "my_password";
List<ApplicationIdentifier> appList = new ArrayList<>();
String landscapeFqdn1 = "api.hana.ondemand.com";
String account1 = "a1";
String application1 = "app1";
ApplicationIdentifier appId1 = new ApplicationIdentifier(landscapeFqdn1, account1, application1);
appList.add(appId1);
String landscapeFqdn2 = "api.us1.hana.ondemand.com";
String account2 = "a2";
String application2 = "app2";
ApplicationIdentifier appId2 = new ApplicationIdentifier(landscapeFqdn2, account2, application2);
appList.add(appId2);
MetricsWatcher metricsWatcher = new MetricsWatcher(appList, mailTo, mailToSms, user, password);
metricsWatcher.start();
}