Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hallee/vapor-simple-file-logger
📝 A Swift Vapor provider for simple file logging on Vapor sites
https://github.com/hallee/vapor-simple-file-logger
file logger logging server-side-swift swift vapor vapor-provider vapor-service
Last synced: 29 days ago
JSON representation
📝 A Swift Vapor provider for simple file logging on Vapor sites
- Host: GitHub
- URL: https://github.com/hallee/vapor-simple-file-logger
- Owner: hallee
- License: mit
- Created: 2018-09-08T16:18:18.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-28T18:45:09.000Z (over 4 years ago)
- Last Synced: 2024-10-30T17:16:37.312Z (about 2 months ago)
- Topics: file, logger, logging, server-side-swift, swift, vapor, vapor-provider, vapor-service
- Language: Swift
- Homepage:
- Size: 9.77 KB
- Stars: 18
- Watchers: 3
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Overview
A simple [Vapor](https://vapor.codes) `Logger` provider for outputting server logs to log files.
Simple File Logger outputs separate files based on the log's `LogLevel`. Debug logs are output to `debug.log`, error logs to `error.log`, and so on. By default, logs are output to:
| Linux | macOS |
| ----- | ----- |
| `/var/log/Vapor/` | `~/Library/Caches/Vapor/` |You can change `Vapor/` to an arbitrary directory by changing the `executableName` during setup.
## Installation
Add this dependency to your `Package.swift`:
```swift
dependencies: [
.package(url: "https://github.com/hallee/vapor-simple-file-logger.git", from: "1.0.1"),
],
```And add `"SimpleFileLogger"` as a dependency to your app's target.
## Setup
In `configure.swift`:
```swift
services.register(SimpleFileLogger.self)
config.prefer(SimpleFileLogger.self, for: Logger.self)
```To define an executable name and include timestamps, you can provide configuration:
```swift
services.register(Logger.self) { container -> SimpleFileLogger in
return SimpleFileLogger(executableName: "hal.codes",
includeTimestamps: true)
}
config.prefer(SimpleFileLogger.self, for: Logger.self)
```## Usage
You can create a logger anywhere in your Vapor application with access to its `Container` with:
```swift
Container.make(Logger.self)
```For example, to log all the requests to your server:
```swift
router.get(PathComponent.catchall) { req in
let logger = try? req.sharedContainer.make(Logger.self)
logger?.debug(req.description)
}
```