Question: I have a module with a number of exported classes which all extend one base class. Each of these classes have a method called getOutput(). These classes match the structure of an API so I cant change it. The API returns a list and in that list can be any one of these classes (expect for the base class). I use the function to get a unified output no matter which type of object it is. The problem is, Typescript wont let you use the class function unless you assign the object to the class first. So in the base class I wrote a switch case to go through all the types and assign the object to a class. See here <https://stackblitz.com/edit/angular-nvxmqe-9kxr2k>

My problem is that using this approach means that the base class will have to know about each sub class. I would prefer that the subclass itself could assign its class based on the parameters in the class (the type parameter specifically). Or at the very least have another class do a dynamic lookup for the class based on the type. In Java I would use reflection to get a list of classes and assign them that way. I was wondering if there is something similar in Typescript. Or if there was a better way of doing this.

Again, the api is set, I cannot change it.

Answer: 
Are the log files generated by you? Or can you change the log structure? Then you can add a counter as a prefix and filter it out with logstash.

For example for

```
12345 2018-02-25 22:37:55 [mylibrary] INFO: this is an example log line

```

your filter must look like this:

```
filter {
   grok {
     match => {"message" => "%{INT:count} %{GREEDYDATA:message}"
     overwrite => ["message"]
   }
}

```

New field "count" will be created. You can then possibly use it for your purposes.
First let me give what is probably the main reason why Filebeat doesn't already have a line number field. When Filebeat resumes reading a file (like after a restart) it does an `fseek` to resume from the last recorded offset. If it had to report the line numbers it would either need to store this state in its registry or re-read the file and count newlines up to the offset.

If you want to offer a service that allows you to paginate through the logs that are backed by Elasticsearch you can use the [scroll](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html) API with a query for the file. You must [sort](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html) the results by `@timestamp` and then by `offset`. Your service would use a scroll query to get the first page of results.

```
POST /filebeat-*/_search?scroll=1m
{
  "size": 10,
  "query": {
    "match": {
      "source": "/var/log/messages"
    }
  },
  "sort": [
    {
      "@timestamp": {
        "order": "asc"
      }
    },
    {
      "offset": "asc"
    }
  ]
}

```

Then to get all future pages you use the `scroll_id` returned from the first query.

```
POST  /_search/scroll
{
    "scroll" : "1m",
    "scroll_id" : "DnF1ZXJ5VGhlbkZldGNoBwAAAAAAPXDOFk12OEYw="
}

```

This will give you all log data for a given file name even tracking it across rotations. If line numbers are critical you could produce them synthetically by counting events starting with the first event that has `offset == 0`, but I avoid this because it's very error prone especially if you ever add any filtering or multiline grouping.