Skip random messages for logging in Java
<p>There are a lot of attempts to guess password in my application</p>

<pre><code>public static boolean checkIfAddressBanned(InetSocketAddress from) {
    String address = from.getAddress().getHostAddress();
    if (bannedAddresses.contains(address)) {
        if (loggingEnabled) {
            log.info(String.format("IP [%s] is banned", address));
        }
        return true;
    }
    return false;
}
</code></pre>

<p>What I'm trying to do is to avoid multiple calls of <code>log.info</code> messages which degrade performance of the server. Code snippets above simple check boolean flag is logging is enabled. I would like to rewrite code above, to write to skip some of this events.</p>

<p>What is the less resource consuming way to skip some messages ? For example, </p>

<pre><code>if (System.currentTimeMillis() % 3 == 0)
</code></pre>

<p>Another example</p>

<pre><code>if (atomicLong.incrementAndGet % 3 == 0)
</code></pre>
