# How to parse a particular log file

**URL:** <https://discuss.elastic.co/t/how-to-parse-a-particular-log-file/147138>\
**Category:** Logstash\
**Created:** [September 4, 2018, 5:20am UTC](https://discuss.elastic.co/t/how-to-parse-a-particular-log-file/147138 "2018-09-04T05:20:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon69830709](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@anon69830709](https://discuss.elastic.co/u/anon69830709)\
**Post date:** [September 4, 2018, 5:20am UTC](https://discuss.elastic.co/t/how-to-parse-a-particular-log-file/147138/1 "2018-09-04T05:20:12Z")

</div>

So i have 2 log file say log1 and log2.I want to parse them using separate filter.

so can i use if statement on file source like

if [source] == /_/_/log1 {  
do something  
}  
else {  
do something  
}

---

<div class="post-metadata">

**Author:** ![Krunal\_kalaria](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krunal_kalaria/32/23862_2.png) [@Krunal\_kalaria](https://discuss.elastic.co/u/Krunal_kalaria)\
**Post date:** [September 4, 2018, 5:46am UTC](https://discuss.elastic.co/t/how-to-parse-a-particular-log-file/147138/2 "2018-09-04T05:46:13Z")

</div>

Hi @anon69830709,

## You can use it that is the right way and you can use like if [source] == "log1" {

## } else if [source] == "log2" {

}  
else { }

Thanks & Regards,  
Krunal.

---

<div class="post-metadata">

**Author:** ![anon69830709](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@anon69830709](https://discuss.elastic.co/u/anon69830709)\
**Post date:** [September 4, 2018, 6:00am UTC](https://discuss.elastic.co/t/how-to-parse-a-particular-log-file/147138/3 "2018-09-04T06:00:18Z")

</div>

source is for file name or path?  
When i mention source, do i need to specify file location?

---

<div class="post-metadata">

**Author:** ![Krunal\_kalaria](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krunal_kalaria/32/23862_2.png) [@Krunal\_kalaria](https://discuss.elastic.co/u/Krunal_kalaria)\
**Post date:** [September 11, 2018, 6:36am UTC](https://discuss.elastic.co/t/how-to-parse-a-particular-log-file/147138/4 "2018-09-11T06:36:47Z")

</div>

Hi @anon69830709,

Sorry for late response,

Source is your field name like:

if [message] == "login failed"  
{  
kv{ }  
grok{ } #what ever filter you want to apply you can use here in if else loop.  
}  
else if [192.168.1.1] == "login failed"  
{  
#you can use same here  
}

Thanks & Regards,  
Krunal.

---

<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:** [October 9, 2018, 6:37am UTC](https://discuss.elastic.co/t/how-to-parse-a-particular-log-file/147138/5 "2018-10-09T06:37:00Z")

</div>

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