Skip to content

Commit

Permalink
Fixed logging format!
Browse files Browse the repository at this point in the history
  • Loading branch information
FroMage committed Dec 20, 2011
1 parent dbe3d6b commit 0a93d30
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
45 changes: 45 additions & 0 deletions spi/src/main/java/ceylon/modules/CeylonLogFormatter.java
@@ -0,0 +1,45 @@
/*
* Copyright 2011 Red Hat inc. and third party contributors as noted
* by the author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ceylon.modules;

import java.util.logging.Formatter;
import java.util.logging.Level;
import java.util.logging.LogRecord;

public class CeylonLogFormatter extends Formatter {
private static final String MESSAGE_PATTERN = "%s: %s %s\n";

@Override
public String format(LogRecord record) {
return String.format(
MESSAGE_PATTERN,
getErrorType(record.getLevel()),
record.getMessage(),
record.getThrown() == null ? "" : record.getThrown());
}

private String getErrorType(Level level) {
if(level == Level.WARNING)
return "Warning";
if(level == Level.INFO)
return "Note";
if(level == Level.SEVERE)
return "Error";
return "Debug";
}

}
21 changes: 17 additions & 4 deletions spi/src/main/java/ceylon/modules/Main.java
Expand Up @@ -17,13 +17,16 @@

package ceylon.modules;

import ceylon.modules.spi.ArgumentType;
import ceylon.modules.spi.Constants;
import ceylon.modules.spi.Executable;

import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.util.Arrays;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Logger;

import ceylon.modules.spi.ArgumentType;
import ceylon.modules.spi.Constants;
import ceylon.modules.spi.Executable;

/**
* Main Ceylon Modules entry point.
Expand All @@ -32,6 +35,16 @@
*/
public class Main {
public static void main(String[] args) {
try {
for(Handler handler : Logger.getLogger("").getHandlers()){
// this is a hack, but at least it works. With a property file our log formatter has to be in the
// boot class path. This way it doesn't.
if(handler instanceof ConsoleHandler)
handler.setFormatter(new CeylonLogFormatter());
}
} catch (Throwable ex) {
System.err.println("Warning: log configuration failed");
}
try {
execute(args);
} catch (CeylonRuntimeException x) {
Expand Down

0 comments on commit 0a93d30

Please sign in to comment.