|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to you under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.logging.log4j.iceberg; |
| 18 | + |
| 19 | +import java.util.concurrent.TimeUnit; |
| 20 | +import org.apache.logging.log4j.Level; |
| 21 | +import org.apache.logging.log4j.core.LogEvent; |
| 22 | +import org.apache.logging.log4j.core.impl.Log4jLogEvent; |
| 23 | +import org.apache.logging.log4j.message.SimpleMessage; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +class IcebergInspectTest { |
| 27 | + |
| 28 | + @Test |
| 29 | + void createInspectableTable() { |
| 30 | + final String warehouse = "/tmp/iceberg-inspect"; |
| 31 | + final IcebergManager manager = new IcebergManager( |
| 32 | + "inspect", "inspect_catalog", "hadoop", null, warehouse, "logs", "app_logs", 500, 3600); |
| 33 | + manager.startup(); |
| 34 | + |
| 35 | + final Level[] levels = {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR}; |
| 36 | + for (int i = 0; i < 1000; i++) { |
| 37 | + final LogEvent event = Log4jLogEvent.newBuilder() |
| 38 | + .setLoggerName("com.example.App") |
| 39 | + .setLevel(levels[i % levels.length]) |
| 40 | + .setMessage(new SimpleMessage("log message " + i)) |
| 41 | + .setThreadName("main") |
| 42 | + .setTimeMillis(1700000000000L + i * 1000L) |
| 43 | + .build(); |
| 44 | + manager.write(event.toImmutable()); |
| 45 | + } |
| 46 | + |
| 47 | + manager.stop(10, TimeUnit.SECONDS); |
| 48 | + System.out.println("Iceberg table written to: " + warehouse + "/logs/app_logs"); |
| 49 | + System.out.println("Inspect with: find " + warehouse + " -type f"); |
| 50 | + } |
| 51 | +} |
0 commit comments