Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Missed one rename from Final API PR #38

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Logging
// ==== ----------------------------------------------------------------------------------------------------------------
// MARK: Context Protocol

/// The `ContextProtocol` MAY be adopted by specific "framework contexts" such as e.g. `CoolFramework.Context` in
/// The `BaggageContext` MAY be adopted by specific "framework contexts" such as e.g. `CoolFramework.Context` in
/// order to allow users to pass such context directly to libraries accepting any context.
///
/// This allows frameworks and library authors to offer APIs which compose more easily.
Expand All @@ -29,9 +29,9 @@ import Logging
/// and also for their user's sanity, as a reference semantics context type can be very confusing to use when shared
/// between multiple threads, as often is the case in server side environments.
///
/// It is STRONGLY encouraged to use the `DefaultContext` as inspiration for a correct implementation of a `Context`,
/// It is STRONGLY encouraged to use the `DefaultContext` as inspiration for a correct implementation of a `BaggageContext`,
/// as the relationship between `Logger` and `Baggage` can be tricky to wrap your head around at first.
public protocol Context {
public protocol BaggageContext {
/// Get the `Baggage` container.
///
/// ### Implementation notes
Expand Down Expand Up @@ -91,7 +91,7 @@ public protocol Context {
var logger: Logger { get set }
}

/// A default `Context` type.
/// A default `BaggageContext` type.
///
/// It is a carrier of contextual `Baggage` and related `Logger`, allowing to log and trace throughout a system.
///
Expand All @@ -106,12 +106,12 @@ public protocol Context {
///
/// ### Accepting context types in APIs
///
/// It is preferred to accept values of `ContextProtocol` in library APIs, as this yields a more flexible API shape,
/// It is preferred to accept values of `BaggageContext` in library APIs, as this yields a more flexible API shape,
/// to which other libraries/frameworks may pass their specific context objects.
///
/// - SeeAlso: `Baggage` from the Baggage module.
/// - SeeAlso: `Logger` from the SwiftLog package.
public struct DefaultContext: Context {
public struct DefaultContext: BaggageContext {
/// The `Baggage` carried with this context.
/// It's values will automatically be made available to the `logger` as metadata when logging.
///
Expand Down Expand Up @@ -155,7 +155,7 @@ public struct DefaultContext: Context {
self._logger.updateMetadata(previous: .topLevel, latest: baggage)
}

public init<C>(context: C) where C: Context {
public init<Context>(context: Context) where Context: BaggageContext {
self.baggage = context.baggage
self._logger = context.logger
self._logger.updateMetadata(previous: .topLevel, latest: self.baggage)
Expand Down
2 changes: 1 addition & 1 deletion Sources/BaggageContextBenchmarkTools/ArgParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class ArgumentParser<U> {
) {
self.arguments.append(
Argument(name: name, help: help)
{ try self.parseArgument(name, property, defaultValue, parser) }
{ try self.parseArgument(name, property, defaultValue, parser) }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func log_loggerWithBaggage(logger: Logger, baggage: Baggage, iters remaining: In
}

@inline(never)
func log_throughContext(context: Context, iters remaining: Int) {
func log_throughContext(context: BaggageContext, iters remaining: Int) {
for _ in 0 ..< remaining {
context.logger.warning(message)
}
Expand All @@ -298,14 +298,14 @@ func log_loggerWithBaggage_trace(logger: Logger, baggage: Baggage, iters remaini
}

@inline(never)
func log_throughContext_trace(context: Context, iters remaining: Int) {
func log_throughContext_trace(context: BaggageContext, iters remaining: Int) {
for _ in 0 ..< remaining {
context.logger.trace(message)
}
}

@inline(never)
func log_materializeOnce_trace(context: Context, iters remaining: Int) {
func log_materializeOnce_trace(context: BaggageContext, iters remaining: Int) {
var logger = context.logger
context.baggage.forEach { key, value in
logger[metadataKey: key.name] = "\(value)"
Expand All @@ -317,7 +317,7 @@ func log_materializeOnce_trace(context: Context, iters remaining: Int) {
}

@inline(never)
func log_materializeOnce(context: Context, iters remaining: Int) {
func log_materializeOnce(context: BaggageContext, iters remaining: Int) {
var logger = context.logger
context.baggage.forEach { key, value in
logger[metadataKey: key.name] = "\(value)"
Expand Down
6 changes: 3 additions & 3 deletions Tests/BaggageContextTests/BaggageContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class BaggageContextTests: XCTestCase {
baggage.testID = 42
let context = ExampleFrameworkContext(context: baggage, logger: logger)

func frameworkFunctionDumpsBaggage(param: String, context: Context) -> String {
func frameworkFunctionDumpsBaggage(param: String, context: BaggageContext) -> String {
var s = ""
context.baggage.forEach { key, item in
s += "\(key.name): \(item)\n"
Expand Down Expand Up @@ -123,7 +123,7 @@ final class BaggageContextTests: XCTestCase {
}
}

struct ExampleFrameworkContext: BaggageContext.Context {
struct ExampleFrameworkContext: BaggageContext {
var baggage: Baggage {
willSet {
self._logger.updateMetadata(previous: self.baggage, latest: newValue)
Expand All @@ -148,7 +148,7 @@ struct ExampleFrameworkContext: BaggageContext.Context {
}
}

struct CoolFrameworkContext: BaggageContext.Context {
struct CoolFrameworkContext: BaggageContext {
var baggage: Baggage {
willSet {
self.logger.updateMetadata(previous: self.baggage, latest: newValue)
Expand Down
2 changes: 1 addition & 1 deletion Tests/BaggageContextTests/FrameworkContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class FrameworkBaggageContextTests: XCTestCase {
}
}

private struct TestFrameworkContext: Context {
private struct TestFrameworkContext: BaggageContext {
var baggage = Baggage.topLevel

private var _logger = Logger(label: "test")
Expand Down
6 changes: 2 additions & 4 deletions Tests/BaggageContextTests/TestLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ extension History {
metadata: Logger.Metadata? = nil,
source: String? = nil,
file: StaticString = #file,
line: UInt = #line)
{
line: UInt = #line) {
let source = source ?? Logger.currentModule(filePath: "\(file)")
let entry = self.find(level: level, message: message, metadata: metadata, source: source)
XCTAssertNotNil(
Expand All @@ -211,8 +210,7 @@ extension History {
metadata: Logger.Metadata? = nil,
source: String? = nil,
file: StaticString = #file,
line: UInt = #line)
{
line: UInt = #line) {
let source = source ?? Logger.currentModule(filePath: "\(file)")
let entry = self.find(level: level, message: message, metadata: metadata, source: source)
XCTAssertNil(
Expand Down