Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
shop
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
shop
Commits
efaa4d0d
Commit
efaa4d0d
authored
Oct 06, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
9aaecc07
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
14 deletions
+12
-14
AliyunLogProducer.java
...main/java/com/egolm/shop/aliyunLog/AliyunLogProducer.java
+12
-14
No files found.
src/main/java/com/egolm/shop/aliyunLog/AliyunLogProducer.java
View file @
efaa4d0d
...
...
@@ -4,10 +4,10 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.atomic.AtomicLong
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
com.aliyun.openservices.aliyun.log.producer.Producer
;
import
com.aliyun.openservices.aliyun.log.producer.Result
;
...
...
@@ -17,6 +17,7 @@ import com.google.common.util.concurrent.FutureCallback;
import
com.google.common.util.concurrent.Futures
;
import
com.google.common.util.concurrent.ListenableFuture
;
@Component
public
class
AliyunLogProducer
{
private
static
final
ExecutorService
EXECUTOR_SERVICE
=
Executors
.
newCachedThreadPool
();
...
...
@@ -24,12 +25,11 @@ public class AliyunLogProducer {
private
static
final
String
project
=
System
.
getenv
(
"PROJECT"
);
private
static
final
String
logStore
=
System
.
getenv
(
"LOG_STORE"
);
public
static
void
sendLog
(
String
logText
)
{
public
void
sendLog
(
String
logText
)
{
try
{
final
AtomicLong
completed
=
new
AtomicLong
(
0
);
List
<
LogItem
>
logItems
=
new
ArrayList
<
LogItem
>();
ListenableFuture
<
Result
>
future
=
producer
.
send
(
project
,
logStore
,
logItems
);
Futures
.
addCallback
(
future
,
new
SampleFutureCallback
(
project
,
logStore
,
completed
),
EXECUTOR_SERVICE
);
Futures
.
addCallback
(
future
,
new
SampleFutureCallback
(
project
,
logStore
,
logText
),
EXECUTOR_SERVICE
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -43,29 +43,27 @@ public class AliyunLogProducer {
private
final
String
logStore
;
private
final
AtomicLong
completed
;
private
final
String
logText
;
SampleFutureCallback
(
String
project
,
String
logStore
,
AtomicLong
completed
)
{
SampleFutureCallback
(
String
project
,
String
logStore
,
String
logText
)
{
this
.
project
=
project
;
this
.
logStore
=
logStore
;
this
.
completed
=
completed
;
this
.
logText
=
logText
;
}
@Override
public
void
onSuccess
(
Result
result
)
{
LOGGER
.
info
(
"Send logs successfully."
);
completed
.
getAndIncrement
();
}
@Override
public
void
onFailure
(
Throwable
t
)
{
if
(
t
instanceof
ResultFailedException
)
{
Result
result
=
((
ResultFailedException
)
t
).
getResult
();
LOGGER
.
error
(
"Failed to send logs, project={}, logStore={}, result={}
"
,
project
,
logStore
,
resul
t
);
public
void
onFailure
(
Throwable
errors
)
{
if
(
errors
instanceof
ResultFailedException
)
{
Result
result
=
((
ResultFailedException
)
errors
).
getResult
();
LOGGER
.
error
(
"Failed to send logs, project={}, logStore={}, result={}
, log={}"
,
project
,
logStore
,
result
,
logTex
t
);
}
else
{
LOGGER
.
error
(
"Failed to send log
, e="
,
t
);
LOGGER
.
error
(
"Failed to send log
s, project={}, logStore={}, errors={}, log={}"
,
project
,
logStore
,
errors
,
logTex
t
);
}
completed
.
getAndIncrement
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment