未验证 提交 193fc301 编写于 作者: Y youyong205 提交者: GitHub

Merge pull request #1330 from stdrickforce/cat-client

Update Java cat-client docs.
......@@ -111,7 +111,7 @@ catClientInitWithConfig("ccat", &config);
Disable the `ccat`, shutdown `sender`, `monitor` and `aggregator` threads.
Also release all the resources that have been used.
And then release all the resources that have been used.
```c
int catClientDestroy();
......
......@@ -64,7 +64,7 @@ int main() {
## API list
All the `cppcat` apis are in the `cat` namespace.
All the `cppcat` APIs are in the `cat` namespace.
### Common apis
......@@ -84,7 +84,7 @@ Following config is used by default.
* `enableMultiprocessing` is false.
* `enableDebugLog` is false.
You can also customize config. (Like to use text encoder instead of binary encoder)
You can also customize config. (Like to use text encoder instead of the binary encoder)
```cpp
cat::Config c = cat::Config();
......@@ -97,7 +97,7 @@ cat::init("cppcat", c);
Disable the cat client, shutdown `sender`, `monitor` and `aggregator` threads.
Also release all the resources that have been used.
And then release all the resources that have been used.
```cpp
void destroy();
......
# Cat Client Java
# Cat Client for Java
[中文文档](./doc/zh-CN.md)
[中文文档](./README.zh-CN.md)
The java cat client supports JDK 1.6+
......@@ -28,11 +28,11 @@ app.name={appkey}
> Only English characters (a-z, A-Z), numbers (0-9), underscore (\_) and dash (-) is allowed in appkey.
Due to java cat client will be lazy initialized, it's not necessary to initialize it manually.
Due to java cat client will be lazily initialized, it's not necessary to initialize it manually.
## Quickstart
```
```java
Transaction t = Cat.newTransaction("URL", "pageName");
try {
......@@ -51,13 +51,13 @@ try {
}
```
## Api List
## API List
### Transaction
> To avoid of forgetting to complete the Transaction, it's better to surround the Transaction by a try-catch-finally block.
> To avoid forgetting to complete the Transaction, it's better to surround the Transaction by a try-catch-finally block.
```
```java
Transaction t = Cat.newTransaction("URL", "pageName");
try {
......@@ -82,7 +82,7 @@ We offered a series of APIs to modify the Transaction.
These APIs can be easily used with the following codes.
```
```java
Transaction t = Cat.newTransaction("URL", "pageName");
try {
......@@ -111,28 +111,29 @@ There is something you have to know about the transaction APIs:
Log an event.
```
```java
# Log an event with success status and empty data.
Cat.logEvent("URL.Server", "serverIp");
# Log an event with given status and given data.
Cat.logEvent("URL.Server", "serverIp", "failed", "ip=${serverIp}");
```
#### Cat.logError
Log an error with error stack info.
Error is a special event, the type of it depend on the class of the given `Throwable e`.
1. If `e` is an instanceof `Error`, the `type` will be set to `Error`
2. Else if `e` is an instanceof `RuntimeException`, the `type` will be set to `RuntimeException`
1. If `e` is an instanceof `Error`, the `type` will be set to `Error`.
2. Else if `e` is an instanceof `RuntimeException`, the `type` will be set to `RuntimeException`.
3. The `type` will be set to `Exception` in the other cases.
`name` will be set to the `e.getClass().getName()` by default.
And the stack info will be built and set to `data`.
```
```java
try {
1 / 0;
} catch (Exception e) {
......@@ -142,17 +143,13 @@ try {
You can append your own error message to the top of the stack info like this:
```
try {
1 / 0;
} catch (Exception e) {
Cat.logError("error(X) := exception(X)", e);
}
```java
Cat.logError("error(X) := exception(X)", e);
```
#### Cat.logErrorWithCategory
Though `name` has been set to the classname of the given `throwable e` by default, you can use this api to overwrite it.
Though `name` has been set to the classname of the given `throwable e` by default, you can use this API to overwrite it.
```java
Exception e = new Exception("syntax error");
......@@ -168,7 +165,7 @@ Cat.logErrorWithCategory("custom-category", "?- X = Y, Y = 2", e);
### Metric
```
```java
# Counter
Cat.logMetricForCount("metric.key");
Cat.logMetricForCount("metric.key", 3);
......@@ -177,24 +174,24 @@ Cat.logMetricForCount("metric.key", 3);
Cat.logMetricForDuration("metric.key", 5);
```
We do aggregate every seconds.
We do aggregate every second.
For example, if you have called count 3 times in one second (with the same name), we will just summarised the value of them and reported once to the server.
For example, if you have called count 3 times in one second (with the same name), we will just summarise the value of them and reported once to the server.
In case of `duration`, we use `averaged` value instead of `summarised` value.
In the case of `duration`, we use `averaged` value instead of `summarised` value.
## Integration
### Log component integration
[log4j](../../integration/log4j/README.md)
[log4j2](../../integration/log4j2/README.md)
[logback](../../integration/logback/README.md)
* [log4j](../../integration/log4j/README.md)
* [log4j2](../../integration/log4j2/README.md)
* [logback](../../integration/logback/README.md)
### URL monitoring integration
[URL monitoring integration with web.xml](../../integration/URL/README.md)
[URL monitoring integration with springboot](../../integration/spring-boot/README.md)
* [URL monitoring integration with web.xml](../../integration/URL/README.md)
* [URL monitoring integration with springboot](../../integration/spring-boot/README.md)
### Other integration solutions
......
......@@ -47,7 +47,7 @@ try {
}
```
## Api List
## API List
### Transaction
......@@ -114,6 +114,7 @@ Cat.logEvent("URL.Server", "serverIp");
# Log an event with given status and given data.
Cat.logEvent("URL.Server", "serverIp", Event.SUCCESS, "ip=${serverIp}");
```
#### Cat.logError
记录一个带有错误堆栈信息的 Error。
......@@ -161,7 +162,7 @@ Cat.logErrorWithCategory("custom-category", "?- X = Y, Y = 2", e);
记录业务指标的总和或平均值。
```
```java
# Counter
Cat.logMetricForCount("metric.key");
Cat.logMetricForCount("metric.key", 3);
......
......@@ -32,9 +32,9 @@ cat.init("appkey")
### Coroutine Mode
Since we are using `ThreadLocal` to storage the transaction stack in `ccat`, which is neccessary to build the `message tree`, and `pycat` is highly dependent on `ccat`. (with cffi)
Since we are using `ThreadLocal` to storage the transaction stack in `ccat`, which is necessary to build the `message tree`, and `pycat` is highly dependent on `ccat`. (with cffi)
So we don't support message tree in `coroutine` modes, like `gevent`, `greenlet` because different coroutines that in the same thread run alternately.
So we don't support message tree in `coroutine` modes, like `gevent`, `greenlet` because of different coroutines that in the same thread run alternately.
In these cases, you should use the following code to initialize `pycat`.
......@@ -64,7 +64,7 @@ cat.init("appkey", encoder=cat.ENCODER_TEXT)
Sometimes you may want to enable the debug log.
Note the logs will be outputed to `console`.
Note the logs will be outputted to `console`.
```python
cat.init("appkey", debug=True)
......@@ -93,7 +93,7 @@ with cat.Transaction("foo", "bar") as t:
time.sleep(1)
```
## Api List
## API List
### Transaction
......@@ -102,13 +102,13 @@ t = cat.Transaction("Trans", "t3")
t.complete()
```
To avoid of forgetting to complete the transaction, we strongly recommend you to surround the transaction by a `try-finally` block, and complete the transaction in the `finally` code block.
To avoid forgetting to complete the transaction, we strongly recommend you to surround the transaction by a `try-finally` block and complete the transaction in the `finally` code block.
```python
try:
t = cat.Transaction("Trans", "t3")
t = cat.Transaction("Trans", "t3")
finally:
t.complete()
t.complete()
```
We also provide `decorator` and `context manager` usages, which can complete the transaction automatically.
......@@ -126,9 +126,9 @@ def test():
cat.log_event("Event", "E2")
```
If something goes wrong in the decorated function, the status of the transaction will be set to `FAILED`, and whatever the function raised a exception or not, the transaction will be auto-completed.
If something goes wrong in the decorated function, the status of the transaction will be set to `FAILED`, and whatever the function raised an exception or not, the transaction will be auto-completed.
The only problem is that you can't get the transaction object if you monitor a function via decorator.
The only problem is that you can't get the transaction object if you monitor a function via a decorator.
#### via context manager
......@@ -142,7 +142,7 @@ with cat.Transaction("Transaction", "T1") as t:
t.add_data("hello world!")
```
If something goes wrong in the `with` context, the status of the transaction will be set to `FAILED`, and whatever the code block raised a exception or not, the transaction will be auto-completed.
If something goes wrong in the `with` context, the status of the transaction will be set to `FAILED`, and whatever the code block raised an exception or not, the transaction will be auto-completed.
Though it is a bit complex, you can get the transaction object :)
......@@ -256,8 +256,8 @@ cat.metric("metric1").count(5)
cat.metric("metric2").duration(100)
```
We do aggregate every seconds.
We do aggregate every second.
For example, if you have called count 3 times in one second (with the same name), we will just summarised the value of them and report once to the server.
For example, if you have called count 3 times in one second (with the same name), we will just summarise the value of them and report once to the server.
In case of `duration`, we use `averaged` value instead of `summarised` value.
In the case of `duration`, we use `averaged` value instead of `summarised` value.
......@@ -91,7 +91,7 @@ with cat.Transaction("foo", "bar") as t:
time.sleep(1)
```
## Api List
## API List
### Transaction
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册