Java Code Examples for java.util.logging.Logger.severe()

The following are Jave code examples for showing how to use severe() of the java.util.logging.Logger class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jdk8u-jdk   File: TestIsLoggable.java   View Source Code Vote up 6 votes
public void loglevel(Level l, Logger logger, String message) {
    LogTest test = LogTest.valueOf("LEV_"+l.getName());
    switch(test) {
        case LEV_SEVERE:
            logger.severe(message);
            break;
        case LEV_WARNING:
            logger.warning(message);
            break;
        case LEV_INFO:
            logger.info(message);
            break;
        case LEV_CONFIG:
            logger.config(message);
            break;
        case LEV_FINE:
            logger.fine(message);
            break;
        case LEV_FINER:
            logger.finer(message);
            break;
        case LEV_FINEST:
            logger.finest(message);
            break;
    }
}
 
Example 2
Project: Pogamut3   File: Listeners.java   View Source Code Vote up 5 votes
/**
 * Calls notifier.notify() on each of the stored listeners, allowing you to execute stored
 * command.
 * <p><p>
 * Every notification is run inside try/catch block, exceptions are reported into the log
 * (if not null) and method returns false if some exception is thrown.
 * 
 * @param notifier
 * @param exceptionLog where to log exceptions, may be null
 * @return true, if no exception happened
 */
public boolean notifySafe(ListenerNotifier<Listener> notifier, Logger exceptionLog) {
	
	boolean noException = true;
	
	synchronized(listeners) {
		boolean listenersIterationOriginal = listenersIteration;
		listenersIteration = true;
		try {
 		Iterator<ListenerStore<Listener>> iterator = listeners.iterator();
 		while(iterator.hasNext()) {
 			ListenerStore<Listener> store = iterator.next();
 			Listener storedListener = store.getListener();
 			if (storedListener == null) {
 				if (!listenersIterationOriginal) {
 					if ((store instanceof WeakListenerStore) && log != null && log.isLoggable(Level.FINE)) {
 						log.fine((name == null ? "" : name + ": ") + "Weakly referenced listener was GC()ed.");
 					}
 					iterator.remove();
 				}
 				continue;
 			}
 			try {
 				notifier.notify(storedListener);
 			} catch (Exception e) {
 				noException = false;
 				if (exceptionLog != null) {
 					if (exceptionLog.isLoggable(Level.SEVERE)) exceptionLog.severe(ExceptionToString.process("Exception during event processing (" + notifier.getEvent() + ").", e));
 				}
 			}
 		}
		} finally {
			listenersIteration = listenersIterationOriginal;
		}
	}
	
	return noException;
}
 
Example 3
Project: Pogamut3   File: PogamutException.java   View Source Code Vote up 5 votes
/**
 * Logs the exception to the log + sets isLogged() to true.
 */
public synchronized void logException(Logger log) {
	try {
		if (log == null) return;
		if (log.isLoggable(Level.SEVERE)) log.severe(ExceptionToString.process(getMessage(), this));
		this.hasBeenLogged = true;			
	} catch (Exception e) {
		System.err.println("PogamutException (and can't log to log '"+log.getName()+"' because \""+e.getMessage()+"\"), exception: " + toString());			
		this.printStackTrace(System.err);
	}			
}
 
Example 4
Project: Pogamut3   File: IniFile.java   View Source Code Vote up 5 votes
/**
 * Checks, whether THIS {@link IniFile} is the subset of 'other'.
 * @param other
 * @param thisName
 * @param otherName
 * @param log
 * @return
 */
