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