Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit d43f500

Browse files
Merge pull request #49 from omgapuppy/master
Remove LogTooLongException
2 parents 5b74cff + e77b906 commit d43f500

5 files changed

Lines changed: 51 additions & 20 deletions

File tree

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ jdk:
44
- openjdk7
55
- oraclejdk7
66
- oraclejdk8
7+
before_install:
8+
# override default MAVEN_OPTS
9+
- echo "MAVEN_OPTS='-Xms1g -Xmx2g -XX:MaxPermSize=512m'" > ~/.mavenrc
10+
# Fix OpenJDK buffer overflow
11+
- cat /etc/hosts # optionally check the content *before*
12+
- sudo hostname "$(hostname | cut -c1-63)"
13+
- sed -e "s/^\\(127\\.0\\.0\\.1.*\\)/\\1 $(hostname | cut -c1-63)/" /etc/hosts | sudo tee /etc/hosts
14+
- cat /etc/hosts # optionally check the content *after*

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@
7272
</execution>
7373
</executions>
7474
</plugin>
75+
<plugin>
76+
<groupId>org.apache.maven.plugins</groupId>
77+
<artifactId>maven-surefire-plugin</artifactId>
78+
<version>2.19.1</version>
79+
<configuration>
80+
<!-- Travis build workaround -->
81+
<forkCount>1</forkCount>
82+
<argLine>${surefire.jvm.params}</argLine>
83+
</configuration>
84+
</plugin>
7585
</plugins>
7686
</build>
7787
<profiles>

src/main/java/com/logentries/net/AsyncLogger.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,53 +270,53 @@ public int getDataHubPort() {
270270
*
271271
* @param logHostName
272272
*/
273-
public void setLogHostName(boolean logHostName) {
274-
this.logHostName = logHostName;
273+
public void setLogHostName(boolean logHostName) {
274+
this.logHostName = logHostName;
275275
}
276276

277277
/**
278278
* Gets value of the switch that determines whether to send HostName alongside with the log message
279279
*
280280
* @return logHostName switch value
281281
*/
282-
public boolean getLogHostName() {
283-
return this.logHostName;
282+
public boolean getLogHostName() {
283+
return this.logHostName;
284284
}
285285

286286
/**
287287
* Sets the HostName from configuration
288288
*
289289
* @param hostName
290290
*/
291-
public void setHostName(String hostName) {
292-
this.hostName = hostName;
291+
public void setHostName(String hostName) {
292+
this.hostName = hostName;
293293
}
294294

295295
/**
296296
* Gets HostName parameter
297297
*
298298
* @return Host name field value
299299
*/
300-
public String getHostName() {
301-
return this.hostName;
300+
public String getHostName() {
301+
return this.hostName;
302302
}
303303

304304
/**
305305
* Sets LogID parameter from config
306306
*
307307
* @param logID
308308
*/
309-
public void setLogID(String logID) {
310-
this.logID = logID;
309+
public void setLogID(String logID) {
310+
this.logID = logID;
311311
}
312312

313313
/**
314314
* Gets LogID parameter
315315
*
316316
* @return logID field value
317317
*/
318-
public String getLogID() {
319-
return this.logID;
318+
public String getLogID() {
319+
return this.logID;
320320
}
321321

322322
/**
@@ -419,7 +419,9 @@ public void addLineToQueue(String line) {
419419
}
420420

421421
private void addLineToQueue (String line, int limit) {
422-
if (limit == 0) { throw new LogTooLongException(); }
422+
if (limit == 0) {
423+
dbg("Message longer than " + RECURSION_LIMIT);
424+
return; }
423425

424426
//// Check credentials only if logs are sent to LE directly.
425427
// Check that we have all parameters set and socket appender running.

src/main/java/com/logentries/net/LogTooLongException.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/test/java/com/logentries/net/AsyncLoggerTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.logentries.net;
22

33
import org.junit.Test;
4+
5+
import java.util.Random;
6+
47
import static org.junit.Assert.*;
58

69
public class AsyncLoggerTest {
@@ -17,6 +20,21 @@ public void testGetAndSetToken()
1720
}
1821

1922
@Test
23+
public void testOversizeMessage()
24+
{
25+
AsyncLogger async = new AsyncLogger();
26+
char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
27+
StringBuilder sb = new StringBuilder();
28+
Random random = new Random();
29+
for (int i = 0; i < 2100000; i++) {
30+
char c = chars[random.nextInt(chars.length)];
31+
sb.append(c);
32+
}
33+
String output = sb.toString();
34+
async.addLineToQueue(output);
35+
}
36+
37+
@Test
2038
public void testGetAndSetHttpPut()
2139
{
2240
AsyncLogger async = new AsyncLogger();

0 commit comments

Comments
 (0)