Example usage for java.util.logging LogRecord LogRecord

List of usage examples for java.util.logging LogRecord LogRecord

Introduction

In this page you can find the example usage for java.util.logging LogRecord LogRecord.

Prototype

public LogRecord(Level level, String msg) 

Source Link

Document

Construct a LogRecord with the given level and message values.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {
    XMLFormatter formatter = new XMLFormatter();
    LogRecord record = new LogRecord(Level.INFO, "XML message..");

    FileHandler handler = new FileHandler("newxml.xml");
    handler.setFormatter(formatter);//from   w ww  . j  av a 2s  .c om

    handler.publish(record);
    handler.flush();
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Logger logger = Logger.getLogger("your.logging");
    ConsoleHandler handler = new ConsoleHandler();
    MemoryHandler mHandler = new MemoryHandler(handler, 10, Level.ALL);
    logger.addHandler(mHandler);//from w w w .  j  av  a2  s .co  m
    logger.setUseParentHandlers(false);
    LogRecord record1 = new LogRecord(Level.SEVERE, "This is SEVERE level message");
    LogRecord record2 = new LogRecord(Level.WARNING, "This is WARNING level message");
    logger.log(record1);
    logger.log(record2);
}

From source file:LogWindow.java

public static void main(String args[]) {
    Main demo = new Main();
    demo.logMessage();// ww w  . j a v  a  2s  .  co m
    WindowHandler h = WindowHandler.getInstance();
    LogRecord r = new LogRecord(Level.WARNING, "The Handler publish method...");
    h.publish(r);
}

From source file:samplecode.search.EveryEntry.java

/**
 * <blockquote>/*  ww w  .  j a  va 2 s .  c om*/
 * <p/>
 * <pre>
 *   Provides a way to invoke the  searchEntryReturned and
 * searchReferenceReturned
 * methods of a SearchResultListener for each entry returned from a search
 * based
 * on the standard command line options.
 *
 * Usage:  EveryEntry {options}
 *
 * Available options include:
 * -h, --hostname {host}
 *     The IP address or resolvable name to use to connect to the directory
 *     server.  If this is not provided, then a default value of 'localhost'
 * will
 *     be used.
 * -p, --port {port}
 *     The port to use to connect to the directory server.  If this is not
 *     provided, then a default value of 389 will be used.
 * -D, --bindDN {dn}
 *     The DN to use to bind to the directory server when performing simple
 *     authentication.
 * -w, --bindPassword {password}
 *     The password to use to bind to the directory server when performing
 * simple
 *     authentication or a password-based SASL mechanism.
 * -j, --bindPasswordFile {path}
 *     The path to the file containing the password to use to bind to the
 *     directory server when performing simple authentication or a
 * password-based
 *     SASL mechanism.
 * -Z, --useSSL
 *     Use SSL when communicating with the directory server.
 * -q, --useStartTLS
 *     Use StartTLS when communicating with the directory server.
 * -X, --trustAll
 *     Trust any certificate presented by the directory server.
 * -K, --keyStorePath {path}
 *     The path to the file to use as the key store for obtaining client
 *     certificates when communicating securely with the directory server.
 * -W, --keyStorePassword {password}
 *     The password to use to access the key store contents.
 * -u, --keyStorePasswordFile {path}
 *     The path to the file containing the password to use to access the key
 * store
 *     contents.
 * --keyStoreFormat {format}
 *     The format (e.g., jks, jceks, pkcs12, etc.) for the key store file.
 * -P, --trustStorePath {path}
 *     The path to the file to use as trust store when determining whether to
 *     trust a certificate presented by the directory server.
 * -T, --trustStorePassword {password}
 *     The password to use to access the trust store contents.
 * -U, --trustStorePasswordFile {path}
 *     The path to the file containing the password to use to access the
 * trust
 *     store contents.
 * --trustStoreFormat {format}
 *     The format (e.g., jks, jceks, pkcs12, etc.) for the trust store file.
 * -N, --certNickname {nickname}
 *     The nickname (alias) of the client certificate in the key store to
 * present
 *     to the directory server for SSL client authentication.
 * -o, --saslOption {name=value}
 *     A name-value pair providing information to use when performing SASL
 *     authentication.
 * --numThreads {number-of-threads}
 *     Specifies the number of threads to use when running the application.
 * --useSchema
 *     Whether the LDAP SDK should attempt to use server schema information,
 * for
 *     example, for matching rules.
 * --verbose
 *     Whether the tool should be verbose.
 * --abandonOnTimeout
 *     Whether the LDAP SDK should abandon an operation that has timed out.
 * --autoReconnect
 *     Whether the LDAP SDK should automatically reconnect when a connection
 * is
 *     lost.
 * --connectTimeoutMillis {connect-timeout-millis-integer}
 *     Specifies the maximum length of time in milliseconds that a connection
 *     attempt should be allowed to continue before giving up. A value of
 * zero
 *     indicates that there should be no connect timeout.
 * -b, --baseObject {distinguishedName}
 *     The base object used in the search request.
 * --maxResponseTimeMillis {max-response-time-in-milliseconds}
 *     The maximum length of time in milliseconds that an operation should be
 *     allowed to block, with 0 or less meaning no timeout is enforced. This
 *     command line argument is optional and has a default value of zero.
 * --reportInterval {positive-integer}
 *     The report interval in milliseconds.
 * --reportCount {positive-integer}
 *     Specifies the maximum number of reports. This command line argument is
 *     applicable to tools that display repeated reports. The time between
 *     repeated reports is specified by the --reportInterval command line
 *     argument.
 * -a, --attribute {attribute name or type}
 *     The attribute used in the search request or other request. This
 * command
 *     line argument is not required, and can be specified multiple times. If
 * this
 *     command line argument is not specified, the value '*' is used.
 * -f, --filter {filter}
 *     The search filter used in the search request.
 * -i, --initialConnections {positiveInteger}
 *     The number of initial connections to establish to directory server
 * when
 *     creating the connection pool.
 * -m, --maxConnections {positiveInteger}
 *     The maximum number of connections to establish to directory server
 * when
 *     creating the connection pool.
 * -s, --scope {searchScope}
 *     The scope of the search request; allowed values are BASE, ONE, and SUB
 * --sizeLimit {positiveInteger}
 *     The client-request maximum number of results which are returned to the
 *     client. If the number of entries which match the search parameter is
 *     greater than the client-requested size limit or the server-imposed
 * size
 *     limit a SIZE_LIMIT_EXCEEDED code is returned in the result code in the
 *     search response.
 * --timeLimit {positiveInteger}
 *     The client-request maximum time to search used by the server. If the
 * time
 *     of the search is greater than the client-requested time limit or the
 *     server-imposed time limit a TIME_LIMIT_EXCEEDED code is returned in
 * the
 *     result code in the search response.
 * --pageSize {positiveInteger}
 *     The search page size
 * --searchResultListener {class-name}
 *     The name of class which extends the AbstractSearchResultListener
 * class.
 * The
 *     searchEntryReturned method of this class is invoked when an entry is
 *     returned from a search.
 * -H, -?, --help
 *     Display usage information for this program.
 * </pre>
 * <p/>
 * </blockquote>
 *
 * @param args
 *   JVM command line arguments.
 */
