Java Code Examples for java.util.logging.Level

The following are top voted examples for showing how to use java.util.logging.Level. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: netlib   File: MockAndLoggingNetAddressNameServiceLocalTest.java View source code Vote up 6 votes
@Before
public void setUp() {
    // prepare mock
    Map<String,NetAddress> name2AddressMapping = new HashMap<String,NetAddress>();
    Map<NetAddress,String> address2NameMapping = new HashMap<NetAddress,String>();
    name2AddressMapping.put(TEST1_HOSTNAME, TEST1_IP);
    name2AddressMapping.put(TEST2_HOSTNAME, TEST2_IP);
    name2AddressMapping.put(TEST3_HOSTNAME, TEST3_IP);
    address2NameMapping.put(TEST1_IP, TEST1_HOSTNAME);
    address2NameMapping.put(TEST2_IP, TEST2_HOSTNAME);
    address2NameMapping.put(TEST3_IP, TEST3_HOSTNAME);
    
    // create mock
    NetAddressNameService mockNs = new MockNetAddressNameService(name2AddressMapping, address2NameMapping);
    
    // surround by a logger
    ns = new LoggingNetAddressNameService(mockNs, Level.INFO);
}
 
Example 2
Project: sphereMiners   File: AIManager.java View source code Vote up 6 votes
/**
 * This method reinitializes an AI.
 *
 * @param ai determinate which AI should be reinitialized.
 */
private void reinitializeAi(Player ai) {
    try {
        Class<?> cl = loader.loadClass(ais.get(ai).getClass().getName());
        ais.remove(ai);
        SphereMiners2015 newAi = (SphereMiners2015) cl.newInstance();
        newAi.setPlayer(ai);
        newAi.setPhysics(physics);
        newAi.setConstants(constants);
        newAi.init();
        ais.put(ai, newAi);
    } catch (ClassNotFoundException
            | IllegalAccessException
            | InstantiationException e1) {
        constants.getLogger().log(Level.SEVERE, "AI " + ai.getInternalName() + " could not be reinitialized, ai is removed from the game");
        ais.remove(ai);
        throw new Error("Reinitialization of "
                + ais.get(ai).getClass().getName() + " FAILED!");
    }
}
 
Example 3
Project: netlib   File: TcpipLocalTest.java View source code Vote up 6 votes
public TcpipLocalTestServerThread() {
    try {
        //setDaemon(true);
        TcpipLocalTest.log.info("(server) create server socket");
        TcpipNetAddress localListenAddress = new TcpipNetAddress("0.0.0.0", TcpipLocalTest.TEST_SERVER_PORT);
        server = NetFactory.getInstance().getNetLayerById(NetLayerIDs.TCPIP).
        		createNetServerSocket(null, localListenAddress);

    } catch (IOException e) {
        TcpipLocalTest.log.log(Level.WARNING, "exception", e);
    }
}
 
Example 4
Project: credentials-plugin   File: UserCredentialsProvider.java View source code Vote up 6 votes
/**
 * [email protected]}
 */
@NonNull
@Override
public <C extends Credentials> List<C> getCredentials(@NonNull Class<C> type,
                                                      @Nullable ItemGroup itemGroup,
                                                      @Nullable Authentication authentication,
                                                      @NonNull List<DomainRequirement> domainRequirements) {
    // ignore itemGroup, as per-user credentials are available on any object
    if (authentication == null) {
        // assume ACL#SYSTEM
        authentication = ACL.SYSTEM;
    }
    if (!ACL.SYSTEM.equals(authentication)) {
        User user;
        try {
            if (authentication == null || authentication instanceof AnonymousAuthenticationToken) {
                user = null;
            } else if (authentication == Jenkins.getAuthentication()) {
                user = User.current();
            } else {
                user = User.get(authentication.getName());
            }
        } catch (NullPointerException e) {
            LogRecord lr = new LogRecord(Level.FINE,
                    "Could not find user for specified authentication. User credentials lookup aborted");
            lr.setThrown(e);
            lr.setParameters(new Object[]{authentication});
            LOGGER.log(lr);
            user = null;
        }
        if (user != null) {
            UserCredentialsProperty property = user.getProperty(UserCredentialsProperty.class);
            if (property != null) {
                return DomainCredentials
                        .getCredentials(property.getDomainCredentialsMap(), type, domainRequirements, always());
            }
        }
    }
    return new ArrayList<C>();
}
 
