An easy to use HTTP request logger for Vapor: Web framework for swift.
Read a brief explanation about Heimdall's source code here.
Heimdall writes the logs to a tab separated file which can easily be opened in spread sheet software. By default, it logs all requests in combined
format to ~/
path (user's home directory). The log file is named as Heimdall_YYYY-MM-DD.txt
Log format can be chosen from Supported Formats
Requests can be logged in a custom file given the file path exists.
Add the following line to your Package.swift file:
.Package(url: "https://github.com/himani93/heimdall.git", majorVersion: 1)
In App/Config+Setup.swift import Heimdall
and append
HeimdallProvider to list of avaiable providers.
import Heimdall
private func setupProviders() throws {
try addProvider(Heimdall.Provider.self)
}
This default initialization uses combined
as logging format and logs are saved to path ~/
i.e. the user's home directory.
To use a different logging format read below.
In the Config/droplet.json file, add "heimdall" to the appropriate middleware array.
{
...
"middleware": [
"heimdall", // Add heimdall as the first middleware
...
],
...
}
Note: Add heimdall as the first middleware so it correctly measures request response times.
🚩 Heimdall Provider can be initialized in following ways
private func setupProviders() throws {
try addProvider(Heimdall.Provider(format: .tiny))
}
Uses tiny
as logging format and logs are saved to default logging path ~/
(User's home directory).
private func setupProviders() throws {
try addProvider(Heimdall.Provider(path: "/Users/blob/Desktop/Logs/"))
}
Uses default logging format combined
and logged are saved at /Users/blob/Desktop/Logs/
path. Please make sure that the path provided for the file exists.
private func setupProviders() throws {
try addProvider(Heimdall.Provider(format: .tiny, path: "/Users/blob/Desktop/Logs/"))
}
Uses tiny
as logging format and /Users/blob/Desktop/Logs/
as log path. Please make sure that the path provided for the file exists.
🚩 Heimdall Provider can also be initialized using a config file
import Heimdall
private func setupProviders() throws {
try addProvider(Heimdall.Provider.self)
}
format
and path
location can be set in configuration file at Config/heimdall.json
.
Here's an example:
{
"format": "tiny",
"path": "/Users/blob/Desktop/Logs/"
}
If you specify only one parameter in config file other will be set to default.
🔹 complete
Complete log output
remote address | - | remote user | date(clf format) | response time ms | "method url HTTP/http-version" | status | res[content-length] | "referrer" | "user-agent" |
🔹 combined
Standard Apache combined log output
remote address | - | remote user | date(clf format) | "method url HTTP/http-version" | status | res[content-length] | "referrer" | "user-agent" |
🔹 common
Standard Apache common log output
remote address | - | remote user | date(clf format) | "method url HTTP/http-version" | status | res[content-length] |
🔹 dev
method | url | status | response time ms | - | res[content-length] |
🔹 short
remote address | remote user | method | url | HTTP/http-version | status | res[content-length] | - | response time ms |
🔹 tiny
method | url | status | res[content-length] | - | response time ms |
This has been successfully tested on macOS and Ubuntu
This project was suggested by and completed under the mentorship of Santosh Rajan