Comments (7)
Great implementation so far.
I think the most Vapor way to do this would be an API like so.
Log.info("Informational log")
Log.error("something bad happened")
Where the Log
class looks something like this
class Log {
static var driver: LogDriver
static func info(message: Any) { }
...etc
}
This way the logger implementation can be easily swapped out without affecting the interface for logging.
Log.driver = MyCustomLogger()
Let me know what you think.
from vapor.
Yep - makes sense. I will refactor it tomorrow my time.
from vapor.
The logger now simply includes a LoggerDriver
protocol, a default ConsoleLogger
which implements this protocol and a Log
class with static methods for each log level.
In the Log
class you can:
- Override the default logger
- Define which levels to log by setting
[LogLevel]
to the static varenabledLevels
. - Log a
Custom
log level
For example:
Log.info("this is informational") //Only displays if enabledLevel contains .Info
Log.custom("this is a custom method", label: "MyLevel")
//Example output: [2016-02-21 23:14:36 +0000] INFO: Received GET request for /
The Log class:
public class Log {
public static var driver: Logger = ConsoleLogger()
public static var enabledLevels: [LogLevel] = LogLevel.all
public static func verbose(message: String) {
if Log.enabledLevels.contains(.Verbose) {
driver.log(.Verbose, message: message)
}
}
//other methods
Let me know...
from vapor.
This looks great. I'll test it out when I'm back on my computer.
from vapor.
Could you submit this code as a branch on qutheory/vapor
?
from vapor.
done
from vapor.
Merged in #54
from vapor.
Related Issues (20)
- commùit
- Double slash in URLs still breaks route matching with variable parts in vapor 4.92.0 HOT 2
- Trying to build on Ubuntu 20 with swift run and getting Building for debugging... error: emit-module command failed due to signal 9 HOT 2
- Unable to shutdown server HOT 1
- Title
- Vapor URLQueryContainer no longer supports valueless query parameters HOT 4
- Swift Vapor-Save records in Mysql JSON data type during mapping with swift get error- Could not convert MySQL data to String: <MYSQL_TYPE_JSON HOT 6
- Large, streamed request body may result in noSignalReceived preconditionFailure crash HOT 6
- Websocket shouldUpgrade() fail causes empty reply from server HOT 4
- Cannot setup a route returning `[Int: String]` HOT 7
- Log actual port when it's picked by the OS
- 'Flag' URL Query params don't decode into structs HOT 3
- HEAD response should allow non-zero Content-Length HOT 3
- Authentication Cache + Storage crash application HOT 2
- Default to `HTTPClient.shared` when possible HOT 1
- URLFormEncoder does not escape all reserved characters HOT 3
- Return 415 error if compressed request is detected, but not supported
- Crash after installing posix ELG as concurrency executor HOT 1
- Stored property '_id' of 'Sendable'-conforming class 'Todo' is mutable HOT 3
- [routes] does not split path parameter by '/' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vapor.