-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
333 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...s/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/banner/PinpointBannerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.navercorp.pinpoint.bootstrap.banner; | ||
|
||
import com.navercorp.pinpoint.bootstrap.BootLogger; | ||
import com.navercorp.pinpoint.common.Version; | ||
import com.navercorp.pinpoint.common.banner.PinpointBanner; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Properties; | ||
|
||
public class PinpointBannerImpl extends PinpointBanner { | ||
private BootLogger logger; | ||
private Properties properties; | ||
|
||
public PinpointBannerImpl(List<String> keysToPrint, BootLogger logger) { | ||
this.pinpointBannerMode = Mode.CONSOLE; | ||
this.logger = Objects.requireNonNull(logger, "logger"); | ||
this.keysToPrint = Objects.requireNonNull(keysToPrint, "keysToPrint"); | ||
} | ||
|
||
public void setPinpointBannerProperty(Properties properties) { | ||
this.properties = Objects.requireNonNull(properties, "properties"); | ||
} | ||
|
||
@Override | ||
public void setPinpointBannerMode(Mode mode) { | ||
this.pinpointBannerMode = mode; | ||
} | ||
|
||
@Override | ||
public void printBanner() { | ||
if ( properties == null ) { | ||
logger.warn("Property not ready for Pinpoint Banner"); | ||
return; | ||
} | ||
|
||
switch (this.pinpointBannerMode) { | ||
case OFF: | ||
return; | ||
case LOG: | ||
printBanner(logger); | ||
return; | ||
default: | ||
printBanner(System.out); | ||
return; | ||
} | ||
} | ||
|
||
private void printBanner(PrintStream out) { | ||
for (String line : BANNER) { | ||
out.println(line); | ||
} | ||
out.println(format("Pinpoint Version", Version.VERSION)); | ||
|
||
for (String key: keysToPrint) { | ||
String value = properties.getProperty(key); | ||
if ( value != null ) { | ||
out.println(format(key, value)); | ||
} | ||
} | ||
|
||
out.println(); | ||
} | ||
|
||
private void printBanner(BootLogger logger) { | ||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
PrintStream ps = new PrintStream(outputStream); | ||
printBanner(ps); | ||
logger.info(outputStream.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...erver/src/main/java/com/navercorp/pinpoint/common/server/banner/PinpointSpringBanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.navercorp.pinpoint.common.server.banner; | ||
|
||
import com.navercorp.pinpoint.common.Version; | ||
import com.navercorp.pinpoint.common.banner.PinpointBanner; | ||
import com.navercorp.pinpoint.common.server.util.ServerBootLogger; | ||
import org.springframework.boot.context.event.ApplicationStartedEvent; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.core.env.Environment; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
public class PinpointSpringBanner extends PinpointBanner implements ApplicationListener<ApplicationStartedEvent> { | ||
private ServerBootLogger logger = ServerBootLogger.getLogger(PinpointSpringBanner.class); | ||
|
||
private Environment environment; | ||
|
||
public PinpointSpringBanner() { | ||
this.pinpointBannerMode = Mode.CONSOLE; | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(ApplicationStartedEvent event) { | ||
environment = event.getApplicationContext().getEnvironment(); | ||
|
||
String bannerMode = environment.getProperty("pinpoint.banner.mode"); | ||
String bannerConfigs = environment.getProperty("pinpoint.banner.configs"); | ||
|
||
Mode mode; | ||
if (bannerMode == null) { | ||
mode = Mode.CONSOLE; | ||
} else { | ||
mode = PinpointBanner.Mode.valueOf(bannerMode.toUpperCase()); | ||
} | ||
this.setPinpointBannerMode(mode); | ||
|
||
if (bannerConfigs == null) { | ||
this.keysToPrint = new ArrayList<>(); | ||
} else { | ||
this.keysToPrint = Arrays.asList(bannerConfigs.split(",")); | ||
} | ||
|
||
printBanner(); | ||
} | ||
|
||
@Override | ||
public void printBanner() { | ||
if ( environment == null ) { | ||
logger.info("Environment not ready for banner."); | ||
return; | ||
} | ||
|
||
switch (this.pinpointBannerMode) { | ||
case OFF: | ||
return; | ||
case LOG: | ||
printBanner(logger); | ||
return; | ||
default: | ||
printBanner(System.out); | ||
return; | ||
} | ||
} | ||
|
||
private void printBanner(ServerBootLogger logger) { | ||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
PrintStream ps = new PrintStream(outputStream); | ||
printBanner(ps); | ||
logger.info(outputStream.toString()); | ||
} | ||
|
||
private void printBanner(PrintStream out) { | ||
for (String line : BANNER) { | ||
out.println(line); | ||
} | ||
out.println(format("Pinpoint Version", Version.VERSION)); | ||
|
||
for (String key: this.keysToPrint) { | ||
String value = environment.getProperty(key); | ||
if ( value != null ) { | ||
out.println(format(key, value)); | ||
} | ||
} | ||
|
||
out.println(); | ||
} | ||
|
||
@Override | ||
public void setPinpointBannerMode(Mode mode) { | ||
this.pinpointBannerMode = mode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
commons/src/main/java/com/navercorp/pinpoint/common/banner/PinpointBanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.navercorp.pinpoint.common.banner; | ||
|
||
import java.util.List; | ||
|
||
public abstract class PinpointBanner { | ||
protected Mode pinpointBannerMode; | ||
protected List<String> keysToPrint; | ||
|
||
protected final String BANNER[] = { | ||
"", | ||
" 88888888ba 88 888b 88 88888888ba ,ad8888ba, 88 888b 88 888888888888", | ||
" 88 ,8P 88 88 `8b 88 88 ,8P d8' `8b 88 88 `8b 88 88", | ||
" 88aaaaaa8P' 88 88 `8b 88 88aaaaaa8P' 88 da 88 88 88 `8b 88 88", | ||
" 88 88 88 `8b 88 88 Y8, ,8P 88 88 `8b 88 88", | ||
" 88 88 88 `888 88 `\"Y8888Y\"' 88 88 `888 88", | ||
"", | ||
" https://github.com/pinpoint-apm/pinpoint", | ||
"", | ||
}; | ||
|
||
public abstract void printBanner(); | ||
public abstract void setPinpointBannerMode(Mode mode); | ||
|
||
protected String format(String key, String value) { | ||
return String.format(" :: %55s :: %35s", key, value); | ||
} | ||
|
||
public static enum Mode { | ||
OFF, | ||
CONSOLE, | ||
LOG; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters