<p>A few things to keep in mind.</p>

<ol>
<li><p><code>LogLevel::Info</code>is only going to be logged when <code>devMode</code> is enabled, so any overhead from excessive logging won't be an issue in production.</p></li>
<li><p>Excessive logging will consume extra memory because all logging information on a given request is stored in memory and flushed to disk at the end of the request, but overall I imaging that the performance hit will be negligible.</p></li>
<li><p>Excessive logging will cause your log files to rotate out quicker.  By default Craft will cap each log file at 1MB worth of data and will start to rotate out the older files after 6MB worth of data has been hit.</p></li>
</ol>

CC BY-SA 3.0
2015-09-01T14:48:57.643Z
Perfect, thank you!
Alec Ritson
CC BY-SA 3.0
2015-09-01T14:47:36.393Z
2015-09-01T17:14:36.450Z
2015-09-01T17:14:36.450Z
Brad Bell
<p>With regards to logging in your own plugin, is there a point which could be considered "You are logging too much" For example. In a service I currently have something like this:</p>

<pre><code>public function getSomeRecordsByParentId($id)
{
  FooPlugin::log(Craft::t("Getting all records for parent id {$id}"), LogLevel::Info);

  // .. do service logic here

  FooPlugin::log(Craft::t("Found {$recordCount} records for parent with id {$id}"), LogLevel::Info);
}
</code></pre>

<p>And then again</p>

<pre><code>public function getRecordById($id)
{
    FooPlugin::log(Craft::log("Trying to find record with an id of {$id}"), LogLevel::Info);

    $record = FooRecord::model()-&gt;findByPk($id);

    if(!$record)
    {
        FooPlugin::log(Craft::log("Unable to find record with id {$id}"), LogLevel::Error);
        throw new HttpException(404);
    }

    return FooModel::populateModel($record);
}
</code></pre>

<p>I know I'm only doing two per function at the moment but when they are all called it can really start to stack up.</p>

<p>I guess what i'm asking is are there any real performance hits that are going to be noticeable or has anyone noticed anything from logging a lot of things?</p>

<plugin-development><logging>
When should I log in a plugin?
# When should I log in a plugin?

(Asked by: username_0 on 2015-09-01)

With regards to logging in your own plugin, is there a point which could be considered "You are logging too much" For example. In a service I currently have something like this:
public function getSomeRecordsByParentId($id)
{
  FooPlugin::log(Craft::t("Getting all records for parent id {$id}"), LogLevel::Info);

  // .. do service logic here

  FooPlugin::log(Craft::t("Found {$recordCount} records for parent with id {$id}"), LogLevel::Info);
}

And then again
public function getRecordById($id)
{
    FooPlugin::log(Craft::log("Trying to find record with an id of {$id}"), LogLevel::Info);

    $record = FooRecord::model()->findByPk($id);

    if(!$record)
    {
        FooPlugin::log(Craft::log("Unable to find record with id {$id}"), LogLevel::Error);
        throw new HttpException(404);
    }

    return FooModel::populateModel($record);
}

I know I'm only doing two per function at the moment but when they are all called it can really start to stack up.
I guess what i'm asking is are there any real performance hits that are going to be noticeable or has anyone noticed anything from logging a lot of things?

**Tags:** plugin-development, logging


---

## 1 answers

### Answer by username_1 on 2015-09-01. Score: 4 | Accepted answer

A few things to keep in mind.

1. `LogLevel::Info`is only going to be logged when `devMode` is enabled, so any overhead from excessive logging won't be an issue in production.
2. Excessive logging will consume extra memory because all logging information on a given request is stored in memory and flushed to disk at the end of the request, but overall I imaging that the performance hit will be negligible.
3. Excessive logging will cause your log files to rotate out quicker. By default Craft will cap each log file at 1MB worth of data and will start to rotate out the older files after 6MB worth of data has been hit.

> **Comments:**
> **username_0**: Perfect, thank you!  

---

