skip to content

Logging & Observability

Logging frameworks and metrics facades across the JVM, .NET, Node and Go ecosystems. Interviewers ask because structured output and a stable facade are what make logs and metrics usable once you run more than one service.

on this pageshow

explore

questions

page 2 of 2

You wrap a Logback file appender in AsyncAppender to cut latency. Explain the queue model, what queueSize, discardingThreshold, neverBlock and includeCallerData actually do, and which log lines you can silently lose.

level: seniorimportance: should knowfreq 45%

basics

~20 s

AsyncAppender puts events on a bounded blocking queue (default 256) drained by one worker thread. When the queue is 80% full it silently drops TRACE/DEBUG/INFO events by default; when full it blocks the caller unless neverBlock=true, which drops instead. Caller data is not captured unless enabled.

open as a page

In Micrometer, the same counter can be registered from several places without creating duplicate series, a counter on a step-based export registry can read as zero moments after you incremented it, and an export that fails can lose a whole interval. Explain the registry mechanics behind all three: how Micrometer decides that two registrations refer to the same meter, what accumulate-and-reset means for step meters and which interval a step meter's reported value refers to, and what a step-based registry does when a publish fails.

level: seniorimportance: should knowfreq 35%

basics

~20 s

Registration is idempotent: the same name plus tag set is the same Meter.Id, so you get the existing meter back. Step meters report the last completed interval and then reset. Publishing runs on that same step interval, and a failed batch is dropped, not retried.

open as a page

An Express API logs with morgan and immediate: true, and every line shows '-' for status and timing; why, and what do :response-time and :total-time each measure?

level: seniorimportance: should knowfreq 20%

basics

~20 s

With immediate: true morgan writes the line when the request reaches it, before any response exists, so :status, :res[...] and both timers print '-'. Without it, :response-time ends when headers are written and :total-time when the response finishes.

open as a page

With morgan, how do you route access-log lines into the application's structured logger through the stream option, and what changes when that stream is in object mode?

level: seniorimportance: should knowfreq 30%

basics

~20 s

Pass stream: { write: (line) => logger.info(line.trimEnd()) }; morgan calls write with each formatted line plus a newline. Since morgan 1.12.0, a stream whose writableObjectMode is true receives a format function's returned object as-is, with no newline.

open as a page

Why does Serilog.AspNetCore recommend CreateBootstrapLogger() followed by AddSerilog((services, lc) => ...), and what happens to the bootstrap logger once the host starts?

level: seniorimportance: should knowfreq 45%

basics

~20 s

A bootstrap logger exists before the host, so failures while building it are still logged; the final logger, configured once configuration and DI exist, then completely replaces it. CreateBootstrapLogger() returns a ReloadableLogger that AddSerilog reloads and freezes.

open as a page

With Serilog.Sinks.File, how do rollingInterval, fileSizeLimitBytes, rollOnFileSizeLimit and retainedFileCountLimit interact, and why can a plain WriteTo.File("log.txt") stop logging?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Serilog.Sinks.File caps each file at 1 GB by default. Without rollingInterval or rollOnFileSizeLimit there is no roll point, so a full log.txt silently drops new events. Rolling creates a file set; retainedFileCountLimit (31) prunes the oldest.

open as a page

How do you stop Serilog from logging a shipment's recipient details or its whole object graph, using Destructure.ByTransforming, the size limits and a custom IDestructuringPolicy?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Register Destructure.ByTransforming<Shipment>(s => new { s.TrackingNumber, s.Status }) so {@Shipment} logs only safe fields, cap graphs with ToMaximumDepth, ToMaximumStringLength and ToMaximumCollectionCount, and write an IDestructuringPolicy for rules across many types. None of these affect {Shipment} without @.

open as a page

A service upgraded from SLF4J 1.7 to slf4j-api 2.0 stopped writing application logs while its 1.7-era binding jar is still deployed; how do you diagnose and fix it?

level: seniorimportance: should knowfreq 48%

basics

~10 s

slf4j-api 2.0 finds backends only through ServiceLoader and ignores 1.7-era StaticLoggerBinder bindings, so it falls back to a no-op logger and prints 'Ignoring binding found at'. Replace the binding with the backend's 2.0 provider.

open as a page

A payments team's SLF4J 2.0 addKeyValue() pairs print as `orderId=42 Payment captured` on one backend but as separate fields on another; why?

level: seniorimportance: should knowfreq 28%

basics

~20 s

DefaultLoggingEventBuilder hands the whole event to a Logger that implements LoggingEventAware; for any other Logger it prefixes markers and key=value text to the message and calls the classic API. Only an event-aware logger receives the pairs as data.

open as a page

