Question: I have 2000 batches to run in a single batch job. One of the batch gives "Attempt to de-reference a null object" error. I want to track this error. How can I track? I have used debug logs but they are pretty much in quantity. Is there any way to do so?

Answer: 
I would suggest that you need to add some additional error handling to your batch job. This error message will be caused by you trying to reference a variable that is null, you would need to defensively code for this.

One thing you can do, is to add the Database.Stateful interface to your batch apex class method declaration, e.g. 

```
global class InvoicePosterBatch implements Database.Batchable<SObject>, Database.Stateful

```

By adding this, you can maintain some kind of log of what is happening - you have to be careful though not to exceed the heap size. One strategy I sometimes employ for circumventing that is something like this:

```
    if( Limits.getHeapSize()*1.1 >= Limits.getLimitHeapSize() )
    {
        sendEmail();
        failures = new List<String>();
    }

```

Debugging the batch 'chunks' is difficult because not only do you have your chunk log, you then may have up to 2000 iterations of records within that log. 

Another thing you could do, is say reduce your batch size to 1 and then you will see which record is failing, you could do that by querying the AsyncApexJob object, e.g. 

```
Select Status, NumberOfErrors, ExtendedStatus 
From AsyncApexJob
Where ParentJobId = '707U0000008qTH7'
and NumberOfErrors > 0

```

You can retrieve the 'ParentJobId' from Setup->Monitor->Apex Jobs
Log all the error messages in a custom object .This is the best method i have heard so far.Keep the batch Id and record Id that failed and the error message in the custom object for each batch run.You can clean this for every month to avoid huge data in this .