public static void main(final String... args) {
    final EveryEntry everyEntry = new EveryEntry();
    final ResultCode resultCode = everyEntry.runTool(args);
    if (resultCode != null) {
        final String message = String.format("%s has completed processing. The result code was: %s",
                everyEntry.getToolName(), resultCode);
        final LogRecord logRecord = new LogRecord(Level.INFO, message);
        final String msg = new MinimalLogFormatter().format(logRecord);
        everyEntry.out(msg);
    }
}

From source file:org.apache.tomee.util.SimpleTomEEFormatterTest.java

@Test
public void formatNullThrown() throws Exception {
    final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY);
    try {/*  w w  w. jav  a  2s . c  o m*/
        final String lineSeparatorValue = "\n";
        final String logMessage = "An example log record";
        final Level level = Level.FINEST;

        System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue);
        final LogRecord logRecordInput = new LogRecord(level, logMessage);
        logRecordInput.setThrown(null);

        final Formatter formatter = new SimpleTomEEFormatter();
        final String actualFormatOutput = formatter.format(logRecordInput);

        final StringBuilder expectedFormatOutputSb = new StringBuilder(level.getLocalizedName());
        expectedFormatOutputSb.append(" - ").append(logMessage).append("\n");
        final String expectedFormatOutput = expectedFormatOutputSb.toString();

        assertEquals(expectedFormatOutput, actualFormatOutput);
    } finally {
        System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty);
    }
}

From source file:org.apache.tomee.jul.formatter.SimpleTomEEFormatterTest.java

@Test
public void formatNullThrown() throws Exception {
    final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY);
    try {//w w  w.  j a va  2s .c  om
        final String lineSeparatorValue = "\n";
        final String logMessage = "An example log record";
        final Level level = Level.FINEST;

        System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue);
        final LogRecord logRecordInput = new LogRecord(level, logMessage);
        logRecordInput.setThrown(null);

        final Formatter formatter = new SimpleTomEEFormatter();
        final String actualFormatOutput = formatter.format(logRecordInput);

        final String expectedFormatOutput = level.getLocalizedName() + " - " + logMessage + "\n";

        assertEquals(expectedFormatOutput, actualFormatOutput);
    } finally {
        System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty);
    }
}