Third-party dependencies in a JVM service log through java.util.logging, Apache Commons Logging and Log4j 1.x, yet operations wants a single log stream. How do the SLF4J bridge jars solve this, and what must you avoid when installing them?

level: seniorimportance: should knowfreq 45%

basics

~20 s

Bridge jars re-implement each legacy API on top of SLF4J so those calls land in your one backend. Rules: never ship both a bridge and the binding that routes back to the same framework (infinite loop), and exclude the original legacy jar.

open as a page

A Spring Boot service embeds one library logging through Log4j 1 and another through the Log4j 2 API; which Log4j-related SLF4J jars do you ship when the backend is Logback, and when it is Log4j 2?

level: seniorimportance: should knowfreq 32%

basics

~20 s

On Logback, ship log4j-over-slf4j for Log4j 1 calls and log4j-to-slf4j for Log4j 2 API calls. On Log4j 2, keep log4j-over-slf4j but bind SLF4J with log4j-slf4j2-impl and drop log4j-to-slf4j. Never pair a jar with its reverse.

open as a page

A service on SLF4J 2.0 calls MDC.put on every request, yet the request id never reaches its logs and nothing errors; how does the provider's MDCAdapter explain that?

level: seniorimportance: should knowfreq 35%

basics

~10 s

SLF4J's MDC only delegates to the MDCAdapter the bound provider supplies. slf4j-simple, slf4j-nop and the no-provider fallback supply NOPMDCAdapter, which discards every put, so MDC silently does nothing; check which provider bound.

open as a page

On an inventory service's hot path, what does a disabled SLF4J `log.debug` call with four arguments still cost, and how would you measure that cost?

level: seniorimportance: should knowfreq 44%

basics

~20 s

The call still evaluates every argument expression, boxes primitive arguments and, with three or more arguments, allocates the varargs Object[] before the level check runs. Measure it with a JMH benchmark using the GC profiler, and JFR allocation sampling in production.

open as a page

As the lead setting an access-log standard for a team's Express services, would you standardise on morgan's combined format or a shared format function emitting structured entries, and which fields must every entry carry?

level: principalimportance: should knowfreq 15%

basics

~20 s

Keep combined only where an existing parser expects it. Otherwise ship one shared morgan 1.12+ format function writing one structured entry per request to the app logger: request id, method, path, status, both timers, size; never credentials or query strings.

open as a page

What SLF4J dependency rule would you set for every library and service in an organisation, and how would you make the build enforce it?

level: principalimportance: should knowfreq 30%

basics

~20 s

Libraries depend on slf4j-api only; each application ships exactly one provider at runtime scope and no 1.7-era binding. Because SLF4J merely warns or goes silent, a build check counting providers and StaticLoggerBinder resources must enforce it.

open as a page

What does Serilog.Formatting.Compact's CompactJsonFormatter write for each event, and when would you choose RenderedCompactJsonFormatter or the core JsonFormatter instead?

level: middleimportance: nice to knowfreq 25%

basics

~20 s

CompactJsonFormatter writes one JSON object per line: @t, @mt, @r for formatted holes, @l (omitted for Information), @x, @tr/@sp, then every property at the top level. RenderedCompactJsonFormatter writes a rendered @m and an @i event id instead of @mt.

open as a page

In SLF4J 2.0.9 and later, what does the slf4j.provider system property do, and why is it a stopgap rather than a fix?

level: middleimportance: nice to knowfreq 35%

basics

~20 s

slf4j.provider names one SLF4JServiceProvider class; if it instantiates, SLF4J skips ServiceLoader discovery. If it fails, SLF4J prints an error and falls back to discovery. The extra provider stays on the classpath, so it masks the problem.

open as a page

SLF4J 2.0 added a fluent logging API entered through methods such as `atInfo()` and `atDebug()`. What does it offer over the classic `info(String, Object...)` calls, and how do its key-value pairs differ from Mapped Diagnostic Context entries and from Markers?

level: middleimportance: nice to knowfreq 25%

basics

~20 s

The fluent API builds an event step by step: message, arguments, key-value pairs, a marker, a cause, then log. Its key-value pairs are per-event structured fields; MDC entries are per-thread ambient context; markers are labels for routing and filtering, not data.

open as a page

In SLF4J 2.0, how do calls to the JDK's System.Logger reach SLF4J, and does a Spring application still need jcl-over-slf4j for Commons Logging?

level: middleimportance: nice to knowfreq 27%

basics

~10 s

Add slf4j-jdk-platform-logging: its SLF4JSystemLoggerFinder is the JDK's System.LoggerFinder service and hands every System.Logger to SLF4J. Spring Framework 7.0.9's spring-core already depends on Apache commons-logging 1.3.5, so check that before adding jcl-over-slf4j.

open as a page

showing 31–49 of 49