1 package org.slf4j.impl;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
23
24 import java.io.PrintStream;
25
26
27
28
29
30
31 public class MavenSimpleLogger
32 extends SimpleLogger
33 {
34 MavenSimpleLogger( String name )
35 {
36 super( name );
37 }
38
39 @Override
40 protected String renderLevel( int level )
41 {
42 switch ( level )
43 {
44 case LOG_LEVEL_TRACE:
45 return buffer().debug( "TRACE" ).toString();
46 case LOG_LEVEL_DEBUG:
47 return buffer().debug( "DEBUG" ).toString();
48 case LOG_LEVEL_INFO:
49 return buffer().info( "INFO" ).toString();
50 case LOG_LEVEL_WARN:
51 return buffer().warning( "WARNING" ).toString();
52 case LOG_LEVEL_ERROR:
53 default:
54 return buffer().error( "ERROR" ).toString();
55 }
56 }
57
58 @Override
59 protected void renderThrowable( Throwable t, PrintStream stream )
60 {
61 stream.print( buffer().failure( t.getClass().getName() ) );
62 if ( t.getMessage() != null )
63 {
64 stream.print( ": " );
65 stream.print( buffer().failure( t.getMessage() ) );
66 }
67 stream.println();
68
69 while ( t != null )
70 {
71 for ( StackTraceElement e : t.getStackTrace() )
72 {
73 stream.print( " " );
74 stream.print( buffer().strong( "at" ) );
75 stream.print( " " + e.getClassName() + "." + e.getMethodName() );
76 stream.print( buffer().a( " (" ).strong( getLocation( e ) ).a( ")" ) );
77 stream.println();
78 }
79
80 t = t.getCause();
81 if ( t != null )
82 {
83 stream.print( buffer().strong( "Caused by" ).a( ": " ).a( t.getClass().getName() ) );
84 if ( t.getMessage() != null )
85 {
86 stream.print( ": " );
87 stream.print( buffer().failure( t.getMessage() ) );
88 }
89 stream.println();
90 }
91 }
92 }
93
94 protected String getLocation( final StackTraceElement e )
95 {
96 assert e != null;
97
98 if ( e.isNativeMethod() )
99 {
100 return "Native Method";
101 }
102 else if ( e.getFileName() == null )
103 {
104 return "Unknown Source";
105 }
106 else if ( e.getLineNumber() >= 0 )
107 {
108 return String.format( "%s:%s", e.getFileName(), e.getLineNumber() );
109 }
110 else
111 {
112 return e.getFileName();
113 }
114 }
115 }