Skip to content
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
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
groups:
dependencies:
patterns:
- "*"
- package-ecosystem: "swift"
directory: "/"
schedule:
interval: "daily"
groups:
dependencies:
patterns:
- "*"
26 changes: 19 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,42 @@ on:

jobs:
unit-tests:
permissions:
contents: read
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
with:
# with_windows: true
with_windows: true
with_musl: true
# with_android: true
with_android: true
with_linting: true
enable_all_traits: true
secrets: inherit

package-traits:
permissions:
contents: read
runs-on: ubuntu-latest
container: swift:6.2-bookworm
container: swift:noble
steps:
- name: Check out ConsoleKit
uses: actions/checkout@v6
- name: Run tests with traits disabled
run: swift test --disable-default-traits


submit-dependencies:
permissions:
contents: write
if: ${{ github.event_name == 'push' }}
uses: vapor/ci/.github/workflows/submit-deps.yml@main
secrets: inherit

# integration-check:
# runs-on: ubuntu-latest
# container: swift:noble
# steps:
# - uses: actions/checkout@v4
# - uses: actions/checkout@v6
# with: { path: console-kit }
# - uses: actions/checkout@v4
# - uses: actions/checkout@v6
# with: { repository: 'vapor/vapor', path: vapor }
# - run: swift package --package-path vapor edit console-kit --path console-kit
# - run: SWIFT_DETERMINISTIC_HASHING=1 swift test --package-path vapor
# - run: swift test --package-path vapor
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
.default(enabledTraits: ["ConfigReader"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-log.git", from: "1.8.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.11.0"),
.package(url: "https://github.com/apple/swift-async-algorithms.git", from: "1.1.1"),
.package(url: "https://github.com/apple/swift-configuration.git", from: "1.0.0", traits: [.defaults, "CommandLineArguments"]),
],
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/console-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/console-kit/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/github/vapor/console-kit"><img src="https://img.shields.io/codecov/c/github/vapor/console-kit?style=plastic&logo=codecov&label=codecov" alt="Code Coverage"></a>
<a href="https://github.com/vapor/console-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/console-kit/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/gh/vapor/console-kit"><img src="https://img.shields.io/codecov/c/gh/vapor/console-kit?style=plastic&logo=codecov&label=codecov" alt="Code Coverage"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift61up.svg" alt="Swift 6.1+"></a>
</p>

Expand Down
30 changes: 17 additions & 13 deletions Sources/ConsoleKit/Docs.docc/images/vapor-consolekit-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions Sources/ConsoleKit/Docs.docc/theme-settings.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"theme": {
"aside": { "border-radius": "16px", "border-style": "double", "border-width": "3px" },
"aside": { "border-radius": "16px", "border-width": "3px", "border-style": "double" },
"border-radius": "0",
"button": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" },
"code": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" },
"color": {
"consolekit": "#392048",
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-consolekit) 30%, #000 100%)",
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-consolekit) 30%, #000 100%)",
"documentation-intro-accent": "var(--color-consolekit)",
"documentation-intro-eyebrow": "white",
"hero-eyebrow": "white",
"documentation-intro-figure": "white",
"documentation-intro-title": "white",
"hero-title": "white",
"logo-base": { "dark": "#fff", "light": "#000" },
"logo-shape": { "dark": "#000", "light": "#fff" },
"fill": { "dark": "#000", "light": "#fff" }
},
"icons": { "technology": "/consolekit/images/vapor-consolekit-logo.svg" }
"icons": { "technology": "/consolekit/images/ConsoleKit/vapor-consolekit-logo.svg" }
},
"features": {
"quickNavigation": { "enable": true },
Expand Down
4 changes: 4 additions & 0 deletions Sources/ConsoleKit/Terminal/ANSI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ extension Terminal {

// fdopen() on stdout is fast; also the returned file MUST NOT be fclose()d
// This avoids concurrency complaints due to accessing global `stdout`.
#if os(Windows)
fflush(_fdopen(_fileno(stdout), "w+"))
#else
fflush(fdopen(STDOUT_FILENO, "w+"))
#endif
}
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/ConsoleKit/Terminal/Console.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ extension Console {
#if Xcode
// Xcode output does not support ANSI commands
return false
#elseif os(Windows)
return _isatty(_fileno(stdout)) > 0
#else
// If STDOUT is not an interactive terminal then omit ANSI commands
return isatty(STDOUT_FILENO) > 0
Expand Down
5 changes: 1 addition & 4 deletions Sources/ConsoleKit/Terminal/Terminal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ import Darwin.C
import WASILibc
#elseif os(Windows)
import CRT
import WinSDK
#endif

import Synchronization

#if os(Windows)
import WinSDK
#endif

/// Generic console that uses a mixture of Swift and C standard
/// libraries to fulfill protocol requirements.
public final class Terminal: Console, Sendable {
Expand Down
2 changes: 2 additions & 0 deletions Sources/ConsoleLogger/ANSIColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ private var supportsANSICommands: Bool {
#if Xcode
// Xcode output does not support ANSI commands
return false
#elseif os(Windows)
return _isatty(_fileno(stdout)) > 0
#else
// If STDOUT is not an interactive terminal then omit ANSI commands
return isatty(STDOUT_FILENO) > 0
Expand Down
8 changes: 4 additions & 4 deletions Sources/ConsoleLogger/ConsoleLogger+bootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public import Configuration
#endif

extension ConsoleLogger {
/// Bootstraps a ``ConsoleLogger`` to the `LoggingSystem`, so that logger will be used in `Logger.init(label:)`.
/// Bootstraps a ``ConsoleLogger`` to the `LoggingSystem` as the default log handler.
///
/// ```swift
/// ConsoleLogger.bootstrap()
Expand All @@ -30,7 +30,7 @@ extension ConsoleLogger {
)
}

/// Bootstraps a ``ConsoleLogger`` to the `LoggingSystem`, so that logger will be used in `Logger.init(label:)`.
/// Bootstraps a ``ConsoleLogger`` to the `LoggingSystem` as the default log handler.
///
/// ```swift
/// ConsoleLogger.bootstrap() {
Expand All @@ -55,7 +55,7 @@ extension ConsoleLogger {
}

#if ConfigReader
/// Bootstraps a ``ConsoleLogger`` to the `LoggingSystem`, so that logger will be used in `Logger.init(label:)`.
/// Bootstraps a ``ConsoleLogger`` to the `LoggingSystem` as the default log handler.
///
/// ```swift
/// ConsoleLogger.bootstrapWithConfigReader(config: ConfigReader(...))
Expand Down Expand Up @@ -86,7 +86,7 @@ extension ConsoleLogger {
)
}

/// Bootstraps a ``ConsoleLogger`` to the `LoggingSystem`, so that logger will be used in `Logger.init(label:)`.
/// Bootstraps a ``ConsoleLogger`` to the `LoggingSystem` as the default log handler.
///
/// ```swift
/// ConsoleLogger.bootstrapWithConfigReader(config: ConfigReader(...)) {
Expand Down
59 changes: 23 additions & 36 deletions Sources/ConsoleLogger/ConsoleLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ public import Configuration

/// Outputs logs to console via a ``LoggerFragment`` pipeline.
public struct ConsoleLogger<T: LoggerFragment>: LogHandler, Sendable {
/// The log handler's label.
public let label: String

/// See `LogHandler.metadata`.
// See `LogHandler.metadata`.
public var metadata: Logger.Metadata

/// See `LogHandler.metadataProvider`.
// See `LogHandler.metadataProvider`.
public var metadataProvider: Logger.MetadataProvider?

/// See `LogHandler.logLevel`.
// See `LogHandler.logLevel`.
public var logLevel: Logger.Level

/// The ``LoggerFragment`` this logger outputs through.
Expand All @@ -29,9 +30,9 @@ public struct ConsoleLogger<T: LoggerFragment>: LogHandler, Sendable {
/// - fragment: The ``LoggerFragment`` this logger outputs through.
/// - printer: The ``ConsoleLoggerPrinter`` used to output log messages.
/// - label: Unique identifier for this logger.
/// - level: The minimum level of message that the logger will output. This defaults to `.debug`, the lowest level.
/// - metadata: Extra metadata to log with the message. This defaults to an empty dictionary.
/// - metadataProvider: The metadata provider to use for this logger. This defaults to `nil`.
/// - level: The minimum level of message that the logger will output. Defaults to `.debug`.
/// - metadata: Extra metadata to log with the message. Defaults to an empty dictionary.
/// - metadataProvider: The metadata provider to use for this logger. Defaults to `nil`.
public init(
fragment: T = .default,
printer: any ConsoleLoggerPrinter = DefaultConsoleLoggerPrinter(),
Expand All @@ -53,9 +54,9 @@ public struct ConsoleLogger<T: LoggerFragment>: LogHandler, Sendable {
/// - Parameters:
/// - printer: The ``ConsoleLoggerPrinter`` used to output log messages.
/// - label: Unique identifier for this logger.
/// - level: The minimum level of message that the logger will output. This defaults to `.debug`, the lowest level.
/// - metadata: Extra metadata to log with the message. This defaults to an empty dictionary.
/// - metadataProvider: The metadata provider to use for this logger. This defaults to `nil`.
/// - level: The minimum level of message that the logger will output. Defaults to `.debug`.
/// - metadata: Extra metadata to log with the message. Defaults to an empty dictionary.
/// - metadataProvider: The metadata provider to use for this logger. Defaults to `nil`.
/// - fragment: The ``LoggerFragment`` this logger outputs through.
public init(
printer: any ConsoleLoggerPrinter = DefaultConsoleLoggerPrinter(),
Expand Down Expand Up @@ -83,9 +84,9 @@ public struct ConsoleLogger<T: LoggerFragment>: LogHandler, Sendable {
/// - fragment: The ``LoggerFragment`` this logger outputs through.
/// - printer: The ``ConsoleLoggerPrinter`` used to output log messages.
/// - label: Unique identifier for this logger.
/// - config: The config reader to read the log level from. This defaults to `.debug`, the lowest level.
/// - metadata: Extra metadata to log with the message. This defaults to an empty dictionary.
/// - metadataProvider: The metadata provider to use for this logger. This defaults to `nil`.
/// - config: The config reader to read the log level from. Defaults to `.debug`.
/// - metadata: Extra metadata to log with the message. Defaults to an empty dictionary.
/// - metadataProvider: The metadata provider to use for this logger. Defaults to `nil`.
public init(
fragment: T = .default,
printer: any ConsoleLoggerPrinter = DefaultConsoleLoggerPrinter(),
Expand Down Expand Up @@ -131,33 +132,23 @@ public struct ConsoleLogger<T: LoggerFragment>: LogHandler, Sendable {
}
#endif

/// See `LogHandler[metadataKey:]`.
///
/// This just acts as a getter/setter for the ``ConsoleLogger/metadata`` property.
// See `LogHandler.subscript(metadataKey:)`.
public subscript(metadataKey key: String) -> Logger.Metadata.Value? {
get { self.metadata[key] }
set { self.metadata[key] = newValue }
}

/// See `LogHandler.log(level:message:metadata:source:file:function:line:)`.
public func log(
level: Logger.Level,
message: Logger.Message,
metadata: Logger.Metadata?,
source: String,
file: String,
function: String,
line: UInt
) {
// See `LogHandler.log(event:)`.
public func log(event: LogEvent) {
var output = FragmentOutput()
var record = LogRecord(
level: level,
message: message,
metadata: metadata,
source: source,
file: file,
function: function,
line: line,
level: event.level,
message: event.message,
metadata: event.metadata,
source: event.source,
file: event.file,
function: event.function,
line: event.line,
label: self.label,
loggerLevel: self.logLevel,
loggerMetadata: self.metadata,
Expand All @@ -180,8 +171,4 @@ extension Logger.Level {
case .critical: .brightRed
}
}

public var name: String {
"\(self)".uppercased()
}
}
30 changes: 17 additions & 13 deletions Sources/ConsoleLogger/Docs.docc/images/vapor-consolekit-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading