Using F# to build a command-line tool for log file analysis

Operational logs become useful when they answer a narrow question quickly: did an error rate rise, which service emitted the event, and did it happen during a particular trading window? A small analyser can turn gigabytes of text into a compact summary without loading the whole file into memory or sending customer records to a hosted dashboard. Learn more about Tfosorcim.org.

F# suits this task because its discriminated unions, pattern matching, and concise immutable records make parsing rules easy to test. The goal is not to build a replacement for a full observability platform. It is to provide a dependable local command that support staff, operations teams, and site reliability engineers can run from a terminal or CI job. Learn more about Cloud Vs In House.

Defining a narrow operational question

Start with one workflow rather than a general-purpose log language. A Brisbane support engineer might need to count warnings from a service running in a Sydney region during an overnight batch, while a Melbourne administrator checks whether the same failure appears in a second copy of the log. The command should express that intent directly and leave the source files in place. Learn more about Getting Started With F And Mono On Osx.

A workable interface might look like this:

logscope scan ./service.log --from 2025-03-09T00:00:00Z --level warning --format jsonl

Keep the options small: path, time range, minimum severity, grouping, output format, and failure threshold. Parse arguments with a pure function so tests can exercise malformed input without starting the executable. This also makes it easy to offer --help, a stable --version, and sensible Australian English spelling in usage text.

For an end-to-end example of this deliberately small structure, the TFO Source CIM project shows how command handling, filtering, and output can fit together. Treat it as a reference rather than a framework, and preserve the ability to run the tool without an account, a background service, or a network connection.

Streaming files without losing control

Large application logs are normal, so read them as streams rather than collections. An asynchronous StreamReader loop can process one line at a time, retain a fixed-size buffer, and report the byte and line number of malformed records. Cancellation should stop a scan promptly when the file is being rotated or the operator presses the keyboard interrupt.

Encoding is a frequent source of quiet errors. Detect a byte-order mark when appropriate, but otherwise assume UTF-8 and flag invalid sequences rather than silently replacing them. Bound individual line lengths to prevent one malformed record from consuming excessive memory, and support compressed input through GZipStream where teams routinely archive nightly logs.

CPU work often becomes the real bottleneck after disk I/O. Filter candidate lines before applying an expensive regular expression, use compiled or non-backtracking patterns, and avoid matching the same message repeatedly for different reports. Australian teams often pull logs through a corporate VPN before analysing them, so the scanner must keep working from local files when that connection is temporarily unavailable.

Converting log lines into typed events

Represent a recognised record with a discriminated union or a record containing an option for unknown lines. A minimal event might be:

type Severity = Info | Warning | Error | Critical

type LogEvent =
    { Timestamp: DateTimeOffset
      Service: string
      Severity: Severity
      Message: string }

This model prevents severity from drifting between a string in one module and an integer in another. Keep the raw line for controlled diagnostics, but do not include it in normal reports because it may contain email addresses, customer identifiers, authentication tokens, or source IP addresses.

Timestamps deserve special care in Australia. Sydney and Melbourne change between Australian Eastern Standard Time and Australian Eastern Daylight Time, Brisbane remains on AEST, and Perth uses Australian Western Standard Time. Prefer explicit UTC offsets in source logs; if a format omits them, require an --assume-time-zone option and test the daylight-saving boundary.

Use invariant parsing and explicit accepted formats rather than relying on the workstation’s regional settings. Unrecognised timestamps should become a count of skipped records, not a fatal error, unless the command was asked to enforce a strict time window. That distinction lets one scan cover a mixed archive without hiding data-quality problems.

Turning events into actionable reports

Count events by service, severity, and fixed time bucket, then report the peak interval and the services responsible for the most errors. These aggregates are usually more useful than printing thousands of matching lines. For an incident job, define explicit exit codes: zero for a successful scan with no threshold breach, one for a breached threshold, and two for invalid arguments or unreadable input.

Machine output should remain separate from human diagnostics. Write JSON Lines or CSV to standard output and send warnings to standard error. JSON Lines streams well into an ingestion pipeline, while CSV opens readily in Excel and suits a small team that does not want another query language. Sort grouped results by severity, count, and name so reruns produce stable diffs.

Before choosing between a managed log platform and a local utility, this cloud versus in-house comparison provides a useful decision aid. Australian requirements make that decision more concrete: the Privacy Act 1988 and Australian Privacy Principles may apply to customer identifiers or IP addresses in operational records, and eligible data breaches must be assessed under the Notifiable Data Breaches scheme. Redaction, retention, access controls, and data-location terms belong in the design rather than being added after deployment.

