# How to send logs to logstash using log4js?

**URL:** <https://discuss.elastic.co/t/how-to-send-logs-to-logstash-using-log4js/272783>\
**Category:** Logstash\
**Created:** [May 12, 2021, 8:32am UTC](https://discuss.elastic.co/t/how-to-send-logs-to-logstash-using-log4js/272783 "2021-05-12T08:32:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![K\_N](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/k_n/32/88644_2.png) [@K\_N](https://discuss.elastic.co/u/K_N)\
**Post date:** [May 12, 2021, 8:32am UTC](https://discuss.elastic.co/t/how-to-send-logs-to-logstash-using-log4js/272783/1 "2021-05-12T08:32:37Z")

</div>

I want to send logs from my local node.js application and I used this [https://github.com/log4js-node/logstashHTTP](https://github.com/log4js-node/logstashHTTP).

But the examples that the documentation mention send logs directly to elasticsearch (I'm able to see the logs using kibana locally) and not to logstash( which I've configured as below ) which is what i want.

```auto
    input {
    	beats {
    		port => 5044
    	}

    	tcp {
    		port => 5000
    		add_field => { "name" => "usage"}
    	}
    	tcp {
    		port => 6000
    		add_field => { "name" => "logs"}
    		codec => json
    	}
    }

    output {
    if [name] == "usage"
    {
    		elasticsearch {
    			hosts => ["elasticsearch:9200"]
    			index => "usage-%{+YYYY-MM-dd}"
    		}
    	}
    	if [name] == "logs"
    {
    		elasticsearch {
    			hosts => ["elasticsearch:9200"]
    			index => "logs-%{+YYYY-MM-dd}"
    		}
    	}
    }

```

How to confiure the log4js in the node application to send logs to logstash(on ports 5000 or 6000) which in turn sends it to elasticsearch after some filters and transformations that I will add later. Any leads appreciated. Thanks!

Edit: I think there is some configuration error with me using the http appender. Is this why the problem comes? I've set tcp logstash receiver but i'm sending using http one? Even if it is i don't know how to configure log4js for tcp logstash receiver On the log4js github repo tcp is not mentioned [HERE](https://github.com/log4js-node/log4js-node) .Any leads with this are also great!

---

<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:** [June 9, 2021, 8:33am UTC](https://discuss.elastic.co/t/how-to-send-logs-to-logstash-using-log4js/272783/2 "2021-06-09T08:33:22Z")

</div>

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