public boolean isSubset(IniFile other, String thisName, String otherName, Logger log) {
	for (Section thisSection : this.getSections()) {
		log.info("Checking section [" + thisSection.getName() + "]");
		Section otherSection = other.getSection(thisSection.getName());
		if (otherSection == null) {
			if (log != null) log.severe(thisName + " INI contains Section[" + thisSection.getName() + "] that is not present within Read INI (source)!");
			return false;
		}
		for (String key : thisSection.getKeys()) {
			List<String> thisValues = thisSection.getAll(key);
			List<String> otherValues = new ArrayList<String>(otherSection.getAll(key));
			if (log != null) log.info("Checking key: " + key + " (" + thisValues.size() + " values)");
			
			if (thisValues.size() != otherValues.size()) {
				if (log != null) log.severe(thisName + " INI, Section[" + thisSection.getName() + "], Key[" + key + "] contains #values == " + thisValues.size() + " != " + otherValues.size() + " == #values within " + otherName + " INI (source)!");
			}
			
			for (String testValue : thisValues) {
				boolean present = false;
				for (int i = 0; i < otherValues.size(); ++i) {
					String otherValue = otherValues.get(i);
					if (SafeEquals.equals(testValue, otherValue)) {
						present = true;
						otherValues.remove(i);
						break;
					}
				}
				if (present) continue;
				// ERROR!
				if (log != null) log.severe(thisName + " INI, Section[" + thisSection.getName() + "], Key[" + key + "] contains Value[" + testValue + "] that is not present within " + otherName + " section/key!");
				return false;
			}
		}			
	}
	return true;
}
 
Example 5
Project: bibliome-java-utils   File: EventSchema.java   View Source Code Vote up 5 votes
/**
 * Checks the validity of the specified event.
 * @param logger
 * @param event
 */
public boolean check(Logger logger, Event event) {
	boolean result = true;
	for (String role : event.getRoles())
		if (!roles.containsKey(role)) {
			logger.severe(event.getId() + " (" + type + ") does not allow the role " + role);
			result = false;
		}
	for (RoleSchema roleSchema : roles.values())
		result = roleSchema.check(logger, event) && result;
	return result;
}
 
Example 6
Project: MooProject   File: RedisModule.java   View Source Code Vote up 5 votes
public RedisModule(File configFile, Logger logger) {
    this.logger = logger;
    this.configFile = configFile;
    this.redisConnection = new RedisConnection();

    try {
        this.config = configFile.getName().endsWith(".json") ? Config.fromJSON(configFile) : Config.fromYAML(configFile);
    }
    catch(IOException e) {
        logger.severe("Error while loading Redis config! " + e);
        super.finished(false);
    }
}
 
Example 7
Project: alvisnlp   File: ModuleBase.java   View Source Code Vote up 5 votes
@Override
 public void init(ProcessingContext<T> ctx) throws ModuleException {
 	Class<?> klass = searchAlvisNLPModuleAnnotation();
 	if (klass == null)
throw new RuntimeException("class does not extend a module class");
 	AlvisNLPModule annot = klass.getAnnotation(AlvisNLPModule.class);
 	if (annot.beta())
 		getLogger(ctx).warning("this module is EXPERIMENTAL");
 	Class<?>[] better = annot.obsoleteUseInstead();
 	if (better.length == 0)
 		return;
 	Logger logger = getLogger(ctx);
 	logger.severe("this module class is DEPRECATED, use instead: " + Strings.joinStrings(Arrays.asList(better), ", "));
 	logger.severe("support for this module class may be DSCONTINUED WITHOUT NOTICE");
 }
 
Example 8
Project: alvisnlp   File: AbstractAlvisNLP.java   View Source Code Vote up 5 votes
private void error(Logger logger, Exception e, String msg) {
  	logger.severe(msg);
  	if (logger.isLoggable(Level.FINEST)) {
  		for (Throwable t = e; t != null; t = t.getCause()) {
  			logger.finest(t.getClass().getCanonicalName());
  			for (StackTraceElement ste : t.getStackTrace())
  				logger.finest("    " + ste);
  		}
  	}
else
	logger.info("use -verbose option to get debug info");
  	exitCode = 1;
  }
 
