Commit Graph
55 Commits
Author SHA1 Message Date
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
Konrad `ktoso` Malawski d370d101be fix a few typos in comments (#28) 2019-01-17 11:07:19 +00:00
Johannes Weiss ba9eac9055 fixed small errors/typos etc 2019-01-14 12:36:08 +00:00
Johannes Weiss dfffdaa429 remove Metadata.Value.lazy (#18)
Motivation:

Two reasons for the removal:

1. I don't see a compelling reason to add lazy metadata to the metadata
   storage. Lazy metadata makes sense if it's passed directly to a log
   method like

       logger.info("foo", metadata: somethingExpensive())

   but I don't think this makes a whole lot of sense

       logger[metadataKey: "foo"] = .lazy({ somethingExpensive() })

   why? It's very likely that it'll get evalutated because any next
   log message that gets logged will force it but it's totally
   unclear which one that'll be.

2. More importantly, the lazy metadata can't be implemented correctly
   because we can't memoize the result of the expensive computation
   because we can only mutate the `LogHandler` in mutating methods and
   the log methods aren't mutating.
2019-01-09 15:47:09 +00:00
tomer doron a0c3ceabdf add support for local metadata (#16)
motivation: allow users to define metadata at the log API call site

changes: add metadata param to all log APIs, and implement merge at our example implementations
2019-01-09 12:04:59 +00:00
tomer doron 5ca706eb48 make logger metadata non-optional (#15)
motivation: simpler / cleaner API

changes: change logger Metadata API to be non-nullable, since the original motivation is no longer valid
2019-01-08 21:11:12 +00:00
tomer doron 19d987b6d5 add logger API variants that take an error (#12)
motivation: easily log errors w/o converting them to string first

changes:
* add another set of logger APIs that take in an error object
* add tests and refactor testing assertions
* add autoclosure tests to make sure its resoved on when log level is appropriate
2019-01-08 20:41:03 +00:00
Johannes Weiss c7ac24db1f nest types & allow nested metadata 2019-01-08 18:13:52 +00:00
tomer doron 9027df5f03 refactor examples and remove dependecy on foundation
motivation:
* due to the low level nature of the library we prefer not to force-load foundation
* help reviewers diffrentiate between examples of usage vs implementation, and add more realistic usage and implementations examples

changes:
* remove foundation from Logging module, replace with c based locks and time functions
* rewrite usage examples to be more realistic
* add example of an implementation that writes to files
* add example of an implementation that is config driven
* rename warn -> warning
2019-01-05 02:03:44 -08:00
tomer doron 132af4ff5a add multiplex logger
motivation: support situations when users want to multiplex to multiple logging implementations

changes:
* add MultiplexLogging (factory) and MUXLogHandler (implementation), allowing user to plug in multiple logging implementations
* add tests and examples to demonstrate the functionality
2019-01-02 14:58:37 -08:00
Johannes Weiss 50a8c8fdac use the term "metadata" 2018-12-12 17:43:59 +00:00