Skip to content

πŸ“ A Swift Vapor provider for simple file logging on Vapor sites

License

Notifications You must be signed in to change notification settings

TICESoftware/vapor-simple-file-logger

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Simple File Logger Logo

Vapor 3 Swift 4.1 MIT License

Overview

A simple Vapor 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:

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:

services.register(SimpleFileLogger.self)
config.prefer(SimpleFileLogger.self, for: Logger.self)

To define an executable name and include timestamps, you can provide configuration:

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:

Container.make(Logger.self)

For example, to log all the requests to your server:

router.get(PathComponent.catchall) { req in
    let logger = try? req.sharedContainer.make(Logger.self)
    logger?.debug(req.description)
}

About

πŸ“ A Swift Vapor provider for simple file logging on Vapor sites

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 95.9%
  • HCL 4.1%