forked from osiegmar/logback-gelf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GZIP Compression with GelfUdpAppender (osiegmar#66)
- Loading branch information
1 parent
9c90fe9
commit 881fc69
Showing
7 changed files
with
268 additions
and
25 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/de/siegmar/logbackgelf/CompressionMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Logback GELF - zero dependencies Logback GELF appender library. | ||
* Copyright (C) 2019 Oliver Siegmar | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
package de.siegmar.logbackgelf; | ||
|
||
import de.siegmar.logbackgelf.compressor.Compressor; | ||
import de.siegmar.logbackgelf.compressor.GZIPCompressor; | ||
import de.siegmar.logbackgelf.compressor.ZLIBCompressor; | ||
|
||
public enum CompressionMethod { | ||
ZLIB(new ZLIBCompressor()), | ||
GZIP(new GZIPCompressor()); | ||
|
||
private Compressor compressor; | ||
|
||
CompressionMethod(final Compressor compressor) { | ||
this.compressor = compressor; | ||
} | ||
|
||
public Compressor getCompressor() { | ||
return this.compressor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/de/siegmar/logbackgelf/compressor/Compressor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Logback GELF - zero dependencies Logback GELF appender library. | ||
* Copyright (C) 2016 Oliver Siegmar | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
package de.siegmar.logbackgelf.compressor; | ||
|
||
|
||
public interface Compressor { | ||
|
||
byte[] compress(byte[] binMessage); | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/de/siegmar/logbackgelf/compressor/GZIPCompressor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Logback GELF - zero dependencies Logback GELF appender library. | ||
* Copyright (C) 2019 Oliver Siegmar | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
package de.siegmar.logbackgelf.compressor; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.zip.GZIPOutputStream; | ||
|
||
public class GZIPCompressor implements Compressor { | ||
|
||
@Override | ||
public byte[] compress(final byte[] binMessage) { | ||
final ByteArrayOutputStream bos = new ByteArrayOutputStream(binMessage.length); | ||
try (OutputStream gzipOut = new GZIPOutputStream(bos)) { | ||
gzipOut.write(binMessage); | ||
} catch (IOException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
return bos.toByteArray(); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/de/siegmar/logbackgelf/compressor/NoneCompressor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Logback GELF - zero dependencies Logback GELF appender library. | ||
* Copyright (C) 2019 Oliver Siegmar | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
package de.siegmar.logbackgelf.compressor; | ||
|
||
public class NoneCompressor implements Compressor { | ||
|
||
@Override | ||
public byte[] compress(final byte[] binMessage) { | ||
return binMessage; | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/de/siegmar/logbackgelf/compressor/ZLIBCompressor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Logback GELF - zero dependencies Logback GELF appender library. | ||
* Copyright (C) 2019 Oliver Siegmar | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
package de.siegmar.logbackgelf.compressor; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.zip.DeflaterOutputStream; | ||
|
||
public class ZLIBCompressor implements Compressor { | ||
|
||
@Override | ||
public byte[] compress(final byte[] binMessage) { | ||
final ByteArrayOutputStream bos = new ByteArrayOutputStream(binMessage.length); | ||
try (OutputStream deflaterOut = new DeflaterOutputStream(bos)) { | ||
deflaterOut.write(binMessage); | ||
} catch (IOException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
return bos.toByteArray(); | ||
} | ||
|
||
} |
Oops, something went wrong.