test/java/util/logging/SimpleFormatterFormat.java

Print this page
rev 6099 : 8003380: Compiler warnings in logging test code
Summary: Use generics, suppress warnings where appropriate, remove unused imports, etc.
Reviewed-by: lancea, chegar
   1 /*
   2  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  75             Logger foo = Logger.getLogger("test.foo");
  76             foo.log(Level.SEVERE, "{0} {1} {2}", new Object[] {"severe", "hello", "world"});
  77             foo.warning(messages[1]);
  78 
  79             Logger bar = Logger.getLogger("test.bar");
  80             bar.finest("Dummy message");
  81             bar.info(messages[2]);
  82             bar.log(Level.WARNING, messages[3], new IllegalArgumentException());
  83 
  84         } finally {
  85             logps.flush();
  86             logps.close();
  87             System.setErr(err);
  88         }
  89     }
  90 
  91     private static void checkLogRecords(File log) throws Exception {
  92         System.out.println("Checking log records in file: " + log);
  93         Pattern p = Pattern.compile("([\\.a-zA-Z:]+) (.*) \\[.*\\] source: (.*)");
  94 
  95         try (FileInputStream in = new FileInputStream(log)) {
  96             BufferedReader reader = new BufferedReader(new InputStreamReader(in));

  97             String line;
  98             int i = 0;
  99             while (i < messages.length &&
 100                       (line = reader.readLine()) != null) {
 101                 String expectedLogger = loggers[i];
 102                 String expectedMsg = messages[i];
 103                 i++;
 104 
 105                 line = line.trim();
 106                 System.out.println(line);
 107 
 108                 Matcher m = p.matcher(line);
 109                 if (!m.matches()) {
 110                     throw new RuntimeException("Unexpected output format");
 111                 }
 112                 if (m.groupCount() != 3) {
 113                     throw new RuntimeException("Unexpected group count = " +
 114                         m.groupCount());
 115                 }
 116                 // verify logger name and level


   1 /*
   2  * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  75             Logger foo = Logger.getLogger("test.foo");
  76             foo.log(Level.SEVERE, "{0} {1} {2}", new Object[] {"severe", "hello", "world"});
  77             foo.warning(messages[1]);
  78 
  79             Logger bar = Logger.getLogger("test.bar");
  80             bar.finest("Dummy message");
  81             bar.info(messages[2]);
  82             bar.log(Level.WARNING, messages[3], new IllegalArgumentException());
  83 
  84         } finally {
  85             logps.flush();
  86             logps.close();
  87             System.setErr(err);
  88         }
  89     }
  90 
  91     private static void checkLogRecords(File log) throws Exception {
  92         System.out.println("Checking log records in file: " + log);
  93         Pattern p = Pattern.compile("([\\.a-zA-Z:]+) (.*) \\[.*\\] source: (.*)");
  94 
  95         try (FileInputStream in = new FileInputStream(log);
  96                 BufferedReader reader = new BufferedReader(new InputStreamReader(in));
  97                 ) {
  98             String line;
  99             int i = 0;
 100             while (i < messages.length &&
 101                       (line = reader.readLine()) != null) {
 102                 String expectedLogger = loggers[i];
 103                 String expectedMsg = messages[i];
 104                 i++;
 105 
 106                 line = line.trim();
 107                 System.out.println(line);
 108 
 109                 Matcher m = p.matcher(line);
 110                 if (!m.matches()) {
 111                     throw new RuntimeException("Unexpected output format");
 112                 }
 113                 if (m.groupCount() != 3) {
 114                     throw new RuntimeException("Unexpected group count = " +
 115                         m.groupCount());
 116                 }
 117                 // verify logger name and level