Example 9
Project: bibliome-java-utils   File: RoleSchema.java   View Source Code Vote up 5 votes
/**
 * Checks the validity of the specified event for this role.
 * @param logger
 * @param event
 */
public boolean check(Logger logger, Event event) {
	if (event.hasArg(name))
		return check(logger, event.getArg(name));
	if (mandatory) {
		logger.severe(event.getId() + " has no arg with role " + name);
		return false;
	}
	return true;
}
 
Example 10
Project: alvisnlp   File: CCGParser.java   View Source Code Vote up 5 votes
@Override
public void process(ProcessingContext<Corpus> ctx, Corpus corpus) throws ModuleException {
	try {
		Logger logger = getLogger(ctx);
		EvaluationContext evalCtx = new EvaluationContext(logger);
		List<List<Layer>> sentenceRuns = getSentences(logger, evalCtx, corpus);
		for (int run = 0; run < sentenceRuns.size(); ++run) {
			logger.info(String.format("run %d/%d", run+1, sentenceRuns.size())); 
			List<Layer> sentences = sentenceRuns.get(run);
			CCGParserExternal parserExt = new CCGParserExternal(ctx, run, getMaxLength(sentences));
			TargetStream target = new FileTargetStream(internalEncoding, parserExt.input);
			try (PrintStream out = target.getPrintStream()) {
				printSentences(ctx, out, sentences, true);
			}
			try {
				callExternal(ctx, "run-ccg", parserExt, internalEncoding, "ccg.sh");
			}
			catch (ExternalFailureException e) {
				logger.severe(e.getMessage());
				logger.severe("we know sometimes CCG accidentally the sentences");
				logger.severe("let's try to proceed anyway. No guarantee...");
				logger.severe("btw, input that caused the crash: " + parserExt.input.getAbsolutePath());
			}
			try (BufferedReader r = getBufferedReader(ctx, parserExt)) {
				readSentences(ctx, r, sentences);
			}
		}
	}
	catch (UnsupportedEncodingException uee) {
		rethrow(uee);
	}
	catch (FileNotFoundException fnfe) {
		rethrow(fnfe);
	}
	catch (IOException ioe) {
		rethrow(ioe);
	}
}
 
Example 11
Project: bibliome-java-utils   File: URLSourceStream.java   View Source Code Vote up 5 votes
@Override
public boolean check(Logger logger) {
	try {
		URLConnection urlConnection = url.openConnection();
		urlConnection.connect();
		return true;
	}
	catch (IOException ioe) {
		logger.severe(ioe.getMessage());
		return false;
	}
}
 
Example 12
Project: Pogamut3   File: NetBeansPublicPackages.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
	String definition = "NetBeansPublicPackages.xml";
	if (args.length > 0) {
		definition = args[0];
		if (definition == null) definition = "NetBeansPublicPackages.xml";
	}
	
	SimpleLogging.initLogging();
	Logger log = Logger.getAnonymousLogger();
	log.info("---[[ PUBLIC PACKAGES ]]---");
	log.info("Loading definition from xml file: " + definition + " --> " + new File(definition).getAbsoluteFile());
	File file = new File(definition);
	if (!file.exists() || !file.isFile()) {
		log.severe("FAILED! Definition file not found at: " + file.getAbsolutePath());
		log.severe("Usage: java -jar NetBeansPublicPackages.jar [path-to-definition-xml-file]");
		example(log);
		log.info("---[[ END ]]---");
		System.exit(1);
		return;
	}
	NetBeansPublicPackages publicPackages;
	try {
		publicPackages = new NetBeansPublicPackages(file);
	} catch (Exception e) {
		e.printStackTrace();
		log.severe("Usage: java -jar RewriteFiles.jar [path-to-definition-xml-file]");
		example(log);
		log.info("---[[ END ]]---");
		return;
	}
	publicPackages.setLog(log);
	log.info("Definition file loaded.");
	
	boolean result = publicPackages.rewrite();
	
	
	if (result) {
		log.info("System.exit(0)");
	} else {
		log.warning("Failure! System.exit(1)!");
		System.exit(1);
	}
	
	log.info("---[[ END ]]---");
	
	if (result) {
		System.exit(0);
	} else {
		System.exit(1);
	}
	
}
 
