Giter Site home page Giter Site logo

ticesoftware / vapor-simple-file-logger Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hallee/vapor-simple-file-logger

0.0 1.0 0.0 10 KB

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

License: MIT License

Swift 95.89% HCL 4.11%
fork vapor reassess

vapor-simple-file-logger's Introduction

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)
}

vapor-simple-file-logger's People

Contributors

hallee avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.