---
title: "ApexLogs good practices"
url: "https://blog.beyondthecloud.dev/tips/apexlogs-good-practices"
category: "Apex"
tags: "best-practices, debugging"
published: "2024-04-02"
---

# ApexLogs good practices

Go to Developer Console, Query Editor and do the following: 1. Enter SELECT Id, LogLength FROM ApexLog ORDER BY LogLength DESC into input and click “Execute” 2. Select all the logs (logs…

### Do you struggle with too many debug logs?

When opening the developer console, this message greets you?

![ApexLogs good practices — screenshot 1](https://blog.beyondthecloud.dev/tips/apexlogs-good-practices/fig-1.webp)

There are a few things that can be done!

First, clean up the existing logs:

![ApexLogs good practices — screenshot 2](https://blog.beyondthecloud.dev/tips/apexlogs-good-practices/fig-2.webp)

Go to Developer Console, Query Editor and do the following: 1. Enter SELECT Id, LogLength FROM ApexLog ORDER BY LogLength DESC into input and click “Execute” 2. Select all the logs (logs are sorted from biggest to smallest) 3. Click “Delete Row” to remove no longer needed log

Good practices, to prevent it in the future:

1. When setting user trace flags, select only the period you will be using the logs, smaller the better:

![ApexLogs good practices — screenshot 3](https://blog.beyondthecloud.dev/tips/apexlogs-good-practices/fig-3.webp)

![ApexLogs good practices — screenshot 4](https://blog.beyondthecloud.dev/tips/apexlogs-good-practices/fig-4.webp)

2. Try to never set logs for Integration users or Test Automation users

3. Remove unnecessary System.debug from the files

```apex
HttpResponse response = http.send(request);
System.debug(response.getBody());
System.debug(response.getStatusCode())
```

4. Use Logger framework or Debugger tools instead of System.debug
