Skip to content

Commit 16416dd

Browse files
author
Mark
committed
getLogs()
1 parent 815603c commit 16416dd

File tree

9 files changed

+446
-0
lines changed

9 files changed

+446
-0
lines changed

src/main/java/com/arangodb/ArangoDB.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
import javax.net.ssl.SSLContext;
3030

3131
import com.arangodb.entity.ArangoDBVersion;
32+
import com.arangodb.entity.LogEntity;
3233
import com.arangodb.entity.UserEntity;
3334
import com.arangodb.internal.ArangoDBConstants;
3435
import com.arangodb.internal.CollectionCache;
3536
import com.arangodb.internal.DocumentCache;
3637
import com.arangodb.internal.velocypack.VPackConfigure;
3738
import com.arangodb.internal.velocystream.Communication;
3839
import com.arangodb.model.DBCreateOptions;
40+
import com.arangodb.model.LogOptions;
3941
import com.arangodb.model.OptionsBuilder;
4042
import com.arangodb.model.UserCreateOptions;
4143
import com.arangodb.model.UserUpdateOptions;
@@ -585,4 +587,46 @@ public Response execute(final Request request) {
585587
public CompletableFuture<Response> executeAsync(final Request request) {
586588
return executeAsync(request, response -> response);
587589
}
590+
591+
/**
592+
* Returns fatal, error, warning or info log messages from the server's global log.
593+
*
594+
* @see <a href=
595+
* "https://docs.arangodb.com/current/HTTP/AdministrationAndMonitoring/index.html#read-global-logs-from-the-server">API
596+
* Documentation</a>
597+
* @param options
598+
* Additional options, can be null
599+
* @return the log messages
600+
* @throws ArangoDBException
601+
*/
602+
public LogEntity getLogs(final LogOptions options) throws ArangoDBException {
603+
return executeSync(getLogsRequest(options), LogEntity.class);
604+
}
605+
606+
/**
607+
* Returns fatal, error, warning or info log messages from the server's global log.
608+
*
609+
* @see <a href=
610+
* "https://docs.arangodb.com/current/HTTP/AdministrationAndMonitoring/index.html#read-global-logs-from-the-server">API
611+
* Documentation</a>
612+
* @param options
613+
* Additional options, can be null
614+
* @return the log messages
615+
*/
616+
public CompletableFuture<LogEntity> getLogsAsync(final LogOptions options) {
617+
return executeAsync(getLogsRequest(options), LogEntity.class);
618+
}
619+
620+
private Request getLogsRequest(final LogOptions options) {
621+
final LogOptions params = options != null ? options : new LogOptions();
622+
return new Request(ArangoDBConstants.SYSTEM, RequestType.GET, ArangoDBConstants.PATH_API_ADMIN_LOG)
623+
.putQueryParam(LogOptions.PROPERTY_UPTO, params.getUpto())
624+
.putQueryParam(LogOptions.PROPERTY_LEVEL, params.getLevel())
625+
.putQueryParam(LogOptions.PROPERTY_START, params.getStart())
626+
.putQueryParam(LogOptions.PROPERTY_SIZE, params.getSize())
627+
.putQueryParam(LogOptions.PROPERTY_OFFSET, params.getOffset())
628+
.putQueryParam(LogOptions.PROPERTY_SEARCH, params.getSearch())
629+
.putQueryParam(LogOptions.PROPERTY_SORT, params.getSort());
630+
}
631+
588632
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.entity;
22+
23+
import java.util.List;
24+
25+
/**
26+
* @author Mark - mark at arangodb.com
27+
*
28+
* @see <a href=
29+
* "https://docs.arangodb.com/current/HTTP/AdministrationAndMonitoring/index.html#read-global-logs-from-the-server">API
30+
* Documentation</a>
31+
*/
32+
public class LogEntity {
33+
34+
private List<Long> lid;
35+
private List<LogLevel> level;
36+
private List<Long> timestamp;
37+
private List<String> text;
38+
private Long totalAmount;
39+
40+
/**
41+
* @return a list of log entry identifiers. Each log message is uniquely identified by its @LIT{lid} and the
42+
* identifiers are in ascending order
43+
*/
44+
public List<Long> getLid() {
45+
return lid;
46+
}
47+
48+
/**
49+
* @return a list of the log-levels for all log entries
50+
*/
51+
public List<LogLevel> getLevel() {
52+
return level;
53+
}
54+
55+
/**
56+
* @return a list of the timestamps as seconds since 1970-01-01 for all log entries
57+
*/
58+
public List<Long> getTimestamp() {
59+
return timestamp;
60+
}
61+
62+
/**
63+
* @return a list of the texts of all log entries
64+
*/
65+
public List<String> getText() {
66+
return text;
67+
}
68+
69+
/**
70+
* @return the total amount of log entries before pagination
71+
*/
72+
public Long getTotalAmount() {
73+
return totalAmount;
74+
}
75+
76+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.entity;
22+
23+
/**
24+
* @author Mark - mark at arangodb.com
25+
*
26+
*/
27+
public enum LogLevel {
28+
29+
FATAL(0), ERROR(1), WARNING(2), INFO(3), DEBUG(4);
30+
31+
private final int level;
32+
33+
private LogLevel(final int level) {
34+
this.level = level;
35+
}
36+
37+
public int getLevel() {
38+
return level;
39+
}
40+
41+
public static LogLevel fromLevel(final int level) {
42+
for (final LogLevel logLevel : LogLevel.values()) {
43+
if (logLevel.level == level) {
44+
return logLevel;
45+
}
46+
}
47+
return null;
48+
}
49+
50+
}

src/main/java/com/arangodb/internal/ArangoDBConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class ArangoDBConstants {
5353
public static final String PATH_API_QUERY_CURRENT = "/_api/query/current";
5454
public static final String PATH_API_QUERY_SLOW = "/_api/query/slow";
5555
public static final String PATH_API_TRAVERSAL = "/_api/traversal";
56+
public static final String PATH_API_ADMIN_LOG = "/_admin/log";
5657

5758
public static final String ENCRYPTION_PLAIN = "plain";
5859

src/main/java/com/arangodb/internal/velocypack/VPackConfigure.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.arangodb.entity.CollectionStatus;
3030
import com.arangodb.entity.CollectionType;
3131
import com.arangodb.entity.DocumentField;
32+
import com.arangodb.entity.LogLevel;
3233
import com.arangodb.entity.QueryEntity;
3334
import com.arangodb.internal.CollectionCache;
3435
import com.arangodb.internal.velocystream.AuthenticationRequest;
@@ -96,13 +97,15 @@ public static void configure(
9697
builder.registerSerializer(BaseDocument.class, VPackSerializers.BASE_DOCUMENT);
9798
builder.registerSerializer(BaseEdgeDocument.class, VPackSerializers.BASE_EDGE_DOCUMENT);
9899
builder.registerSerializer(TraversalOptions.Order.class, VPackSerializers.TRAVERSAL_ORDER);
100+
builder.registerSerializer(LogLevel.class, VPackSerializers.LOG_LEVEL);
99101

100102
builder.registerDeserializer(Response.class, VPackDeserializers.RESPONSE);
101103
builder.registerDeserializer(CollectionType.class, VPackDeserializers.COLLECTION_TYPE);
102104
builder.registerDeserializer(CollectionStatus.class, VPackDeserializers.COLLECTION_STATUS);
103105
builder.registerDeserializer(BaseDocument.class, VPackDeserializers.BASE_DOCUMENT);
104106
builder.registerDeserializer(BaseEdgeDocument.class, VPackDeserializers.BASE_EDGE_DOCUMENT);
105107
builder.registerDeserializer(QueryEntity.PROPERTY_STARTED, Date.class, VPackDeserializers.DATE_STRING);
108+
builder.registerDeserializer(LogLevel.class, VPackDeserializers.LOG_LEVEL);
106109
}
107110

108111
}

src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.arangodb.entity.BaseEdgeDocument;
3333
import com.arangodb.entity.CollectionStatus;
3434
import com.arangodb.entity.CollectionType;
35+
import com.arangodb.entity.LogLevel;
3536
import com.arangodb.velocypack.VPackDeserializer;
3637
import com.arangodb.velocystream.Response;
3738

@@ -80,4 +81,7 @@ public class VPackDeserializers {
8081
}
8182
return null;
8283
};
84+
85+
public static final VPackDeserializer<LogLevel> LOG_LEVEL = (parent, vpack, context) -> LogLevel
86+
.fromLevel(vpack.getAsInt());
8387
}

src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.arangodb.entity.BaseEdgeDocument;
2929
import com.arangodb.entity.CollectionType;
3030
import com.arangodb.entity.DocumentField;
31+
import com.arangodb.entity.LogLevel;
3132
import com.arangodb.internal.velocystream.AuthenticationRequest;
3233
import com.arangodb.model.TraversalOptions;
3334
import com.arangodb.velocypack.VPackSerializer;
@@ -107,4 +108,7 @@ public class VPackSerializers {
107108
builder.add(attribute, value.name());
108109
}
109110
};
111+
112+
public static final VPackSerializer<LogLevel> LOG_LEVEL = (builder, attribute, value, context) -> builder
113+
.add(attribute, value.getLevel());
110114
}

0 commit comments

Comments
 (0)