# Logstash plugin use @logger in new class

**URL:** <https://discuss.elastic.co/t/logstash-plugin-use-logger-in-new-class/317034>\
**Category:** Logstash\
**Created:** [October 19, 2022, 5:10pm UTC](https://discuss.elastic.co/t/logstash-plugin-use-logger-in-new-class/317034 "2022-10-19T17:10:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tylersiemers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersiemers/32/108982_2.png) [@tylersiemers](https://discuss.elastic.co/u/tylersiemers)\
**Post date:** [October 19, 2022, 5:10pm UTC](https://discuss.elastic.co/t/logstash-plugin-use-logger-in-new-class/317034/1 "2022-10-19T17:10:30Z")

</div>

New to logstash plugins here. How do you pass the @logger reference into another class within a plugin? The example below but trying to call another class outside and logging cause a failure.

```auto
class SecondClass
	@logger.warn("This line causes an error")
end

class LogStash::Filters::ExamplePlugin < LogStash::Filters::Base
...
snip
...

def callSecondClass
  @logger.info("logger works within this class")
  SecondClass
end  

```

---

<div class="post-metadata">

**Author:** ![tylersiemers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersiemers/32/108982_2.png) [@tylersiemers](https://discuss.elastic.co/u/tylersiemers)\
**Post date:** [October 19, 2022, 8:42pm UTC](https://discuss.elastic.co/t/logstash-plugin-use-logger-in-new-class/317034/2 "2022-10-19T20:42:34Z")

</div>

Got it. Had to pull in the logger module

```auto
require "logstash/util/loggable"

class SecondClass
        include LogStash::Util::Loggable
	logger.warn("This line causes an error")
end

class LogStash::Filters::ExamplePlugin < LogStash::Filters::Base
...
snip
...

def callSecondClass
  @logger.info("logger works within this class")
  SecondClass
end 

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 16, 2022, 8:43pm UTC](https://discuss.elastic.co/t/logstash-plugin-use-logger-in-new-class/317034/3 "2022-11-16T20:43:05Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
