From 989135f1c2067dfe9e07403ec6c09ad433069de3 Mon Sep 17 00:00:00 2001
From: Nikita Vasilev
Date: Mon, 22 Dec 2025 16:14:05 +0400
Subject: [PATCH] docs: update README.md
---
CONTRIBUTING.md | 653 ++++++++++++++++--
README.md | 458 ++++++++++--
.../Formatters/TimestampLogFormatter.swift | 2 +-
.../Core/Printers/ConsolePrinter.swift | 4 +-
.../Log/Classes/Core/Printers/OSPrinter.swift | 34 +-
5 files changed, 1051 insertions(+), 100 deletions(-)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 349d9ec..69e2092 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,61 +1,634 @@
-# Contributing Guidelines
+# Contributing to Log
-This document contains information and guidelines about contributing to this project.
-Please read it before you start participating.
+First off, thank you for considering contributing to Log! It's people like you that make Log such a great tool.
-**Topics**
+## Table of Contents
-* [Reporting Issues](#reporting-issues)
-* [Submitting Pull Requests](#submitting-pull-requests)
-* [Developers Certificate of Origin](#developers-certificate-of-origin)
-* [Code of Conduct](#code-of-conduct)
+- [Code of Conduct](#code-of-conduct)
+- [Getting Started](#getting-started)
+ - [Development Setup](#development-setup)
+ - [Project Structure](#project-structure)
+- [How Can I Contribute?](#how-can-i-contribute)
+ - [Reporting Bugs](#reporting-bugs)
+ - [Suggesting Features](#suggesting-features)
+ - [Improving Documentation](#improving-documentation)
+ - [Submitting Code](#submitting-code)
+- [Development Workflow](#development-workflow)
+ - [Branching Strategy](#branching-strategy)
+ - [Commit Guidelines](#commit-guidelines)
+ - [Pull Request Process](#pull-request-process)
+- [Coding Standards](#coding-standards)
+ - [Swift Style Guide](#swift-style-guide)
+ - [Code Quality](#code-quality)
+ - [Testing Requirements](#testing-requirements)
+- [Community](#community)
-## Reporting Issues
+## Code of Conduct
-A great way to contribute to the project is to send a detailed issue when you encounter a problem. We always appreciate a well-written, thorough bug report.
+This project and everyone participating in it is governed by our Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to nv3212@gmail.com.
-Check that the project issues database doesn't already include that problem or suggestion before submitting an issue. If you find a match, feel free to vote for the issue by adding a reaction. Doing this helps prioritize the most common problems and requests.
+See [CODE_OF_CONDUCT.md](https://github.com/space-code/log/blob/main/CODE_OF_CONDUCT.md) for details.
-When reporting issues, please fill out our issue template. The information the template asks for will help us review and fix your issue faster.
+## Getting Started
-## Submitting Pull Requests
+### Development Setup
-You can contribute by fixing bugs or adding new features. For larger code changes, we recommend first discussing your ideas on our [GitHub Discussions](https://github.com/space-code/log/discussions). When submitting a pull request, please add relevant tests and ensure your changes don't break any existing tests.
+1. **Fork the repository**
+ ```bash
+ # Click the "Fork" button on GitHub
+ ```
-## Developer's Certificate of Origin 1.1
+2. **Clone your fork**
+ ```bash
+ git clone https://github.com/YOUR_USERNAME/log.git
+ cd log
+ ```
-By making a contribution to this project, I certify that:
+3. **Set up the development environment**
+ ```bash
+ # Bootstrap the project
+ make bootstrap
+ ```
-- (a) The contribution was created in whole or in part by me and I
- have the right to submit it under the open source license
- indicated in the file; or
+4. **Create a feature branch**
+ ```bash
+ git checkout -b feature/your-feature-name
+ ```
-- (b) The contribution is based upon previous work that, to the best
- of my knowledge, is covered under an appropriate open source
- license and I have the right under that license to submit that
- work with modifications, whether created in whole or in part
- by me, under the same open source license (unless I am
- permitted to submit under a different license), as indicated
- in the file; or
+5. **Open the project in Xcode**
+ ```bash
+ open Package.swift
+ ```
-- (c) The contribution was provided directly to me by some other
- person who certified (a), (b) or (c) and I have not modified
- it.
+## How Can I Contribute?
-- (d) I understand and agree that this project and the contribution
- are public and that a record of the contribution (including all
- personal information I submit with it, including my sign-off) is
- maintained indefinitely and may be redistributed consistent with
- this project or the open source license(s) involved.
+### Reporting Bugs
-## Code of Conduct
+Before creating a bug report, please check the [existing issues](https://github.com/space-code/log/issues) to avoid duplicates.
+
+When creating a bug report, include:
+
+- **Clear title** - Describe the issue concisely
+- **Reproduction steps** - Detailed steps to reproduce the bug
+- **Expected behavior** - What you expected to happen
+- **Actual behavior** - What actually happened
+- **Environment** - OS, Xcode version, Swift version
+- **Code samples** - Minimal reproducible example
+- **Error messages** - Complete error output if applicable
+
+**Example:**
+```markdown
+**Title:** TimestampLogFormatter produces incorrect date format
+
+**Steps to reproduce:**
+1. Create TimestampLogFormatter with custom date format
+2. Log a message with the formatter
+3. Observe the timestamp output
+
+**Expected:** Timestamp should use the specified format "yyyy-MM-dd"
+**Actual:** Timestamp uses default format "HH:mm:ss"
+
+**Environment:**
+- iOS 16.0
+- Xcode 14.3
+- Swift 5.7
+
+**Code:**
+\`\`\`swift
+let formatter = TimestampLogFormatter(dateFormat: "yyyy-MM-dd")
+let printer = ConsolePrinter(formatters: [formatter])
+let log = Logger(printers: [printer], logLevel: .all)
+log.info(message: "Test")
+// Expected: ℹ️ 2024-01-15 => Test
+// Actual: ℹ️ 14:30:45 => Test
+\`\`\`
+```
+
+### Suggesting Features
+
+We love feature suggestions! When proposing a new feature, include:
+
+- **Problem statement** - What problem does this solve?
+- **Proposed solution** - How should it work?
+- **Alternatives** - What alternatives did you consider?
+- **Use cases** - Real-world scenarios
+- **API design** - Example code showing usage
+- **Breaking changes** - Will this break existing code?
+
+**Example:**
+```markdown
+**Feature:** Add JSON formatter for structured logging
+
+**Problem:** Current formatters produce plain text, making it difficult to parse logs programmatically or integrate with log aggregation services.
+
+**Solution:** Add JSONLogFormatter that outputs logs in structured JSON format.
+
+**API:**
+\`\`\`swift
+let formatter = JSONLogFormatter(
+ includeTimestamp: true,
+ includeLevel: true,
+ additionalFields: ["environment": "production"]
+)
+
+let printer = ConsolePrinter(formatters: [formatter])
+let log = Logger(printers: [printer], logLevel: .all)
+log.info(message: "User logged in")
+
+// Output: {"level":"info","timestamp":"2024-01-15T14:30:45Z","message":"User logged in","environment":"production"}
+\`\`\`
+
+**Use case:** Mobile apps that send logs to centralized logging services like Elasticsearch or Splunk.
+```
+
+### Improving Documentation
+
+Documentation improvements are always welcome:
+
+- **Code comments** - Add/improve inline documentation
+- **DocC documentation** - Enhance documentation articles
+- **README** - Fix typos, add examples
+- **Guides** - Write tutorials or how-to guides
+- **API documentation** - Document public APIs
+
+### Submitting Code
-The Code of Conduct governs how we behave in public or in private
-whenever the project will be judged by our actions.
-We expect it to be honored by everyone who contributes to this project.
+1. **Check existing work** - Look for related issues or PRs
+2. **Discuss major changes** - Open an issue for large features
+3. **Follow coding standards** - See [Coding Standards](#coding-standards)
+4. **Write tests** - All code changes require tests
+5. **Update documentation** - Keep docs in sync with code
+6. **Create a pull request** - Use clear description
-See [CODE_OF_CONDUCT.md](https://github.com/space-code/log/blob/master/CODE_OF_CONDUCT.md) for details.
+## Development Workflow
+
+### Branching Strategy
+
+We use a simplified branching model:
+
+- **`main`** - Main development branch (all PRs target this)
+- **`feature/*`** - New features
+- **`fix/*`** - Bug fixes
+- **`docs/*`** - Documentation updates
+- **`refactor/*`** - Code refactoring
+- **`test/*`** - Test improvements
+
+**Branch naming examples:**
+```bash
+feature/json-formatter
+fix/timestamp-formatter-timezone
+docs/update-formatter-guide
+refactor/simplify-printer-protocol
+test/add-logger-edge-cases
+```
+
+### Commit Guidelines
+
+We use [Conventional Commits](https://www.conventionalcommits.org/) for clear, structured commit history.
+
+**Format:**
+```
+():
+
+
+
+
## Description
-`Log` is a lightweight logging framework written in Swift.
+Log is a lightweight, flexible Swift logging framework that provides elegant and customizable logging capabilities for iOS, macOS, tvOS, watchOS, and visionOS applications. With support for multiple output destinations and custom formatting, Log makes debugging and monitoring your apps easier than ever.
+
+## Features
+
+✨ **Multiple Output Destinations** - Console, system log (os_log), and custom printers
+🎨 **Customizable Formatting** - Prefix, timestamp, and custom formatters
+📊 **Log Levels** - Fine-grained control over message severity
+🔧 **Extensible** - Easy to create custom printers and formatters
+📱 **Cross-Platform** - Works on iOS, macOS, tvOS, watchOS, and visionOS
+⚡ **Lightweight** - Minimal footprint with zero dependencies
+🎯 **Type-Safe** - Leverages Swift's type system for compile-time safety
+
+## Table of Contents
-- [Usage](#usage)
- [Requirements](#requirements)
- [Installation](#installation)
+- [Quick Start](#quick-start)
+- [Usage](#usage)
+ - [Creating a Logger](#creating-a-logger)
+ - [Log Levels](#log-levels)
+ - [Printers](#printers)
+ - [Message Formatting](#message-formatting)
+ - [Custom Formatters](#custom-formatters)
+- [Common Use Cases](#common-use-cases)
- [Communication](#communication)
- [Contributing](#contributing)
+ - [Development Setup](#development-setup)
- [Author](#author)
- [License](#license)
-## Usage
+## Requirements
+
+| Platform | Minimum Version |
+|-----------|----------------|
+| iOS | 13.0+ |
+| macOS | 10.15+ |
+| tvOS | 13.0+ |
+| watchOS | 7.0+ |
+| visionOS | 1.0+ |
+| Xcode | 15.3+ |
+| Swift | 5.10+ |
+
+## Installation
+
+### Swift Package Manager
+
+Add the following dependency to your `Package.swift`:
+
+```swift
+dependencies: [
+ .package(url: "https://github.com/space-code/log.git", from: "1.2.0")
+]
+```
+
+Or add it through Xcode:
-### Create a logger instance
+1. File > Add Package Dependencies
+2. Enter package URL: `https://github.com/space-code/log.git`
+3. Select version requirements
-First, you need to create an instance of `IPrinter` that prints messages to a specific output, such as XCode's console or the `Console` app.
-The `log` package provides predefined printers for printing messages in the XCode console (`ConsolePrinter`) and the system console (`OSPrinter`). You can also create your own printer. To do this, your object must conform to `IPrinterStrategy` and implement the necessary methods.
+## Quick Start
```swift
import Log
+// Create printers
+let consolePrinter = ConsolePrinter()
let osPrinter = OSPrinter()
+
+// Create logger
+let log = Logger(
+ printers: [consolePrinter, osPrinter],
+ logLevel: .all
+)
+
+// Start logging
+log.info(message: "Application started")
+log.debug(message: "Debug information")
+log.error(message: "Something went wrong")
+```
+
+## Usage
+
+### Creating a Logger
+
+Log provides two main printer implementations out of the box:
+
+```swift
+import Log
+
+// Console printer for Xcode console output
let consolePrinter = ConsolePrinter()
+
+// OS printer for system console (Console.app)
+let osPrinter = OSPrinter()
+
+// Create logger with multiple printers
+let log = Logger(
+ printers: [consolePrinter, osPrinter],
+ logLevel: .all
+)
+```
+
+### Log Levels
+
+Log supports various severity levels for organizing your messages:
+
+```swift
+import Log
+
+let log = Logger(printers: [ConsolePrinter()], logLevel: .all)
+
+// Different log levels
+log.debug(message: "Debug information")
+log.info(message: "General informational messages")
+log.error(message: "Error messages")
+log.fault(message: "Critical fault messages")
+```
+
+**Available Log Levels:**
+- `.debug` - Debug information
+- `.info` - General informational messages
+- `.error` - Error messages
+- `.fault` - Critical system faults
+- `.all` - Log all messages
+
+**Filtering by Level:**
+```swift
+// Only log errors
+let log = Logger(
+ printers: [ConsolePrinter()],
+ logLevel: .errors
+)
+
+log.debug(message: "This won't be printed")
+log.error(message: "This will be printed")
```
-Second, create a `Logger` instance and pass these printers as initialization parameters while defining a log level. The log level determines the level of log messages to print. If the log level is set to a specific level, all messages with different log levels will be ignored. To print all messages, use `.all`.
+### Printers
+
+Printers determine where your log messages are output:
+
+**ConsolePrinter** - Outputs to Xcode console:
+```swift
+let consolePrinter = ConsolePrinter(
+ formatters: [
+ PrefixLogFormatter(name: "MyApp"),
+ TimestampLogFormatter(dateFormat: "HH:mm:ss")
+ ]
+)
+```
+**OSPrinter** - Outputs to system log (viewable in Console.app):
```swift
+let osPrinter = OSPrinter(
+ formatters: [
+ PrefixLogFormatter(name: "MyApp")
+ ]
+)
+```
+
+**Using Multiple Printers:**
+```swift
+// Log to both Xcode console and system log
let log = Logger(
- printers: [osPrinter, consolePrinter],
+ printers: [
+ ConsolePrinter(formatters: [TimestampLogFormatter()]),
+ OSPrinter(formatters: [PrefixLogFormatter(name: "MyApp")])
+ ],
logLevel: .all
)
-log.error(message: "test message")
```
-### Formatting a message
+### Message Formatting
-Each instance of `IPrinter` has an array of formatters that are responsible for formatting input messages. The `log` package provides predefined prefix and timestamp formatters. To use these, you need to pass them to an initializer of a printer.
+Formatters transform your log messages before they're printed. Log includes two built-in formatters:
+| Formatter | Description |
+|-----------|-------------|
+| **PrefixLogFormatter** | Adds a specified prefix to messages |
+| **TimestampLogFormatter** | Adds a timestamp based on date format |
+
+**Using Formatters:**
```swift
-let osPrinter = OSPrinter(formatters: [PrefixFormatter(name: "your prefix here")])
-...
-log.fault(message: "message") // "🚨🚨🚨 [your prefix here] => message"
+import Log
+
+// Prefix formatter
+let prefixFormatter = PrefixLogFormatter(name: "NetworkLayer")
+let printer = ConsolePrinter(formatters: [prefixFormatter])
+
+let log = Logger(printers: [printer], logLevel: .all)
+log.info(message: "Request started")
+// Output: [NetworkLayer] => Request started
+
+// Timestamp formatter
+let timestampFormatter = TimestampLogFormatter(dateFormat: "yyyy-MM-dd HH:mm:ss")
+let printer2 = ConsolePrinter(formatters: [timestampFormatter])
+
+let log2 = Logger(printers: [printer2], logLevel: .all)
+log2.info(message: "User logged in")
+// Output: 2025-12-22 15:56:42 User logged in
+
+// Combining formatters
+let combinedPrinter = ConsolePrinter(formatters: [
+ TimestampLogFormatter(dateFormat: "HH:mm:ss"),
+ PrefixLogFormatter(name: "API")
+])
+
+let log3 = Logger(printers: [combinedPrinter], logLevel: .all)
+log3.error(message: "Connection failed")
+// Output: 💣💥💣💥 [API] => 15:56:42 Connection failed
```
-Here is a list of predefined formatters:
+### Custom Formatters
-| **Formatters** | **Description** |
-|----------------------------|-------------------------------------------------------------------------------------|
-| **PrefixLogFormatter** | Add a specified prefix to a printed message |
-| **TimestampLogFormatter** | Add a timestamp before a printed message based on a date format |
+Create custom formatters by conforming to the `ILogFormatter` protocol:
-### Custom formatters
+```swift
+import Log
-If you want to create a custom message formatter, your object must conform to the `ILogFormatter` protocol and implement the necessary methods.
+struct EnvironmentFormatter: ILogFormatter {
+ let environment: String
+
+ func format(message: String, with logLevel: LogLevel) -> String {
+ return "[\(environment.uppercased())] \(message)"
+ }
+}
+// Usage
+let formatter = EnvironmentFormatter(environment: "production")
+let printer = ConsolePrinter(formatters: [formatter])
+let log = Logger(printers: [printer], logLevel: .all)
+
+log.info(message: "Server started")
+// Output: [PRODUCTION] Server started
+```
+
+**Advanced Custom Formatter:**
```swift
-struct MyCustomMessageFormatter: ILogFormatter {
+struct ContextualFormatter: ILogFormatter {
+ let includeThread: Bool
+ let includeFile: Bool
+
func format(message: String, with logLevel: LogLevel) -> String {
- // your implementation here
+ var components: [String] = []
+
+ if includeThread {
+ components.append("[Thread: \(Thread.current.threadName)]")
+ }
+
+ if includeFile {
+ components.append("[File: \(#file)]")
+ }
+
+ components.append(message)
+ return components.joined(separator: " ")
}
}
```
-## Requirements
-- iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 7.0+ / visionOS 1.0+
-- Xcode 14.0
-- Swift 5.7
+**Custom Printer:**
+```swift
+import Log
-## Installation
-### Swift Package Manager
+final class FilePrinter: IPrinter {
+ let formatters: [ILogFormatter]
+ let fileURL: URL
+
+ init(formatters: [ILogFormatter] = [], fileURL: URL) {
+ self.formatters = formatters
+ self.fileURL = fileURL
+ }
+
+ func log(_ message: String, logLevel: Log.LogLevel) {
+ var formattedMessage = message
+
+ for formatter in formatters {
+ formattedMessage = formatter.format(
+ message: formattedMessage,
+ with: logLevel
+ )
+ }
+
+ if let data = (formattedMessage + "\n").data(using: .utf8) {
+ // Write to file
+ }
+ }
+}
+```
-The [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. It is in early development, but `log` does support its use on supported platforms.
+## Common Use Cases
-Once you have your Swift package set up, adding `log` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.
+### Application Logging
```swift
-dependencies: [
- .package(url: "https://github.com/space-code/log.git", .upToNextMajor(from: "1.2.0"))
-]
+import Log
+
+class AppDelegate: UIResponder, UIApplicationDelegate {
+ private let log = Logger(
+ printers: [
+ ConsolePrinter(formatters: [
+ TimestampLogFormatter(dateFormat: "HH:mm:ss.SSS"),
+ PrefixLogFormatter(name: "MyApp")
+ ]),
+ OSPrinter(formatters: [
+ PrefixLogFormatter(name: "MyApp")
+ ])
+ ],
+ logLevel: .all
+ )
+
+ func application(
+ _ application: UIApplication,
+ didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
+ ) -> Bool {
+ log.info(message: "Application launched")
+ setupApplication()
+ return true
+ }
+
+ private func setupApplication() {
+ log.debug(message: "Configuring application")
+ // Configuration code
+ log.info(message: "Application configured successfully")
+ }
+}
+```
+
+### Network Layer Logging
+
+```swift
+import Log
+
+class NetworkManager {
+ private let log = Logger(
+ printers: [
+ ConsolePrinter(formatters: [
+ TimestampLogFormatter(),
+ PrefixLogFormatter(name: "Network")
+ ])
+ ],
+ logLevel: .debug
+ )
+
+ func fetchData(from url: URL) async throws -> Data {
+ log.debug(message: "Requesting: \(url.absoluteString)")
+
+ do {
+ let (data, response) = try await URLSession.shared.data(from: url)
+
+ if let httpResponse = response as? HTTPURLResponse {
+ log.info(message: "Response: \(httpResponse.statusCode)")
+ }
+
+ return data
+ } catch {
+ log.error(message: "Request failed: \(error.localizedDescription)")
+ throw error
+ }
+ }
+}
+```
+
+### Database Operations
+
+```swift
+import Log
+
+class DatabaseManager {
+ private let log = Logger(
+ printers: [
+ ConsolePrinter(formatters: [
+ PrefixLogFormatter(name: "Database")
+ ])
+ ],
+ logLevel: .all
+ )
+
+ func saveRecord(_ record: Record) throws {
+ log.debug(message: "Attempting to save record: \(record.id)")
+
+ do {
+ try database.insert(record)
+ log.info(message: "Record saved successfully: \(record.id)")
+ } catch {
+ log.error(message: "Failed to save record: \(error)")
+ throw error
+ }
+ }
+
+ func deleteRecord(id: String) throws {
+ log.info(message: "Deleting record: \(id)")
+ try database.delete(id)
+ log.info(message: "Record deleted: \(id)")
+ }
+}
+```
+
+### Debug vs Production Logging
+
+```swift
+import Log
+
+class LoggerFactory {
+ static func createLogger() -> Logger {
+ #if DEBUG
+ return Logger(
+ printers: [
+ ConsolePrinter(formatters: [
+ TimestampLogFormatter(dateFormat: "HH:mm:ss.SSS"),
+ PrefixLogFormatter(name: "Debug")
+ ])
+ ],
+ logLevel: .all
+ )
+ #else
+ return Logger(
+ printers: [
+ OSPrinter(formatters: [
+ PrefixLogFormatter(name: "Production")
+ ])
+ ],
+ logLevel: .error // Only log errors in production
+ )
+ #endif
+ }
+}
+
+// Usage
+let log = LoggerFactory.createLogger()
```
## Communication
-- If you **found a bug**, open an issue.
-- If you **have a feature request**, open an issue.
-- If you **want to contribute**, submit a pull request.
+
+- 🐛 **Found a bug?** [Open an issue](https://github.com/space-code/log/issues/new)
+- 💡 **Have a feature request?** [Open an issue](https://github.com/space-code/log/issues/new)
+- ❓ **Questions?** [Start a discussion](https://github.com/space-code/log/discussions)
+- 🤝 **Want to contribute?** Submit a pull request
## Contributing
-Bootstrapping development environment
-```
+We love contributions! Please feel free to help out with this project. If you see something that could be made better or want a new feature, open up an issue or send a Pull Request.
+
+### Development Setup
+
+Bootstrap the development environment:
+
+```bash
make bootstrap
```
-Please feel free to help out with this project! If you see something that could be made better or want a new feature, open up an issue or send a Pull Request!
+For detailed contribution guidelines, see [CONTRIBUTING.md](https://github.com/space-code/log/blob/main/CONTRIBUTING.md).
## Author
-Nikita Vasilev, nv3212@gmail.com
+
+**Nikita Vasilev**
+- Email: nv3212@gmail.com
+- GitHub: [@ns-vasilev](https://github.com/ns-vasilev)
## License
-log is available under the MIT license. See the LICENSE file for more info.
+
+Log is released under the MIT license. See [LICENSE](https://github.com/space-code/log/blob/main/LICENSE) for details.
+
+---
+
+
+
+**[⬆ back to top](#log)**
+
+Made with ❤️ by [space-code](https://github.com/space-code)
+
+
\ No newline at end of file
diff --git a/Sources/Log/Classes/Core/Formatters/TimestampLogFormatter.swift b/Sources/Log/Classes/Core/Formatters/TimestampLogFormatter.swift
index d651ab8..911ff5d 100644
--- a/Sources/Log/Classes/Core/Formatters/TimestampLogFormatter.swift
+++ b/Sources/Log/Classes/Core/Formatters/TimestampLogFormatter.swift
@@ -31,7 +31,7 @@ open class TimestampLogFormatter: ILogFormatter {
/// Initializes a new `TimestampLogFormatter` with the specified date format.
///
/// - Parameter dateFormat: A string representing the desired date and time pattern.
- public init(dateFormat: String) {
+ public init(dateFormat: String = "HH:mm:ss") {
self.dateFormat = dateFormat
}
diff --git a/Sources/Log/Classes/Core/Printers/ConsolePrinter.swift b/Sources/Log/Classes/Core/Printers/ConsolePrinter.swift
index 19910f2..3732996 100644
--- a/Sources/Log/Classes/Core/Printers/ConsolePrinter.swift
+++ b/Sources/Log/Classes/Core/Printers/ConsolePrinter.swift
@@ -27,7 +27,7 @@ public final class ConsolePrinter {
/// Creates a new `ConsolePrinter` instance with a default console writer.
///
/// - Parameter formatters: An array of log formatters used to process and style the log messages.
- public init(formatters: [ILogFormatter]) {
+ public init(formatters: [ILogFormatter] = []) {
self.formatters = formatters
consoleWriter = ConsoleWriter()
}
@@ -40,7 +40,7 @@ public final class ConsolePrinter {
/// - Parameters:
/// - formatters: An array of log formatters for customizing log messages.
/// - consoleWriter: An object conforming to `IConsoleWriter` to handle message output.
- init(formatters: [ILogFormatter], consoleWriter: IConsoleWriter) {
+ init(formatters: [ILogFormatter] = [], consoleWriter: IConsoleWriter = ConsoleWriter()) {
self.formatters = formatters
self.consoleWriter = consoleWriter
}
diff --git a/Sources/Log/Classes/Core/Printers/OSPrinter.swift b/Sources/Log/Classes/Core/Printers/OSPrinter.swift
index 9e2584f..9aa5b33 100644
--- a/Sources/Log/Classes/Core/Printers/OSPrinter.swift
+++ b/Sources/Log/Classes/Core/Printers/OSPrinter.swift
@@ -34,16 +34,16 @@ public final class OSPrinter {
/// - category: A string used to further distinguish logs within a subsystem (e.g., "Database").
/// - formatters: An array of log formatters for customizing the final string output.
public init(
- subsystem: String,
- category: String,
- formatters: [ILogFormatter]
- ) {
- self.formatters = formatters
- osWriter = OSWriter(
- subsystem: subsystem,
- category: category
- )
- }
+ subsystem: String = Bundle.main.bundleIdentifier ?? "com.app.logger",
+ category: String = "General",
+ formatters: [ILogFormatter] = []
+ ) {
+ self.formatters = formatters
+ self.osWriter = OSWriter(
+ subsystem: subsystem,
+ category: category
+ )
+ }
/// Creates a new `OSPrinter` instance using a pre-configured OS writer.
///
@@ -53,10 +53,16 @@ public final class OSPrinter {
/// - Parameters:
/// - formatters: An array of log formatters for customizing log messages.
/// - osWriter: An object conforming to `IOSWriter` that performs the actual system calls.
- init(formatters: [ILogFormatter], osWriter: IOSWriter) {
- self.formatters = formatters
- self.osWriter = osWriter
- }
+ init(
+ formatters: [ILogFormatter] = [],
+ osWriter: IOSWriter = OSWriter(
+ subsystem: Bundle.main.bundleIdentifier ?? "com.app.logger",
+ category: "General"
+ )
+ ) {
+ self.formatters = formatters
+ self.osWriter = osWriter
+ }
}
// MARK: IStyleLogStrategy