An easy to use HTTP request logger for Vapor: Web framework for swift
Swift
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Sources
.gitignore
LICENSE.txt
Package.swift
README.md

README.md

Heimdall

An easy to use HTTP request logger for Vapor: Web framework for swift.

Read a brief explanation about Heimdall's source code here.

πŸ“š Documentation

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.

πŸ““ How to Use

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.

Don't forget to add middleware in Config/droplet.json.

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.

πŸ“’ Supported Formats

πŸ”Ή 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

πŸ”§ Compatibility

This has been successfully tested on macOS and Ubuntu

πŸ“ License

MIT

πŸ‘€ Mentor

This project was suggested by and completed under the mentorship of Santosh Rajan

πŸ‘₯ Contributors

Himani Agrawal

Ankit Goel