mstrucken opened a new issue, #7954:
URL: https://github.com/apache/storm/issues/7954
Example bolt written in Python (`multilang/resources/log_level.py`):
```python
import asyncio
import storm
class LogLevelTestBolt(storm.BasicBolt):
async def initialize(self, conf, context):
storm.logInfo("Python bolt starting...")
storm.logWarn("This is a sample warning")
async def process(self, tup):
storm.logError("Error processing tuple with python...")
async def main():
bolt = LogLevelTestBolt()
await bolt.run()
asyncio.run(main())
```
A minimal bolt that extends the `ShellBolt` used to execute the Python bolt
above:
```java
package com.stockpulse.stockstorm.logging;
import org.apache.storm.task.ShellBolt;
import org.apache.storm.topology.IRichBolt;
import org.apache.storm.topology.OutputFieldsDeclarer;
public class PythonLogLevelBolt extends ShellBolt implements IRichBolt {
public PythonLogLevelBolt() {
super("python", "log_level.py");
}
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
}
@Override
public java.util.Map<String, Object> getComponentConfiguration() {
return null;
}
}
```
Output:
```
16:30:51.806 [main] WARN o.a.s.s.o.a.z.s.ServerCnxnFactory - maxCnxns is
not configured, using default value 0.
16:30:57.247 [Thread-37-python-logging-executor[2, 2]] INFO
o.a.s.t.ShellBolt - Launched subprocess with pid 17336
16:30:57.248 [Thread-37-python-logging-executor[2, 2]] INFO
o.a.s.t.ShellBolt - Start checking heartbeat...
16:30:57.248 [Thread-39] INFO o.a.s.t.ShellBolt - ShellLog pid:17336,
name:python-logging Python bolt starting...
16:30:57.248 [Thread-39] INFO o.a.s.t.ShellBolt - ShellLog pid:17336,
name:python-logging This is a sample warning
16:30:57.251 [Thread-39] INFO o.a.s.t.ShellBolt - ShellLog pid:17336,
name:python-logging Error processing tuple with python...
```
Expected output:
```
16:30:51.806 [main] WARN o.a.s.s.o.a.z.s.ServerCnxnFactory - maxCnxns is
not configured, using default value 0.
16:30:57.247 [Thread-37-python-logging-executor[2, 2]] INFO
o.a.s.t.ShellBolt - Launched subprocess with pid 17336
16:30:57.248 [Thread-37-python-logging-executor[2, 2]] INFO
o.a.s.t.ShellBolt - Start checking heartbeat...
16:30:57.248 [Thread-39] INFO o.a.s.t.ShellBolt - ShellLog pid:17336,
name:python-logging Python bolt starting...
16:30:57.248 [Thread-39] WARN o.a.s.t.ShellBolt - ShellLog pid:17336,
name:python-logging This is a sample warning
16:30:57.251 [Thread-39] ERROR o.a.s.t.ShellBolt - ShellLog pid:17336,
name:python-logging Error processing tuple with python...
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]