Example 5
Project: SafariBowl   File: User.java View source code Vote up 6 votes
/**
 * Gets the stats (touchdowns scored/received and casualties) from a game and write it to this user.
 * @param game The game to get the stats from.
 */
private void getStatsFromGame(GameController game) {
    try {
        int teamIndex = game.getTeam(0).getCoach().getName().equals(getName()) ? 0 : 1; // set the index of the team where this user was coach
        setTouchdownsScoredWithoutWrite(getTouchdownsScored() + game.getScoreFromTeam(teamIndex)); // add the score of the team where this user was coach.
        setTouchdownsReceivedWithoutWrite(getTouchdownsReceived() + game.getScoreFromTeam(teamIndex == 0 ? 1 : 0)); // add the score of the team where this user was NOT coach.
        for(Player casualty: game.getCasualties())
            if(casualty.getTeam().getCoach().getName().equals(getName()))
                setCasualties(getCasualties() + 1);
    } catch (NullPointerException e) { // the teams have not been set up yet
        manager.getParent().log(Level.FINEST, "Match has not yet started. No touchdowns have happened.");
    } finally {
        writeUser();
    }
}
 
Example 6
Project: dlna   File: FixedAndroidHandler.java View source code Vote up 6 votes
/**
 * Converts a [email protected] java.util.logging.Logger} logging level into an Android one.
 *
 * @param level The [email protected] java.util.logging.Logger} logging level.
 *
 * @return The resulting Android logging level.
 */
static int getAndroidLevel(Level level) {
    int value = level.intValue();
    if (value >= 1000) { // SEVERE
        return Log.ERROR;
    } else if (value >= 900) { // WARNING
        return Log.WARN;
    } else if (value >= 800) { // INFO
        return Log.INFO;
    } else {
        return Log.DEBUG;
    }
}
 
Example 7
Project: SOLR   File: LogLevelSelection.java View source code Vote up 6 votes
public void doPost(HttpServletRequest request,
                   HttpServletResponse response)
        throws IOException, ServletException {
  if (request.getParameter("submit").equals("set")) {

    Map paramMap = request.getParameterMap();

    Iterator iParams = paramMap.entrySet().iterator();
    while (iParams.hasNext()) {
      Map.Entry p = (Map.Entry) iParams.next();
      String name = (String) p.getKey();
      String value = ((String[]) p.getValue())[0];

      if (name.equals("submit")) continue;
      Logger logger;
      LogManager logManager = LogManager.getLogManager();
      if ("root".equals(name)) {
        logger = logManager.getLogger("");
      } else logger = logManager.getLogger(name);

      if ("unset".equals(value)) {
        if ((logger != null) && (logger.getLevel() != null)) {
          logger.setLevel(null);
          log.info("Unset log level on '" + name + "'.");
        }
      } else {
        Level level = Level.parse(value);
        if (logger == null) logger = Logger.getLogger(name);
        if (logger.getLevel() != level) {
          logger.setLevel(level);
          log.info("Set '" + name + "' to " +
                  level + " level.");
        }
      }
    }
  } else {
    log.fine("Selection form cancelled");
  }

  // Redirect back to standard get page.
  response.sendRedirect(request.getRequestURI());
}
 
Example 8
Project: PowerTool   File: PowerToolPlugin.java View source code Vote up 6 votes
private void readConfig() {
    getLogger().setLevel(config.getBoolean("debug", false) ? Level.CONFIG : null);

    playerToken = config.getString("player-token", DEFAULT_PLAYER_TOKEN);
    xToken = config.getString("x-token", DEFAULT_X_TOKEN);
    yToken = config.getString("y-token", DEFAULT_Y_TOKEN);
    zToken = config.getString("z-token", DEFAULT_Z_TOKEN);
    yAirToken = config.getString("y-air-token", DEFAULT_Y_AIR_TOKEN);
    verbose = config.getBoolean("verbose", DEFAULT_VERBOSE);
    omitFirstSlash = config.getBoolean("omit-first-slash", DEFAULT_OMIT_FIRST_SLASH);
    useDisplayNames = config.getBoolean("use-display-names", DEFAULT_USE_DISPLAY_NAMES);

    // Group options
    groupOptions.clear();
    defaultGroupOption = new GroupOption("default");
    List<?> opts = config.getList("options");
    if (opts == null) opts = Collections.emptyList();
    for (Object o : opts) {
        if (o instanceof Map<?, ?>) {
            Map<?, ?> opt = (Map<?, ?>)o;
            Object nameObj = opt.get("name");
            if (nameObj == null) {
                warn(this, "Missing name in options section");
                continue;
            }
            String name = nameObj.toString();
            
            GroupOption groupOption = new GroupOption(name);

            Object limitObj = opt.get("limit");
            if (!(limitObj instanceof Number)) {
                warn(this, "Limit for %s in options section must be a number; defaulting to -1", name);
            }
            else {
                groupOption.setLimit(((Number)limitObj).intValue());
            }
            
            if ("default".equalsIgnoreCase(name)) {
                defaultGroupOption = groupOption;
            }
            else
                groupOptions.add(groupOption);
        }
        else
            warn(this, "options section must be a list of maps");
    }
    debug(this, "defaultGroupOption = %s", defaultGroupOption);
    debug(this, "groupOptions = %s", groupOptions);
}
 