From source file:io.proscript.jlight.Runtime.java

public static void run(CommandLine line) throws IOException {

    Environment environment = new Environment();

    if (1 == line.getArgList().size()) {
        File cwdCandidate = new File(line.getArgList().get(0));
        if (cwdCandidate.isDirectory()) {
            environment.setCwd(cwdCandidate);
        } else {/*from   ww  w .ja v  a  2  s  .c  o  m*/
            throw new IOException("Last argument must be valid source root directory");
        }
    } else {
        environment.setCwd(new File(System.getProperty("user.dir")));
    }

    if (line.hasOption("port")) {
        environment.setPort(Integer.valueOf(line.getOptionValue("port")));
    }

    if (line.hasOption("host")) {
        environment.setHost(line.getOptionValue("host"));
    }

    environment.setCacheDirectory(new File(environment.getCwd().toString() + "/.jlcache"));
    environment.setMainClassName(line.getOptionValue("class"));

    CacheManager cacheManager = new CacheManager(environment);

    try {
        cacheManager.initialize();
    } catch (IOException e) {
        log.log(Level.SEVERE, "Failed to initialize class file cache: %s", e.getMessage());
        return;
    }

    Collection<File> javaFiles = SourcesLocator.locateRecursive(environment.getCwd());

    ApplicationCompiler compiler = new ApplicationCompiler(environment.getCacheDirectory());

    boolean result = false;

    try {
        result = compiler.compile(javaFiles);
    } catch (IOException e) {
        log.log(Level.SEVERE, "Compilation failed: %s", e.getMessage());
        return;
    }

    if (!result) {
        for (Diagnostic diagnostic : compiler.getLastDiagnosticCollector().getDiagnostics()) {
            System.out.println(diagnostic.getMessage(Locale.getDefault()));
            LogRecord record = new LogRecord(Level.SEVERE, diagnostic.getMessage(Locale.getDefault()));
            log.log(record);
        }
    } else {

        Application application = buildApplication(environment);
        ThreadedHTTPServer server = new ThreadedHTTPServer(environment);
        server.run(application);
    }

    try {
        cacheManager.destroy();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.johncroth.histo.logging.LogHistogramWriterParserTest.java

@Test
public void testLogFormatter() {
    LogRecord lr = new LogRecord(Level.INFO, "foo");
    assertEquals("foo\n", LogHistogramWriter.createJavaLoggingFormatter().format(lr));
}

From source file:org.apache.tomee.jul.formatter.SimpleTomEEFormatterTest.java

@Test
public void formatNotNullThrown() throws Exception {
    final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY);

    try {//ww  w.ja  v a  2  s .  co  m
        final String lineSeparatorValue = "\n";
        final String logMessage = "An example log record";
        final Level level = Level.CONFIG;
        final String exceptionMessage = "An example exception";
        final Throwable thrown = new Exception(exceptionMessage);

        System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue);
        final LogRecord logRecordInput = new LogRecord(level, logMessage);
        logRecordInput.setThrown(thrown);

        final Formatter formatter = new SimpleTomEEFormatter();
        final String actualFormatOutput = formatter.format(logRecordInput);

        final String expectedFormatOutput = level.getLocalizedName() + " - " + logMessage + lineSeparatorValue
                + ExceptionUtils.getStackTrace(thrown);

        assertEquals(expectedFormatOutput, actualFormatOutput);
    } finally {
        System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty);
    }
}

From source file:org.apache.tomee.util.SimpleTomEEFormatterTest.java

@Test
public void formatNotNullThrown() throws Exception {
    final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY);

    try {/*from   w  w w .  java  2s  .com*/
        final String lineSeparatorValue = "\n";
        final String logMessage = "An example log record";
        final Level level = Level.CONFIG;
        final String exceptionMessage = "An example exception";
        final Throwable thrown = new Exception(exceptionMessage);

        System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue);
        final LogRecord logRecordInput = new LogRecord(level, logMessage);
        logRecordInput.setThrown(thrown);

        final Formatter formatter = new SimpleTomEEFormatter();
        final String actualFormatOutput = formatter.format(logRecordInput);

        final StringBuilder expectedFormatOutputSb = new StringBuilder(level.getLocalizedName());
        expectedFormatOutputSb.append(" - ").append(logMessage).append(lineSeparatorValue);
        expectedFormatOutputSb.append(ExceptionUtils.getStackTrace(thrown));

        final String expectedFormatOutput = expectedFormatOutputSb.toString();

        assertEquals(expectedFormatOutput, actualFormatOutput);
    } finally {
        System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty);
    }
}