Skip to content

Commit

Permalink
Fix Failing Logging capture
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed Jan 20, 2024
1 parent 03fdacc commit 1f53912
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 55 deletions.
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
}
7 changes: 4 additions & 3 deletions core/src/main/scala/io/pdal/Pipeline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ package io.pdal

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

class Pipeline(val json: String, val logLevel: Int) extends Native {
class Pipeline private (val json: String, val logLevel: Int) extends Native {
Pipeline // reference the object so that the nativeLoader will load 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
@native def getPointViews(): PointViewIterator
Expand All @@ -41,11 +43,10 @@ class Pipeline(val json: String, val logLevel: Int) extends Native {
@native def validate(): Boolean
@native def setLogLevel(i: Int): Unit
@native def getLogLevel(): Int
@native def getLog(): String
}

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
}
}
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
3 changes: 0 additions & 3 deletions native/src/include/JavaPipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class PDAL_DLL PipelineExecutor {
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,8 +83,6 @@ class PDAL_DLL PipelineExecutor {
bool m_executed = false;

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

Expand Down
8 changes: 0 additions & 8 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.

7 changes: 0 additions & 7 deletions native/src/io_pdal_Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,6 @@ JNIEXPORT jint JNICALL Java_io_pdal_Pipeline_getLogLevel
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 1f53912

Please sign in to comment.