Example 9
Project: OsmUi   File: mxCoordinateAssignment.java View source code Vote up 6 votes
/**
 * Creates a coordinate assignment.
 * 
 * @param intraCellSpacing
 *            the minimum buffer between cells on the same rank
 * @param interRankCellSpacing
 *            the minimum distance between cells on adjacent ranks
 * @param orientation
 *            the position of the root node(s) relative to the graph
 * @param initialX
 *            the leftmost coordinate node placement starts at
 */
public mxCoordinateAssignment(mxHierarchicalLayout layout,
		double intraCellSpacing, double interRankCellSpacing,
		int orientation, double initialX, double parallelEdgeSpacing)
{
	this.layout = layout;
	this.intraCellSpacing = intraCellSpacing;
	this.interRankCellSpacing = interRankCellSpacing;
	this.orientation = orientation;
	this.initialX = initialX;
	this.parallelEdgeSpacing = parallelEdgeSpacing;
	setLoggerLevel(Level.OFF);
}
 
Example 10
Project: HoloAPI   File: ModuleLogger.java View source code Vote up 6 votes
public ModuleLogger(Logger parent, String... modulePath) {
    super(StringUtils.join(modulePath, "."), null);
    this.setParent(parent);
    this.setLevel(Level.ALL);
    this.modulePath = modulePath;
    StringBuilder builder = new StringBuilder();
    for (String module : modulePath) {
        builder.append("[").append(module).append("] ");
    }
    this.prefix = builder.toString();
}
 
Example 11
Project: Recipear2   File: RecipearFormatter.java View source code Vote up 6 votes
public String format(LogRecord record)
{
    StringBuilder msg = new StringBuilder();
    msg.append(this.dateFormat.format(Long.valueOf(record.getMillis())));
    Level lvl = record.getLevel();

    String name = lvl.getLocalizedName();
    if ( name == null )
    {
        name = lvl.getName();        	
    }

    if ( ( name != null ) && ( name.length() > 0 ) )
    {
        msg.append(" [" + name + "] ");
    }
    else
    {
        msg.append(" ");
    }
    msg.append(record.getMessage());
    msg.append(LINE_SEPARATOR);
    Throwable thr = record.getThrown();

    if (thr != null)
    {
        StringWriter thrDump = new StringWriter();
        thr.printStackTrace(new PrintWriter(thrDump));
        msg.append(thrDump.toString());
    }

    return msg.toString();
}
 
Example 12
Project: nuCommander   File: DebugConsoleDialog.java View source code Vote up 6 votes
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    if(value==null)
        return null;

    // TODO: line-wrap log items when the text is too long to fit on a single line
    // A single-column JTable may be the easiest way to go, see:
    // http://javaspecialists.co.za/archive/newsletter.do?issue=106&locale=en_US
    // http://forums.sun.com/thread.jspa?threadID=702740&start=0&tstart=0

    // Using a JTextArea with line-wrapping enabled does not work as a JList has by design a fixed height
    // for cells

    JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

    // Change the label's foreground color to match the level of the log record
    if(!isSelected) {
        Level level = ((LogRecordListItem)value).getLogRecord().getLevel();
        Color color;

        if(level.equals(Level.SEVERE))
            color = Color.RED;
        else if(level.equals(Level.WARNING))
            color = new Color(255, 100, 0);     // Dark orange
        else if(level.equals(Level.CONFIG))
            color = Color.BLUE;
        else if(level.equals(Level.INFO))
            color = Color.BLACK;
        else if(level.equals(Level.FINE))
            color = Color.DARK_GRAY;
        else
            color = new Color(110, 110, 110);    // Between Color.GRAY and Color.DARK_GRAY

        label.setForeground(color);
    }

    // TODO: remove this when line-wrapping has been implemented
    // If component's preferred width is larger than the list's width then the component is not entirely
    // visible. In that case, we set a tooltip text that will display the whole text when mouse is over the
    // component
    if (recordsList.getVisibleRect().getWidth() < label.getPreferredSize().getWidth())
        label.setToolTipText(label.getText());
    // Have to set it to null because of the rubber-stamp rendering scheme (last value is kept)
    else
        label.setToolTipText(null);
    
    return label;
}
 
