Skip to content

Commit

Permalink
Fix Failing Logging capture (#82)
Browse files Browse the repository at this point in the history
* Fix Failing Logging capture

* Remove unused methods

* Add issue-79 example

* Rename private getLogLevelInt method, add tests
  • Loading branch information
pomadchin authored Jan 20, 2024
1 parent 03fdacc commit 0827c56
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 79 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ val json =
|}
""".stripMargin

val pipeline = Pipeline(json)
val pipeline = Pipeline(json, LogLevel.Debug5) // initialize and make it really noisy
pipeline.validate() // check if our JSON and options were good
pipeline.setLogLevel(LogLevel.Debug5) // make it really noisy
pipeline.execute() // execute the pipeline
val metadata = pipeline.getMetadata() // retrieve metadata
val pvs = pipeline.getPointViews() // iterator over PointViews
Expand Down
13 changes: 2 additions & 11 deletions core/src/main/scala/io/pdal/LogLevel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@

package io.pdal

object LogLevel {
val Error = 0
val Warning = 1
val Info = 2
val Debug = 3
val Debug1 = 4
val Debug2 = 5
val Debug3 = 6
val Debug4 = 7
val Debug5 = 8
val None = 9
object LogLevel extends Enumeration {
val Error, Warning, Info, Debug, Debug1, Debug2, Debug3, Debug4, Debug5 = Value
}
14 changes: 8 additions & 6 deletions core/src/main/scala/io/pdal/Pipeline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ package io.pdal

import com.github.sbt.jni.syntax.NativeLoader

class Pipeline(val json: String, val logLevel: Int) extends Native {
Pipeline // reference the object so that the nativeLoader will load the JNI native libraries
class Pipeline private (val json: String, val logLevel: Int) extends Native {
Pipeline // reference companion object so nativeLoader loads the JNI native libraries

def this(json: String, logLevel: LogLevel.Value = LogLevel.Error) = this(json, logLevel.id)

@native def initialize(): Unit
@native def execute(): Unit
Expand All @@ -39,13 +41,13 @@ class Pipeline(val json: String, val logLevel: Int) extends Native {
@native def getSchema(): String
@native def getQuickInfo(): String
@native def validate(): Boolean
@native def setLogLevel(i: Int): Unit
@native def getLogLevel(): Int
@native def getLog(): String
@native private def getLogLevelInt(): Int

def getLogLevel(): LogLevel.Value = LogLevel.apply(getLogLevelInt())
}

object Pipeline extends NativeLoader("pdaljni.2.6") {
def apply(json: String, logLevel: Int = LogLevel.Error): Pipeline = {
def apply(json: String, logLevel: LogLevel.Value = LogLevel.Error): Pipeline = {
val p = new Pipeline(json, logLevel); p.initialize(); p
}
}
5 changes: 5 additions & 0 deletions core/src/test/scala/io/pdal/PipelineSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class PipelineSpec extends TestEnvironmentSpec {
pipeline.execute()
}

it("should get pipeline LogLevel") {
pipeline.getLogLevel() shouldBe LogLevel.Error
pipeline.getLogLevel() shouldBe LogLevel(pipeline.logLevel)
}

it("should create pointViews iterator") {
val pvi = pipeline.getPointViews()
pvi.asScala.length should be(1)
Expand Down
Binary file added examples/pdal-jni/data/issue-79.las
Binary file not shown.
34 changes: 34 additions & 0 deletions examples/pdal-jni/src/main/scala/com/azavea/MainLogging.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import io.pdal.Pipeline

object MainLogging {
val json =
"""
|{
| "pipeline": [
| {
| "filename": "data/issue-79.las",
| "type": "readers.las",
| "spatialreference": "EPSG:2056"
| },
| {
| "distance": 250,
| "type": "filters.crop",
| "point": "POINT(2717706.2 1103466.2 677.54)"
| },
| {
| "count": 100000,
| "decay": 0.9,
| "type": "filters.relaxationdartthrowing",
| "radius": 1
| }
| ]
|}
""".stripMargin

def main(args: Array[String]) = {
val pipeline = Pipeline(json, LogLevel.Debug)
pipeline.execute()
println(s"pipeline.getMetadata(): ${pipeline.getMetadata()}")
pipeline.close()
}
}
29 changes: 6 additions & 23 deletions native/src/JavaPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include <pdal/XMLSchema.hpp>
#endif

using pdal::LogLevel;
using pdal::LogPtr;
using pdal::MetadataNode;
using pdal::PointId;
using pdal::PointViewSet;
Expand All @@ -64,14 +62,9 @@ PipelineExecutor::PipelineExecutor(string const& json, int level)
{
setLogLevel(level);

LogPtr log(pdal::Log::makeLog("javapipeline", &m_logStream));
log->setLevel(m_logLevel);
m_manager.setLog(log);

stringstream strm;
strm << json;
m_manager.readPipeline(strm);

}

bool PipelineExecutor::validate()
Expand Down Expand Up @@ -123,7 +116,6 @@ string PipelineExecutor::getPipeline() const
return strm.str();
}


string PipelineExecutor::getMetadata() const
{
if (!m_executed)
Expand All @@ -135,7 +127,6 @@ string PipelineExecutor::getMetadata() const
return strm.str();
}


string PipelineExecutor::getSchema() const
{
if (!m_executed)
Expand Down Expand Up @@ -188,7 +179,6 @@ MetadataNode computePreview(Stage* stage)
return summary;
}


string PipelineExecutor::getQuickInfo() const
{

Expand Down Expand Up @@ -217,25 +207,18 @@ string PipelineExecutor::getQuickInfo() const
return strm.str();
}

void PipelineExecutor::setLogStream(std::ostream& strm)
{

LogPtr log(pdal::Log::makeLog("javapipeline", &strm));
log->setLevel(m_logLevel);
m_manager.setLog(log);
}


void PipelineExecutor::setLogLevel(int level)
{
if (level < static_cast<int>(LogLevel::Error) || level > static_cast<int>(LogLevel::None))
throw java_error("LogLevel should be between 0 and 9");
if (level < 0 || level > 8)
throw java_error("LogLevel should be between 0 and 8!");

m_logLevel = static_cast<pdal::LogLevel>(level);
setLogStream(m_logStream);

pdal::LogPtr log(pdal::Log::makeLog("javapipeline", "stdlog"));
log->setLevel(m_logLevel);
m_manager.setLog(log);
}


int PipelineExecutor::getLogLevel() const
{
return static_cast<int>(m_logLevel);
Expand Down
6 changes: 2 additions & 4 deletions native/src/include/JavaPipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ class PDAL_DLL PipelineExecutor {
std::string getSchema() const;
std::string getSrsWKT2() const;
pdal::PipelineManager const& getManager() const { return m_manager; }
void setLogLevel(int level);
int getLogLevel() const;
std::string getLog() const { return m_logStream.str(); }

protected:
virtual pdal::ConstPointTableRef pointTable() const { return m_manager.pointTable(); }
Expand All @@ -84,9 +82,9 @@ class PDAL_DLL PipelineExecutor {
bool m_executed = false;

private:
void setLogStream(std::ostream& strm);
std::stringstream m_logStream;
pdal::LogLevel m_logLevel;

void setLogLevel(int level);
};

class CountPointTable : public pdal::FixedPointTable
Expand Down
20 changes: 2 additions & 18 deletions native/src/include/io_pdal_Pipeline.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 1 addition & 15 deletions native/src/io_pdal_Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,13 @@ JNIEXPORT jboolean JNICALL Java_io_pdal_Pipeline_validate
return result;
}

JNIEXPORT void JNICALL Java_io_pdal_Pipeline_setLogLevel
(JNIEnv *env, jobject obj, jint i)
{
PipelineExecutor *p = getHandle<PipelineExecutor>(env, obj);
p->setLogLevel(i);
}

JNIEXPORT jint JNICALL Java_io_pdal_Pipeline_getLogLevel
JNIEXPORT jint JNICALL Java_io_pdal_Pipeline_getLogLevelInt
(JNIEnv *env, jobject obj)
{
PipelineExecutor *p = getHandle<PipelineExecutor>(env, obj);
return p->getLogLevel();
}

JNIEXPORT jstring JNICALL Java_io_pdal_Pipeline_getLog
(JNIEnv *env, jobject obj)
{
PipelineExecutor *p = getHandle<PipelineExecutor>(env, obj);
return env->NewStringUTF(p->getLog().c_str());
}

JNIEXPORT jobject JNICALL Java_io_pdal_Pipeline_getPointViews
(JNIEnv *env, jobject obj)
{
Expand Down

0 comments on commit 0827c56

Please sign in to comment.