Skip to content

Commit 0827c56

Browse files
authored
Fix Failing Logging capture (#82)
* Fix Failing Logging capture * Remove unused methods * Add issue-79 example * Rename private getLogLevelInt method, add tests
1 parent 03fdacc commit 0827c56

File tree

10 files changed

+61
-79
lines changed

10 files changed

+61
-79
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ val json =
8383
|}
8484
""".stripMargin
8585

86-
val pipeline = Pipeline(json)
86+
val pipeline = Pipeline(json, LogLevel.Debug5) // initialize and make it really noisy
8787
pipeline.validate() // check if our JSON and options were good
88-
pipeline.setLogLevel(LogLevel.Debug5) // make it really noisy
8988
pipeline.execute() // execute the pipeline
9089
val metadata = pipeline.getMetadata() // retrieve metadata
9190
val pvs = pipeline.getPointViews() // iterator over PointViews

core/src/main/scala/io/pdal/LogLevel.scala

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@
2424

2525
package io.pdal
2626

27-
object LogLevel {
28-
val Error = 0
29-
val Warning = 1
30-
val Info = 2
31-
val Debug = 3
32-
val Debug1 = 4
33-
val Debug2 = 5
34-
val Debug3 = 6
35-
val Debug4 = 7
36-
val Debug5 = 8
37-
val None = 9
27+
object LogLevel extends Enumeration {
28+
val Error, Warning, Info, Debug, Debug1, Debug2, Debug3, Debug4, Debug5 = Value
3829
}

core/src/main/scala/io/pdal/Pipeline.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ package io.pdal
2626

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

29-
class Pipeline(val json: String, val logLevel: Int) extends Native {
30-
Pipeline // reference the object so that the nativeLoader will load the JNI native libraries
29+
class Pipeline private (val json: String, val logLevel: Int) extends Native {
30+
Pipeline // reference companion object so nativeLoader loads the JNI native libraries
31+
32+
def this(json: String, logLevel: LogLevel.Value = LogLevel.Error) = this(json, logLevel.id)
3133

3234
@native def initialize(): Unit
3335
@native def execute(): Unit
@@ -39,13 +41,13 @@ class Pipeline(val json: String, val logLevel: Int) extends Native {
3941
@native def getSchema(): String
4042
@native def getQuickInfo(): String
4143
@native def validate(): Boolean
42-
@native def setLogLevel(i: Int): Unit
43-
@native def getLogLevel(): Int
44-
@native def getLog(): String
44+
@native private def getLogLevelInt(): Int
45+
46+
def getLogLevel(): LogLevel.Value = LogLevel.apply(getLogLevelInt())
4547
}
4648

4749
object Pipeline extends NativeLoader("pdaljni.2.6") {
48-
def apply(json: String, logLevel: Int = LogLevel.Error): Pipeline = {
50+
def apply(json: String, logLevel: LogLevel.Value = LogLevel.Error): Pipeline = {
4951
val p = new Pipeline(json, logLevel); p.initialize(); p
5052
}
5153
}

core/src/test/scala/io/pdal/PipelineSpec.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class PipelineSpec extends TestEnvironmentSpec {
4646
pipeline.execute()
4747
}
4848

49+
it("should get pipeline LogLevel") {
50+
pipeline.getLogLevel() shouldBe LogLevel.Error
51+
pipeline.getLogLevel() shouldBe LogLevel(pipeline.logLevel)
52+
}
53+
4954
it("should create pointViews iterator") {
5055
val pvi = pipeline.getPointViews()
5156
pvi.asScala.length should be(1)
332 KB
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import io.pdal.Pipeline
2+
3+
object MainLogging {
4+
val json =
5+
"""
6+
|{
7+
| "pipeline": [
8+
| {
9+
| "filename": "data/issue-79.las",
10+
| "type": "readers.las",
11+
| "spatialreference": "EPSG:2056"
12+
| },
13+
| {
14+
| "distance": 250,
15+
| "type": "filters.crop",
16+
| "point": "POINT(2717706.2 1103466.2 677.54)"
17+
| },
18+
| {
19+
| "count": 100000,
20+
| "decay": 0.9,
21+
| "type": "filters.relaxationdartthrowing",
22+
| "radius": 1
23+
| }
24+
| ]
25+
|}
26+
""".stripMargin
27+
28+
def main(args: Array[String]) = {
29+
val pipeline = Pipeline(json, LogLevel.Debug)
30+
pipeline.execute()
31+
println(s"pipeline.getMetadata(): ${pipeline.getMetadata()}")
32+
pipeline.close()
33+
}
34+
}

native/src/JavaPipeline.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
#include <pdal/XMLSchema.hpp>
3737
#endif
3838

39-
using pdal::LogLevel;
40-
using pdal::LogPtr;
4139
using pdal::MetadataNode;
4240
using pdal::PointId;
4341
using pdal::PointViewSet;
@@ -64,14 +62,9 @@ PipelineExecutor::PipelineExecutor(string const& json, int level)
6462
{
6563
setLogLevel(level);
6664

67-
LogPtr log(pdal::Log::makeLog("javapipeline", &m_logStream));
68-
log->setLevel(m_logLevel);
69-
m_manager.setLog(log);
70-
7165
stringstream strm;
7266
strm << json;
7367
m_manager.readPipeline(strm);
74-
7568
}
7669

7770
bool PipelineExecutor::validate()
@@ -123,7 +116,6 @@ string PipelineExecutor::getPipeline() const
123116
return strm.str();
124117
}
125118

126-
127119
string PipelineExecutor::getMetadata() const
128120
{
129121
if (!m_executed)
@@ -135,7 +127,6 @@ string PipelineExecutor::getMetadata() const
135127
return strm.str();
136128
}
137129

138-
139130
string PipelineExecutor::getSchema() const
140131
{
141132
if (!m_executed)
@@ -188,7 +179,6 @@ MetadataNode computePreview(Stage* stage)
188179
return summary;
189180
}
190181

191-
192182
string PipelineExecutor::getQuickInfo() const
193183
{
194184

@@ -217,25 +207,18 @@ string PipelineExecutor::getQuickInfo() const
217207
return strm.str();
218208
}
219209

220-
void PipelineExecutor::setLogStream(std::ostream& strm)
221-
{
222-
223-
LogPtr log(pdal::Log::makeLog("javapipeline", &strm));
224-
log->setLevel(m_logLevel);
225-
m_manager.setLog(log);
226-
}
227-
228-
229210
void PipelineExecutor::setLogLevel(int level)
230211
{
231-
if (level < static_cast<int>(LogLevel::Error) || level > static_cast<int>(LogLevel::None))
232-
throw java_error("LogLevel should be between 0 and 9");
212+
if (level < 0 || level > 8)
213+
throw java_error("LogLevel should be between 0 and 8!");
233214

234215
m_logLevel = static_cast<pdal::LogLevel>(level);
235-
setLogStream(m_logStream);
216+
217+
pdal::LogPtr log(pdal::Log::makeLog("javapipeline", "stdlog"));
218+
log->setLevel(m_logLevel);
219+
m_manager.setLog(log);
236220
}
237221

238-
239222
int PipelineExecutor::getLogLevel() const
240223
{
241224
return static_cast<int>(m_logLevel);

native/src/include/JavaPipeline.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ class PDAL_DLL PipelineExecutor {
7373
std::string getSchema() const;
7474
std::string getSrsWKT2() const;
7575
pdal::PipelineManager const& getManager() const { return m_manager; }
76-
void setLogLevel(int level);
7776
int getLogLevel() const;
78-
std::string getLog() const { return m_logStream.str(); }
7977

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

8684
private:
87-
void setLogStream(std::ostream& strm);
88-
std::stringstream m_logStream;
8985
pdal::LogLevel m_logLevel;
86+
87+
void setLogLevel(int level);
9088
};
9189

9290
class CountPointTable : public pdal::FixedPointTable

native/src/include/io_pdal_Pipeline.h

Lines changed: 2 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

native/src/io_pdal_Pipeline.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,27 +191,13 @@ JNIEXPORT jboolean JNICALL Java_io_pdal_Pipeline_validate
191191
return result;
192192
}
193193

194-
JNIEXPORT void JNICALL Java_io_pdal_Pipeline_setLogLevel
195-
(JNIEnv *env, jobject obj, jint i)
196-
{
197-
PipelineExecutor *p = getHandle<PipelineExecutor>(env, obj);
198-
p->setLogLevel(i);
199-
}
200-
201-
JNIEXPORT jint JNICALL Java_io_pdal_Pipeline_getLogLevel
194+
JNIEXPORT jint JNICALL Java_io_pdal_Pipeline_getLogLevelInt
202195
(JNIEnv *env, jobject obj)
203196
{
204197
PipelineExecutor *p = getHandle<PipelineExecutor>(env, obj);
205198
return p->getLogLevel();
206199
}
207200

208-
JNIEXPORT jstring JNICALL Java_io_pdal_Pipeline_getLog
209-
(JNIEnv *env, jobject obj)
210-
{
211-
PipelineExecutor *p = getHandle<PipelineExecutor>(env, obj);
212-
return env->NewStringUTF(p->getLog().c_str());
213-
}
214-
215201
JNIEXPORT jobject JNICALL Java_io_pdal_Pipeline_getPointViews
216202
(JNIEnv *env, jobject obj)
217203
{

0 commit comments

Comments
 (0)