Example 13
Project: openjdk-jdk10   File: TestInferCaller.java   View Source Code Vote up 4 votes
public void test4(Logger logger) {
    System.out.println("test4: " + loggerName(logger));
    AtomicInteger count = new AtomicInteger();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    logger.setLevel(Level.ALL);
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");

    logger.severe(() -> "message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    LogEvent event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test4", "message " + count.get());

    logger.warning(() -> "message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test4", "message " + count.get());

    logger.info(() -> "message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test4", "message " + count.get());

    logger.config(() -> "message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test4", "message " + count.get());

    logger.fine(() -> "message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test4", "message " + count.get());

    logger.finer(() -> "message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test4", "message " + count.get());

    logger.finest(() -> "message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test4", "message " + count.get());
}
 
Example 14
Project: bibliome-java-utils   File: AbstractFile.java   View Source Code Vote up 4 votes
protected static boolean checkReadable(Logger logger, File f) {
	if (f.canRead())
		return true;
	logger.severe(f.getAbsolutePath() + " cannot be read");
	return false;
}
 
Example 15
Project: bibliome-java-utils   File: AbstractFile.java   View Source Code Vote up 4 votes
protected static boolean checkWritable(Logger logger, File f) {
	if (f.canWrite())
		return true;
	logger.severe(f.getAbsolutePath() + " cannot be written");
	return false;
}
 
Example 16
Project: bibliome-java-utils   File: AbstractFile.java   View Source Code Vote up 4 votes
protected static boolean checkDirectory(Logger logger, File f) {
	if (f.isDirectory())
		return true;
	logger.severe(f.getAbsolutePath() + " is not a directory");
	return false;
}
 
Example 17
Project: openjdk-jdk10   File: TestInferCaller.java   View Source Code Vote up 4 votes
public void test1(Logger logger) {
    System.out.println("test1: " + loggerName(logger));

    AtomicInteger count = new AtomicInteger();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    logger.setLevel(Level.ALL);
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");

    logger.severe("message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    LogEvent event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test1", "message " + count.get());

    logger.warning("message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test1", "message " + count.get());

    logger.info("message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test1", "message " + count.get());

    logger.config("message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test1", "message " + count.get());

    logger.fine("message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test1", "message " + count.get());

    logger.finer("message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test1", "message " + count.get());

    logger.finest("message " + count.incrementAndGet());
    assertEquals(1, TestHandler.PUBLISHED.size(), "No event in queue: ");
    event = TestHandler.PUBLISHED.remove();
    assertEquals(0, TestHandler.PUBLISHED.size(), "Queue should be empty: ");
    checkEvent(event, this.getClass().getName(), "test1", "message " + count.get());
}
 
Example 18
Project: bibliome-java-utils   File: RoleSchema.java   View Source Code Vote up 4 votes
private boolean check(Logger logger, Entity entity) {
	if (allowedTypes.contains(entity.getType()))
		return true;
	logger.severe("role " + name + " does not allow entity of type " + entity.getType());
	return false;
}
 
Example 19
Project: bibliome-java-utils   File: AbstractFile.java   View Source Code Vote up 4 votes
protected boolean checkExecutable(Logger logger) {
	if (canExecute())
		return true;
	logger.severe(getAbsolutePath() + " is not executable");
	return false;
}
 
Example 20
Project: bibliome-java-utils   File: AbstractFile.java   View Source Code Vote up 4 votes
protected static boolean checkRegular(Logger logger, File f) {
	if (f.isFile())
		return true;
	logger.severe(f.getAbsolutePath() + " is not a regular file");
	return false;
}