Skip to content

Website Logging Explained: From Print Statements in Java to Error Monitoring

Java logo above the words How to Print in Java.

When a customer says the checkout failed last Tuesday, the first question a developer asks is "what do the logs say?" Logs are the record a website or application keeps of what happened: requests, errors, payments, logins, and warnings. Good logs turn a vague complaint into a quick fix. Missing or messy logs turn it into days of guesswork.

This guide explains logging for business owners and managers. It starts with how Java programs print messages, moves to proper logging frameworks, and covers what should and should not be logged. It also explains the security lesson of Log4Shell, monitoring and alerts, and the questions to ask your developer.

Printing in Java

The simplest way for a Java program to show a message is System.out.println("Order received");, which prints a line of text to the console. Developers also use System.out.printf to format numbers and text, and System.err for error messages. Printing is how most people write their first program, and it is handy for quick checks while developing.

In a live website or business application, printing to the console is not enough. Messages are not timestamped or categorized, they may vanish when the server restarts, and there is no easy way to search them, filter them, or send an alert when something serious happens.

Logging frameworks

Real applications use logging libraries. In Java, common choices include the built-in java.util.logging, Log4j 2, and Logback, often used through a common interface called SLF4J. Other languages have equivalents, and platforms such as WordPress and hosted store builders keep their own logs.

These libraries add a timestamp, a source, and a level to every message. Typical levels run from DEBUG, for detailed development information, through INFO and WARN, to ERROR for failures. The application can be set to record only WARN and ERROR in production, keeping logs useful without filling the disk.

ApplicationINFO, WARN,ERROR messagesStored logstimestamped,set retentionMonitoringsearch andalert the teamNo passwords, card numbers, or tokens at any stage
Logs are only useful if they are stored, searchable, and watched.

What to log

Useful logs record events you would want to reconstruct later. Examples are failed and successful payments with an order reference, errors with enough detail to find the cause, and logins and failed login attempts. Changes to important settings belong there too, as do calls to outside services such as payment providers or couriers, including whether they succeeded.

Each entry should carry an identifier that links related events, such as an order number or request ID. That lets a developer follow one customer's failed checkout from the first click to the error message in minutes.

What never to log

Logs are often less protected than databases and are copied to more places, so they must never contain secrets. Passwords, full card numbers, card security codes, API tokens, and session tokens should never appear in logs. The PCI Data Security Standard, which applies to businesses that handle card payments, prohibits storing card security codes after authorization and requires card numbers to be protected wherever they are stored.

Personal data needs care too. IP addresses, email addresses, and names in logs are personal data under privacy laws such as the GDPR, so keep only what you need, set a retention period, and delete old logs on schedule. Our guide to tokens in web development explains why tokens deserve the same protection as passwords.

The Log4Shell lesson

In December 2021, a severe vulnerability known as Log4Shell was found in Log4j 2, one of the most widely used Java logging libraries. It allowed attackers to run code on affected servers by getting a specially built text string logged, for example in a form field or a browser header. Organizations around the world spent weeks finding and updating every system that used the library, often deep inside third-party software.

The lesson for business owners is about maintenance rather than logging itself. Every website and application depends on libraries written by others, and those need updates. Ask your developer or agency how they track dependencies and how quickly they apply security updates.

Monitoring and alerts

Logs help most when someone is told about problems before customers complain. Error monitoring services collect errors from your website, group similar ones together, and send an email or chat alert when a new error appears or a known one spikes. Uptime monitors check that your site responds every few minutes and alert you when it does not.

Agree who receives alerts and what happens next. An alert that goes to a former employee's inbox is no better than no alert at all.

Questions to ask your developer

  • Where are our logs stored, and how long are they kept?
  • Who receives alerts for errors and downtime, and how fast do they respond?
  • How do you make sure no passwords, card data, or tokens are logged?
  • How do you track and update the libraries our site depends on?

Logs from integrations

Many of the hardest problems happen between systems: a payment provider sends a webhook that your site rejects, or a courier's API stops accepting shipments. Log each call to an outside service with the time, the order reference, and whether it succeeded, and log the response code when it fails. Our guide to hiring a backend developer for integrations covers what to ask about this.

On shared or managed hosting, some logs are provided for you. Our guide to cPanel shows where to find error and access logs on a typical hosting account, which is often the first place to look when a small site misbehaves.

Finally, test the alerts. Ask your developer to trigger a harmless error on a staging site and confirm the right person receives the alert within minutes. A monitoring setup that has never been tested is a guess.

Logs that save time when it matters

Printing messages with System.out.println is how Java programs start, but business applications need proper logging: timestamped, leveled messages stored for a set period, searched by monitoring tools, and free of passwords, card data, and tokens. Combined with alerts and regular dependency updates, good logging turns outages and failed orders into quick fixes.

If you are unsure whether your website is monitored, our web development team can review it. Our guide to choosing web hosting also explains which logs and monitoring different hosting types include.

Want this checked on your own site?

Check one URL in Swiss Knife SEO without an account. A free account supports crawls of up to 100 URLs.