Example 13
Project: dlna   File: LogCategories.java View source code Vote up 5 votes
public LogCategories() {
    super(10);

    add(new LogCategory("Network", new LogCategory.Group[]{

            new LogCategory.Group(
                    "UDP communication",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.DatagramIO.class.getName(), Level.FINE),
                            new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.MulticastReceiver.class.getName(), Level.FINE),
                    }
            ),

            new LogCategory.Group(
                    "UDP datagram processing and content",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.DatagramProcessor.class.getName(), Level.FINER)
                    }
            ),

            new LogCategory.Group(
                    "TCP communication",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.UpnpStream.class.getName(), Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.StreamServer.class.getName(), Level.FINE),
                            new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.StreamClient.class.getName(), Level.FINE),
                    }
            ),

            new LogCategory.Group(
                    "SOAP action message processing and content",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.SOAPActionProcessor.class.getName(), Level.FINER)
                    }
            ),

            new LogCategory.Group(
                    "GENA event message processing and content",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.GENAEventProcessor.class.getName(), Level.FINER)
                    }
            ),

            new LogCategory.Group(
                    "HTTP header processing",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel(org.teleal.cling.model.message.UpnpHeaders.class.getName(), Level.FINER)
                    }
            ),
    }));


    add(new LogCategory("UPnP Protocol", new LogCategory.Group[]{

            new LogCategory.Group(
                    "Discovery (Notification & Search)",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.ProtocolFactory.class.getName(), Level.FINER),
                            new LogCategory.LoggerLevel("org.teleal.cling.protocol.async", Level.FINER)
                    }
            ),

            new LogCategory.Group(
                    "Description",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.ProtocolFactory.class.getName(), Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.RetrieveRemoteDescriptors.class.getName(), Level.FINE),
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.ReceivingRetrieval.class.getName(), Level.FINE),
                            new LogCategory.LoggerLevel(org.teleal.cling.binding.xml.DeviceDescriptorBinder.class.getName(), Level.FINE),
                            new LogCategory.LoggerLevel(org.teleal.cling.binding.xml.ServiceDescriptorBinder.class.getName(), Level.FINE),
                    }
            ),

            new LogCategory.Group(
                    "Control",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.ProtocolFactory.class.getName(), Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.ReceivingAction.class.getName(), Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.SendingAction.class.getName(), Level.FINER),
                    }
            ),

            new LogCategory.Group(
                    "GENA ",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel("org.teleal.cling.model.gena", Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.ProtocolFactory.class.getName(), Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.ReceivingEvent.class.getName(), Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.ReceivingSubscribe.class.getName(), Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.ReceivingUnsubscribe.class.getName(), Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.SendingEvent.class.getName(), Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.SendingSubscribe.class.getName(), Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.SendingUnsubscribe.class.getName(), Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.SendingRenewal.class.getName(), Level.FINER),
                    }
            ),
    }));

    add(new LogCategory("Core", new LogCategory.Group[]{

            new LogCategory.Group(
                    "Router",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel(org.teleal.cling.transport.Router.class.getName(), Level.FINER)
                    }
            ),

            new LogCategory.Group(
                    "Registry",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel(org.teleal.cling.registry.Registry.class.getName(), Level.FINER),
                    }
            ),

            new LogCategory.Group(
                    "Local service binding & invocation",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel("org.teleal.cling.binding.annotations", Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.model.meta.LocalService.class.getName(), Level.FINER),
                            new LogCategory.LoggerLevel("org.teleal.cling.model.action", Level.FINER),
                            new LogCategory.LoggerLevel("org.teleal.cling.model.state", Level.FINER),
                            new LogCategory.LoggerLevel(org.teleal.cling.model.DefaultServiceManager.class.getName(), Level.FINER)
                    }
            ),

            new LogCategory.Group(
                    "Control Point interaction",
                    new LogCategory.LoggerLevel[]{
                            new LogCategory.LoggerLevel("org.teleal.cling.controlpoint", Level.FINER),
                    }
            ),
    }));

}