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)
- Adding vapor as a dependency breaks documentation building HOT 3
- Incorrect Content-Length header for HEAD requests HOT 2
- If Unix domain socket file exists then Vapor crashes when starting instead of taking over the socket file HOT 1
- Namespace collision with third party library HOT 6
- Object 0x7f5ed8607740 deallocated with retain count 2, reference may have escaped from deinit. HOT 5
- Streaming request crash
- Always get this error: HTTPClientError.getConnectionFromPoolTimeout HOT 4
- Crashes during unit test execution HOT 8
- Make `XCTHTTPRequest` initializer public HOT 2
- Proposal on Soft Delete. HOT 9
- Install database extensions via Migrations HOT 2
- Websocket Error Propagation & Handling
- Privacy Manifest HOT 3
- Linker Error while using Vapor inside XCode Project HOT 6
- Vapor migrations do not finish running on fly.io HOT 8
- Documentation for cache HOT 5
- Unable to test vapor using .xcodeproj project HOT 8
- Response compression handler not added for HTTP2 requests
- Updating HTTP server configuration on the fly (ie. TLS settings) HOT 3
- Double encoded post requests after recent update (4.89.3 → 4.91.1) 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.