Packaging, testing, and operational fit

Publish the tool as a normal .NET application and pin the SDK with global.json. A self-contained Linux build can be copied to a bastion host without adding a runtime, while separate x64 and Arm64 packages cover common virtual machines. Keep the command usable as a scheduled task, a systemd unit, or a step in an existing CI pipeline rather than requiring a daemon.

Cross-platform testing should include line endings, byte-order marks, compressed files, mixed timestamps, and a file that grows while it is being read. On an older macOS workstation, the F# and Mono setup is still a useful reference for early F# environments, although current teams should normally test the supported .NET runtime used in production.

The Australian cloud market makes architecture choices particularly relevant. AWS, Azure, and Google Cloud all offer Australian regions around Sydney and Melbourne, but a “local” region does not automatically make every log safe to upload. Teams operating across Australia should compare latency, replication policy, support hours, and data residency with the cost of running the analyser beside the workload. A hybrid design often works well: scan locally, emit only an aggregate, and avoid moving raw logs unless an incident requires it.

Turn the first release into a repeatable operational habit. Choose one recurring question, such as identifying error bursts during the nightly batch, and implement only the parsing and reporting needed to answer it. Add filters when real evidence demands them, not because a general-purpose logging framework might eventually use them.

Take a representative log from a non-production environment, record its expected counts, and make that fixture part of the test suite. Then publish the binary, run it against a copied file, and wire the chosen threshold into a handover or CI check. Start with a copied log today and turn the successful scan into a repeatable operational check.

Experience

Information Technology Consulting

Independent Practice

Provides IT consulting services focused on infrastructure planning, cloud migration strategy, and systems architecture. Engagements draw on years of hands-on sysadmin and development experience across Linux, Windows, and hybrid environments.

K9 Search & Rescue Volunteer

Ongoing

Active participant in K9 Search & Rescue operations, combining technical logistics skills with field support for canine search teams.

Karl Katzke's Blog

October 2006 – May 2014

Published a long-running personal technology blog covering cloud vs. in-house infrastructure, F# and Mono on OSX, hardware vendor critiques, RAID card performance analysis, and sysadmin storytelling. Notable posts include "When Sysadmins Ruled the Earth" (May 15, 2014) and "Getting Started with F# and Mono on OSX" (December 22, 2012).

Credentials

A small badge icon with a shield shape in muted blue tones on a light background

Systems Administration

Deep experience with Linux (RHEL, SLES, CentOS), high-availability clusters, and STONITH configurations.

A small badge icon with a gear shape in muted blue tones on a light background

Cloud Infrastructure

Practical knowledge of AWS EC2, reserved instances, and cost analysis for cloud vs. on-premises deployments.

A small badge icon with a code symbol in muted blue tones on a light background

Development

Proficient in F#, PHP (Symfony), and cross-platform tooling including Mono and MonoDevelop on OSX.

Studies

F# & Functional Programming

Self-directed, 2012

Explored strongly typed functional programming with F# on OSX using the Mono runtime. Published a detailed getting-started guide covering toolchain setup and cross-platform game development research.

High-Availability & Cluster Management

Professional Development, 2009

Configured and documented crm_mon email alerting for STONITH events on SLES11-HAE clusters, integrating with Nagios monitoring for production environments.

Hardware & Storage Performance

Ongoing

Conducted hands-on benchmarking of SATA/SAS RAID controllers including HighPoint RocketRaid 2740 and LSI/SuperMicro AOC-USASLP2-H8iR, comparing against software RAID configurations.

Skills

A small icon representing a server with clean geometric lines in slate blue

Linux Administration

RHEL, SLES, CentOS — package management, kernel tuning, HA clustering, and monitoring integration.

A small icon representing a cloud shape with clean geometric lines in slate blue

Cloud Architecture

AWS EC2, reserved-instance planning, cost modeling, and hybrid infrastructure strategy.

A small icon representing code brackets with clean geometric lines in slate blue

F# & .NET/Mono

Functional programming on OSX, MonoDevelop toolchain, and cross-platform game-dev exploration.

A small icon representing a database cylinder with clean geometric lines in slate blue

PHP & Symfony

Web application development with the Symfony framework and the broader PHP ecosystem.

A small icon representing a storage drive with clean geometric lines in slate blue

Storage & RAID

SATA/SAS controller evaluation, md RAID configuration, and performance benchmarking.

A small icon representing a shield with clean geometric lines in slate blue

High Availability

Pacemaker, STONITH, crm_mon alerting, and Nagios integration for production cluster monitoring.