This is an automated email from the ASF dual-hosted git repository.

yaohaishi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-docs.git


The following commit(s) were added to refs/heads/master by this push:
     new e3c5bad  [SCB-1451]Printing the service information on the log
e3c5bad is described below

commit e3c5bad453619b5f7921967918fab9f734ddfd87
Author: ZihangJiao <[email protected]>
AuthorDate: Thu Aug 22 17:22:30 2019 +0800

    [SCB-1451]Printing the service information on the log
---
 .../service-information-printer.md                 | 64 ++++++++++++++++++++
 .../service-information-printer.md                 | 68 ++++++++++++++++++++++
 2 files changed, 132 insertions(+)

diff --git 
a/java-chassis-reference/en_US/general-development/service-information-printer.md
 
b/java-chassis-reference/en_US/general-development/service-information-printer.md
new file mode 100644
index 0000000..684df9d
--- /dev/null
+++ 
b/java-chassis-reference/en_US/general-development/service-information-printer.md
@@ -0,0 +1,64 @@
+# Printing Service Information
+## Conception Illustration
+In order make it easier and faster for users to gather the service 
information, those data are collected and printed on the log.
+## effect
+How the printing looks like:  
+No matter the initialization of the service succeeded or not, the service 
information will be printed at the end of the log, users can search by "Service 
Information is shown below" to locate it
+```
+2019-08-21 16:37:14,859 [INFO] Service information is shown below:
+service center: [http://127.0.0.1:30100]
+config center: [http://127.0.0.1:30113]
+AppID: Restful-Service-HelloWorld
+ServiceName: restful_provider
+Version: 0.0.1
+Environment: production
+ServiceID: a3344e9ad4557f883b36d7f53e33306fbc0a54ad
+InstanceID; e0765a8ec3ee11e9910d0255ac105780
+ 
org.apache.servicecomb.core.SCBEngine$1.afterRegistryInstance(SCBEngine.java:243)
+```
+
+## extension
+### related interfaces and classes
+1. interface: BootUpInformationCollector
+> collect(): return a string,which is the information that should be printed 
on the log  
+> getOrder():return the priority of the implementation classes of 
BootUpInformationCollector, the smaller the number, the higher the priority.  
+
+### how users implement extension
+to make extension of the printing service, user need to:
+1. Create new classes that implements Interface BootUpInformationCollector, 
and set the appropriate order.
+2. Create SPI file.
+
+### example
+1. Create a new implementation class HelloCollector.
+```java
+public class HelloCollector implements BootUpInformationCollector {
+  @Override
+  public String collect() {
+    return "Hello!";
+  }
+
+  @Override
+  public int getOrder() {
+    return 5;
+  }
+}
+```
+because the order of this class is 5, it will be printed between the address 
information(order 0) and service information(order 200)  
+2. Create SPI file  
+create new SPI file under directory resources/META-INF/services  
+name of the file: 
org.apache.servicecomb.core.bootup.BootUpInformationCollector  
+content: the class name of HelloCollector  
+3. printing effect
+```
+   2019-08-21 16:37:14,859 [INFO] Service information is shown below:
+   service center: [http://127.0.0.1:30100]
+   config center: [http://127.0.0.1:30113]
+   Hello!
+   AppID: Restful-Service-HelloWorld
+   ServiceName: restful_provider
+   Version: 0.0.1
+   Environment: production
+   ServiceID: a3344e9ad4557f883b36d7f53e33306fbc0a54ad
+   InstanceID; e0765a8ec3ee11e9910d0255ac105780
+    
org.apache.servicecomb.core.SCBEngine$1.afterRegistryInstance(SCBEngine.java:243)
+```
diff --git 
a/java-chassis-reference/zh_CN/general-development/service-information-printer.md
 
b/java-chassis-reference/zh_CN/general-development/service-information-printer.md
new file mode 100644
index 0000000..af50424
--- /dev/null
+++ 
b/java-chassis-reference/zh_CN/general-development/service-information-printer.md
@@ -0,0 +1,68 @@
+# 服务信息打印
+
+## 概念阐述
+
+为了使用户可以更快捷,方便的获得服务信息,将服务信息进行整理,并在日志中打印出来
+
+## 效果
+不论服务创建成功与否,服务信息都会在日志信息的末尾被自动打出,用户可以通过搜索"Service Information is shown below"进行定位
+```
+2019-08-21 16:37:14,859 [INFO] Service information is shown below:
+service center: [http://127.0.0.1:30100]
+config center: [http://127.0.0.1:30113]
+AppID: Restful-Service-HelloWorld
+ServiceName: restful_provider
+Version: 0.0.1
+Environment: production
+ServiceID: a3344e9ad4557f883b36d7f53e33306fbc0a54ad
+InstanceID; e0765a8ec3ee11e9910d0255ac105780
+ 
org.apache.servicecomb.core.SCBEngine$1.afterRegistryInstance(SCBEngine.java:243)
+```
+
+## 扩展
+
+### 相关的接口
+接口BootUpInformationCollector
+> collect(): 返回一个string,也就是服务中需要打印的信息  
+> getOrder(): 返回BootUpInformationCollector实现类的优先级,数字越小优先级越高
+
+### 用户扩展
+
+用户如果需要对打印信息进行进一步扩展,需要
+1. 根据BootUpInformationCollector创建新的类,并赋予合适的order。
+2. 创建SPI文件
+
+### 样例
+1. 创建一个新的实现类HelloCollector
+```java
+public class HelloCollector implements BootUpInformationCollector {
+  @Override
+  public String collect() {
+    return "Hello!";
+  }
+
+  @Override
+  public int getOrder() {
+    return 5;
+  }
+}
+```
+由于order是5,所以这个类会在地址信息(order 0)和服务信息(order 200)之间被打出
+2. 创建SPI文件  
+在resources/META-INF/services中创建新的SPI文件  
+名字:org.apache.servicecomb.core.bootup.BootUpInformationCollector  
+内容:(HelloCollector的类名)  
+3. 运行效果
+```
+   2019-08-21 16:37:14,859 [INFO] Service information is shown below:
+   service center: [http://127.0.0.1:30100]
+   config center: [http://127.0.0.1:30113]
+   Hello!
+   AppID: Restful-Service-HelloWorld
+   ServiceName: restful_provider
+   Version: 0.0.1
+   Environment: production
+   ServiceID: a3344e9ad4557f883b36d7f53e33306fbc0a54ad
+   InstanceID; e0765a8ec3ee11e9910d0255ac105780
+    
org.apache.servicecomb.core.SCBEngine$1.afterRegistryInstance(SCBEngine.java:243)
+   ```
\ No newline at end of file

Reply via email to