65 Commits
Author SHA1 Message Date
tomer doron e309184b89 add flush api to default stdout/stderr logger (#87)
* add flush api to default stdout/stderr logger

motivation: default logger may not flush the streams on crush, so need to make flushing moe explicit

changes:
* add a constructor argument to control flushing behaviour, default to "everytime"
* add a "flush" method to allow user defined flush timing. this api is now internal but we could expose it if there is a need
* add tests

* fixup
2019-08-13 10:59:48 +01:00
Johannes Weiss ebdfdcf0ff better documentation around MetadataValue being expressible by literals (#85)
* better documentation around MetadataValue being expressible by literals

Motivation:

In many examples, I could see that users seem to construct metadata
values using the explicit enum cases `.string("foo")`, `.array(...)`, as
well as `.dictionary(...)`. It's much more readable and easier to type
to just use `"foo"`, `["bar", "buz"]`, and `["qux": "quux"]` and rely on
the `ExpressibleBy...Literal` conformances.

Modifications:

Add the docs and examples.

Result:

Hopefully, users will read the docs and write more idiomatic code.

* Update Logging.swift
2019-08-07 11:43:28 +09:00
tomer doron 263735081c test formatting issues as part of sanity check (#84)
motivaiton: unified format

changes:
* use official docker image 🎉
* fix outstanding formatting issues
* add a call to swiftformat as part of sanity script
* fix sanity script language check debugging statements
2019-07-30 13:34:00 -07:00
Kevin Sweeney b33865f66b Fix documented ordering of Level (#78)
Levels are actually ordered from least severe to most severe, and their raw values are not exposed.
2019-06-25 22:52:56 +01:00
Max Desiatov df4d2c80df Fix typo in LogHandler doc comment (#76) 2019-06-03 10:01:42 -07:00
Allen Humphreys ea3eea9dcb Expose an API for configuring basic stdio log handling (#61)
Expose `StreamLogHandler` to the public which replaces the previously internal `StdoutLogHandlers`. Users can choose now the output stream, while `stdout` is the default.

### Motivation:

As discussed on #51 and #60

### Modifications:

Rename `StdoutLogHandler` to `StreamLogHandler` and provide 2 factory methods `standardOutput(label:)` and `standardError(label:)` for using during bootstrapping.

### Result:

Users who adopt other logging backends during `LoggingSystem` bootstrapping will still be able to use the default log handler to get very basic console output to their choice of `stdout` or `stderr`.

### Example:
```
// Log to both stderr and stdout for good measure
LoggingSystem.bootstrap { 
    MultiplexLogHandler([
        FancyLoggingBackend(label: $0),
        StreamLogHandler.standardError(label: $0), 
        StreamLogHandler.standardOutput(label: $0)
    ])
}
```
2019-05-01 16:44:16 +01:00
tsuyoshi hyuga a26395d403 changed to isEmpty. (#65) 2019-04-25 10:48:14 +01:00
Ian Partridge 0c403de592 docs: improve API documentation coverage (#67) 2019-04-25 10:47:00 +01:00
Yim Lee 9ac2ad4064 Fix API documentation (#66)
Motivation:

API doc contains misinformation.

Modifications:

Update documentation for `Logger` API to match code.

Result:

API doc is correct.
2019-04-24 22:14:10 +01:00
grundoon 250cef01ad fix docs #file -> #function (#59)
* fix docs #file -> #function

Multiple occurrences of `#file` in docs where `#function` was intended.

* add missing parentheses to parameter docs
2019-04-17 08:59:41 +01:00
tomer doron 4fe877816a fix linux tests formatting (#45)
motivation: use consistent formatting

changes: update generate_linux_tests to match the formatting rules we use: `swiftformat --self insert --patternlet inline --stripunusedargs unnamed-only --comments ignore`
2019-04-15 17:29:30 +01:00
Konrad `ktoso` Malawski 856a83e9f4 Link to more appropriate (still open) Swift issue (#50)
The original issue that was https://bugs.swift.org/browse/SR-9687 has been closed as duplicate of https://bugs.swift.org/browse/SR-9686
Perhaps it would be less confusing for others reading the code if we linked to the not-closed issue?

Not a big deal, just something I noticed; if we want to continue to link to the original issue that's fine too.
2019-04-15 11:59:33 +01:00
Konrad `ktoso` Malawski e37f28a5ff Fix typo in "critical" words in docs (#49) 2019-04-15 11:19:09 +01:00
David Okun a4828d9184 Added CaseIterable to Logger.Level enum (#46)
* Added CaseIterable to Logger.Level enum
2019-04-12 14:49:25 +01:00
tomer doron 9a393a5d35 retain SwiftNIO copyright header (#44)
motivation: retain copyrights

changes:
* add notice file with references to derived work
* add swift-nio license header to lock
2019-04-11 14:12:41 +01:00
tomer doron 23f0f6ee6e fix typo in API docs (#42)
motivation: better docs

changes: swidft-log -> SwiftLog in an API doc that got it wrong
2019-04-10 18:02:11 +01:00
tomer doron f6a420460d use consistent, swifty naming convention (#41)
motivation: prepare to release

changes: refer to package as SwiftLog across the board isntead of swift-log
2019-04-10 17:45:54 +01:00
Johannes Weiss ca922e38f5 remove Logger.metadata property (#36)
Motivation:

Logger had two ways to access the metadata:

    logger[metadataKey: "foo"] = "bar"

and

    logger.metadata["foo"] = "bar"

. The first one is the preferred API (as it doesn't force the
`LogHandler`s to store it in a dictionary) but the second one was still
available for cases where you need to import/export the whole metadata
storage.

Instead of exposing this as a dictionary, we should make the
'whole-metadata import/export' opaque. We're close to tagging 1.0.0
however let's design this API properly and add a sensible implementation
for 1.1.0 or so.

Moditications:

remove `Logger.metadata` property

Result:

- We can design the import/export APIs and add them when they're ready.
- the `LogHandler` API is unchanged
2019-04-08 20:28:10 +01:00
Johannes Weiss 09c2837476 change log levels to be more natural (#35)
Motivation:

The syslog log level was unnatural in order (`.error` < `.info`) but also
didn't have `.trace` and instead the odd `.emergency` and `.alert`.

Modification:

As per https://forums.swift.org/t/logging-levels-for-swifts-server-side-logging-apis-and-new-os-log-apis/20365/56 ,
we decided to go for

    trace < debug < info < notice < warning < error < critical

and also remove the integrals completely. The levels remain comparable
though.

Result:

log levels more natural
2019-04-05 18:42:39 +01:00
Johannes Weiss e60caa9502 improve the LogHandler documentation (#17)
Motivation:

Correct `LogHandler` implementation is very imprortant for a working
swift-log ecosystem. Treating the `logLevel` as a value has lead to
confusion in the discussion leading to this project though.

Modification:

- add documentation on the implementation of a `LogHandler`
- move `LogHandler` to its own file
- add a unit test showcasing a global log level override

Result:

better docs
2019-03-20 15:24:34 +00:00
Kirill Titov 4c01a824b7 Formatting, readability (#15) 2019-03-19 12:24:17 +00:00
Abdullah Selek bee6142a07 Fix for spaces and new line end of file. (#16) 2019-03-19 11:49:20 +00:00
Johannes Weiss f0a5088707 make MultiplexLogHandler a value (#12) 2019-03-18 18:05:52 +00:00
Johannes Weiss 766ff20cc8 explicitly mark functions on internal types as internal (for jazzy) (#11) 2019-03-18 17:41:13 +00:00
Johannes Weiss 98886523fb first cut at API docs (#8) 2019-03-15 18:26:22 +00:00
Johannes Weiss 284bf1fdeb switch #file/#function to String (#4)
Motivation:

With the new, awesome Swift 5 `String`s, there doesn't seem to be any
point in using `StaticString`s anymore. `String` seems to use immortal
strings for literals now and is in fact 1 byte less wide than
StaticString.

Modification:

Switch all StaticString for String

Result:

better asm (slightly shorter), fewer registers burnt, more features
2019-03-14 11:32:08 +00:00
Johannes Weiss 1039ca5db2 StdoutHandler: add colon after log level (#5) 2019-03-14 11:31:56 +00:00
Johannes Weiss 7dd7738627 allow string interpolations in log messages 2019-03-01 10:59:17 +00:00
Johannes Weiss 306f432f6c convert to struct Logger.Message from String 2019-02-26 11:19:58 +00:00
Johannes Weiss c693fb6db1 switch to syslog log levels 2019-02-26 09:57:44 +00:00
Johannes Weiss 6254844827 remove examples, add code of conduct, Swift 5 2019-02-26 09:06:55 +00:00
Johannes Weiss 7db09d7d68 add license information (#48) 2019-02-24 13:51:38 +00:00
tomer doron c7583429a6 enforce that logging system can only be bootstrapped once (#32)
motivation: safer logging system

changes: do a precondition check to verify logging syste is only initialized/bootstrapped once per process
2019-02-22 18:13:52 +00:00
tomer doron 045ba36718 remove error argument from logging API (#34)
motivation: since Error in swift does not carry any additional information (such as stack traces) that can be useful in formatting decision the LogHandler may need to do, there is no real reason to treat it as special in the API, and it can just be "strigified" at the calling site

changes: remove error params from all APIs
2019-02-22 18:02:14 +00:00
Thomas Krajacic 9bd90f06ba Add label to Logger (#50) 2019-02-22 14:43:11 +00:00
Johannes Weiss 45c6d10678 rename Logging to LoggingSystem (#49) 2019-02-22 13:38:22 +00:00
tomer doron aa3990dfa0 support custom logging factories (#33)
motivation: make the API flexible enough so that users that need to inject custom factories as an escape hatch can do that

changes: add a Logging::make API variant that takes a custom factory instead of the default one
2019-02-22 13:28:41 +00:00
Konrad `ktoso` Malawski b0e59933ac Allow carrying CustomStringConvertible in metadata #24 (#25)
This has numerous benefits, most of which center around values which may
have expensive to perform custom `description` implementations, e.g.
yet are neither a dictionary nor an array.

It also allows carrying and thus "delaying" rendering of string
representations until they are actually needed. E.g. one can imagine
wanting to avoid rendering a string representation of a value if a
logger never would log any of the metadata, esp. if the rendering is a
heavy process.
2019-02-19 12:17:42 +00:00
Thomas Krajacic 5c135cd948 Add O_APPEND to flags (#45) 2019-02-19 11:44:24 +00:00
Johannes Weiss 32e9fa5158 make log function public (#44) 2019-02-19 11:43:51 +00:00
Thomas Krajacic 1b17eac10e Add newline to String being written (#47) 2019-02-19 11:01:59 +00:00
David Hart 2474d61a80 Multiple proposal improvements to the API (#41)
* Move `Logging.make` to a `Logger` initializer.
* Remove all factory initializers in example and test code.
2019-02-18 20:27:59 +01:00
Tanner 03174f3260 string interpolation fix (#42) 2019-02-12 17:16:54 +01:00
Konrad `ktoso` Malawski ed51baef90 Align names of Multiplexing loggers #37 (#38) 2019-01-29 09:53:13 +00:00
Max Moiseev 91f6b1017c MultiplexLogging.make(label:) => make(_:) (#36) 2019-01-29 09:52:16 +00:00
Ian Partridge 66bd922254 Improve timestamp calculation (#35) 2019-01-21 15:41:33 +00:00
tomer doron 466a7ed384 fix compilation on 4.2 (#31)
motivation: recent change for 5.x broken 4.x

changes: add code branch for swift < 5
2019-01-17 21:38:53 +00:00
tomer doron 11ea26a505 improve global logging example (#30)
motivation: better example

changes: the exmaple is single threaded, but better to show how to properly use global loggers (although we discourage them)
2019-01-17 18:38:23 +00:00
tomer doron 1d983153b4 change example loggers to structs (#29)
motivation: encourage use of immutable loggers

changes: change example loggers to structs
2019-01-17 18:10:54 +00:00
Konrad `ktoso` Malawski 0bf0588b17 Avoids regression SR-9687 in Swift 5 by not applying extensions to type aliased type (#27) 2019-01-17 11:31:07 +00:00