Created
February 17, 2017 01:29
-
-
Save evren/637d944277696cb70b2f6830e1af6896 to your computer and use it in GitHub Desktop.
Example showing how to read Stardog's audit log
This file contains hidden or 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
/* | |
* Copyright (c) 2017 Stardog Union. <http://www.stardog.com> | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package com.stardog.example; | |
import java.io.BufferedInputStream; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import com.complexible.common.base.CloseableIterator; | |
import com.complexible.stardog.KernelEvent; | |
import com.complexible.stardog.logging.LogReader; | |
import com.complexible.stardog.logging.protobuf.ProtobufTextLogReader; | |
/** | |
* @author Evren Sirin | |
*/ | |
public class PrintProtobufLogs { | |
public static void main(String[] args) throws Exception { | |
File file = new File(args[0]); | |
String format = args[1]; | |
LogReader reader = createLogReader(format); | |
try (CloseableIterator<KernelEvent> events = reader.read(new BufferedInputStream(new FileInputStream(file)))) { | |
while (events.hasNext()) { | |
System.out.println(events.next()); | |
} | |
} | |
} | |
private static LogReader createLogReader(String format) { | |
switch (format.toLowerCase()) { | |
case "text": return new ProtobufTextLogReader(); | |
case "binary": return new ProtobufTextLogReader(); | |
default: throw new UnsupportedOperationException("Unknown format: " + format); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment