adamflott.com

Adamantium - I - Rules of Logging

Date: 2020-02-03

1 Rules of Logging

A list of rules I've come to use when deciding how to log in backend systems. Note, the examples are real.

1.1 Log Data Not Prose

1.2 Deriving Metrics

Logging data begets the ability to derive metrics:

For example,

data LogEvent
    = LogEventOp !Operation
    | LogEventConfig !Config
    | LogEventConenctionOpen !SockAddr
    | LogEventConenctionClose !SockAddr
    | LogEventEnqueueWebexMessage !WebhookNotify
    | LogEventDequeueWebexMessage !WebhookNotify
    | LogEventCommandNew !Command
    | LogEventCommandNotFound !Text
    | LogEventCommandRunResult !Text ![Text] ExitCode !Text !Timespan
    | LogEventHTTPRequest !Request !Status !(Maybe Integer)
    | LogEventWebexAPIResponse !(Response Message) !Timespan

With Haskell you can pattern match on a LogEvent and derive counts for open and closed connections and then emit another event such as MetricEventConnectionCounts !Word32 !Word32. This works when you mux all your logging streams through a single point.

1.3 Log Data To Fit Your Domain

1.4 Many Levels Aren't As Useful As You Think

1.5 Log Relevant Data

1.6 Avoid Duplicating Already Logged Data

1.7 Serialization Format Matters Less Than The Content

1.8 JSON Is Terrible

1.8.1 Cons

1.8.2 Pros

1.9 Encode as UTF-8 or ASCII

1.10 Don't Worry About Big Data Until You Can't Purchase Hardware Large Enough to Handle It

1.11 Require Dynamic Runtime Volume Adjustment

1.12 Buffer Before Bailing

1.13 Sift When Needed