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 pageshowhide
explore
- SLF4J21 questions
- Provider Binding5 questions
- Placeholder Formatting4 questions
- Fluent API & Key-Value Pairs4 questions
- Legacy API Bridges4 questions
- MDC Across Threads4 questions
- Logback4 questions
- Log4j2empty
- Micrometer3 questions
- Serilog15 questions
- Sinks & Settings6 questions
- Message Templates & Enrichers5 questions
- ASP.NET Core Integration4 questions
- NLogempty
- Winstonempty
- Morgan6 questions
- Zapempty
- Zerologempty
questions
page 2 of 2You 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.
basics
~20 sAsyncAppender 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.
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.
basics
~20 sRegistration 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.
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?
basics
~20 sWith 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.
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?
basics
~20 sPass 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.
Why does Serilog.AspNetCore recommend CreateBootstrapLogger() followed by AddSerilog((services, lc) => ...), and what happens to the bootstrap logger once the host starts?
basics
~20 sA 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.
With Serilog.Sinks.File, how do rollingInterval, fileSizeLimitBytes, rollOnFileSizeLimit and retainedFileCountLimit interact, and why can a plain WriteTo.File("log.txt") stop logging?
basics
~20 sSerilog.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.
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?
basics
~20 sRegister 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 @.
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?
basics
~10 sslf4j-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.
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?
basics
~20 sDefaultLoggingEventBuilder 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.
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?
basics
~20 sBridge 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.
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?
basics
~20 sOn 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.
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?
basics
~10 sSLF4J'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.
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?
basics
~20 sThe 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.
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?
basics
~20 sKeep 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.
What SLF4J dependency rule would you set for every library and service in an organisation, and how would you make the build enforce it?
basics
~20 sLibraries 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.
What does Serilog.Formatting.Compact's CompactJsonFormatter write for each event, and when would you choose RenderedCompactJsonFormatter or the core JsonFormatter instead?
basics
~20 sCompactJsonFormatter 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.
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?
basics
~20 sslf4j.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.
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?
basics
~20 sThe 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.
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?
basics
~10 sAdd 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.
showing 31–49 of 49