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 writeThrowable( Throwable t, PrintStream stream )
60 {
61 if ( t == null )
62 {
63 return;
64 }
65 stream.print( buffer().failure( t.getClass().getName() ) );
66 if ( t.getMessage() != null )
67 {
68 stream.print( ": " );
69 stream.print( buffer().failure( t.getMessage() ) );
70 }
71 stream.println();
72
73 while ( t != null )
74 {
75 for ( StackTraceElement e : t.getStackTrace() )
76 {
77 stream.print( " " );
78 stream.print( buffer().strong( "at" ) );
79 stream.print( " " + e.getClassName() + "." + e.getMethodName() );
80 stream.print( buffer().a( " (" ).strong( getLocation( e ) ).a( ")" ) );
81 stream.println();
82 }
83
84 t = t.getCause();
85 if ( t != null )
86 {
87 stream.print( buffer().strong( "Caused by" ).a( ": " ).a( t.getClass().getName() ) );
88 if ( t.getMessage() != null )
89 {
90 stream.print( ": " );
91 stream.print( buffer().failure( t.getMessage() ) );
92 }
93 stream.println();
94 }
95 }
96 }
97
98 protected String getLocation( final StackTraceElement e )
99 {
100 assert e != null;
101
102 if ( e.isNativeMethod() )
103 {
104 return "Native Method";
105 }
106 else if ( e.getFileName() == null )
107 {
108 return "Unknown Source";
109 }
110 else if ( e.getLineNumber() >= 0 )
111 {
112 return String.format( "%s:%s", e.getFileName(), e.getLineNumber() );
113 }
114 else
115 {
116 return e.getFileName();
117 }
118 }
119 }