• Stars
    star
    175
  • Rank 210,332 (Top 5 %)
  • Language
    Swift
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A lightweight logging framework for Swift

Kitura

APIDoc Build Status - Master codecov macOS Linux Apache 2 Slack Status

HeliumLogger

Provides a lightweight logging implementation for Swift which logs to standard output.

Features

Usage

Add dependencies

Add the HeliumLogger package to the dependencies within your application’s Package.swift file. Substitute "x.x.x" with the latest HeliumLogger release.

.package(url: "https://github.com/Kitura/HeliumLogger.git", from: "x.x.x")

Add HeliumLogger to your target's dependencies:

.target(name: "example", dependencies: ["HeliumLogger"]),

Import packages

To use with LoggerAPI:

import HeliumLogger
import LoggerAPI

To use with swift-log:

import HeliumLogger
import Logging

Initialize HeliumLogger

To use HeliumLogger as a logging backend for LoggerAPI:

let logger = HeliumLogger()
Log.logger = logger

or, if you don't need to customize HeliumLogger:

HeliumLogger.use()

To use HeliumLogger as a logging backend for swift-log:

let logger = HeliumLogger()
LoggingSystem.bootstrap(logger.makeLogHandler)

Or, as a convenience:

HeliumLogger.bootstrapSwiftLog()

Logging levels

You can specify the level of output on initialization. You will see output of that level, and all levels below that.

The order is:

  1. entry (entering a function)
  2. exit (exiting a function)
  3. debug
  4. verbose (default)
  5. info
  6. warning
  7. error

For example, this logger will show messages of type verbose, info, warning, and error:

let logger = HeliumLogger(.verbose)
Log.logger = logger

In this example, the logger will only show messages of type warning and error:

HeliumLogger.use(.warning)

Note that when HeliumLogger is used in conjunction with swift-log, the logging level is determined by the Logger, and HeliumLogger's own logging level is unused.

Adjust logging levels at runtime (LoggerAPI)

Calling HeliumLogger.use(LoggerMessageType) will set the LoggerAPI to use this new HeliumLogger instance. If in a route you detect an error with your application, you could use this to dynamically increase the log level.

This new instance will not have any customization which you applied to other instances (see list item 7).

Logging messages (LoggerAPI)

How to use HeliumLogger to log messages in your application with LoggerAPI:

Log.verbose("This is a verbose log message.")

Log.info("This is an informational log message.")

Log.warning("This is a warning.")

Log.error("This is an error.")

Log.debug("This is a debug message.")

Further customization

/// Whether, if true, or not the logger output should be colorized.
public var colored: Bool = false

/// If true, use the detailed format when a user logging format wasn't specified.
public var details: Bool = true

/// If true, use the full file path, not just the filename.
public var fullFilePath: Bool = false

/// If not nil, specifies the user specified logging format.
/// For example: "[(%date)] [(%type)] [(%file):(%line) (%func)] (%msg)"
public var format: String?

/// If not nil, specifies the format used when adding the date and the time to the logged messages.
public var dateFormat: String?

/// If not nil, specifies the timezone used in the date time format.
public var timeZone: TimeZone?

API documentation

For more information visit our API reference.

Community

We love to talk server-side Swift, and Kitura. Join our Slack to meet the team!

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.

More Repositories

1

Kitura

A Swift web framework and HTTP server.
Swift
7,614
star
2

BlueSocket

Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux.
Swift
1,392
star
3

Swift-JWT

JSON Web Tokens in Swift
Swift
539
star
4

Swift-Kuery

SQL database abstraction layer
Swift
427
star
5

Swift-SMTP

Swift SMTP client
Swift
249
star
6

Swift-Kuery-ORM

An ORM for Swift, built on Codable
Swift
211
star
7

BlueCryptor

Swift cross-platform crypto library using CommonCrypto/libcrypto
Swift
189
star
8

swift-html-entities

HTML5 spec-compliant character encoder/decoder for Swift
Swift
165
star
9

swift-ubuntu-docker

🚫 This repo is deprecated - please use the images here: https://hub.docker.com/_/swift
Vim Script
155
star
10

BlueRSA

RSA public/private key encryption, private key signing and public key verification in Swift using the Swift Package Manager. Works on iOS, macOS, and Linux (work in progress).
Swift
128
star
11

SwiftyRequest

SwiftyRequest is an HTTP networking library built for Swift.
Swift
108
star
12

Kitura-net

Kitura networking
Swift
103
star
13

BlueSSLService

SSL/TLS Add-in for BlueSocket using Secure Transport and OpenSSL
Swift
96
star
14

Kitura-redis

Swift Redis library
Swift
94
star
15

BlueECC

Elliptic-curve cryptography for Swift
Swift
92
star
16

BlueSignals

Generic Cross Platform Signal Handler
Swift
92
star
17

Kitura-Sample

A sample application that shows how to use various features of Kitura
Swift
80
star
18

Configuration

Hierarchical configuration manager for Swift applications
Swift
78
star
19

Kitura-WebSocket

WebSocket support for Kitura
Swift
66
star
20

Swift-Kuery-PostgreSQL

PostgreSQL plugin for Swift-Kuery framework
Swift
61
star
21

OpenSSL

Swift modulemaps for libSSL and libcrypto
C
58
star
22

SwiftKafka

Swift SDK for Apache Kafka
Swift
58
star
23

KituraKit

Swift client library for using Codable routes with Kitura
Swift
58
star
24

Kitura-CouchDB

CouchDB adapter for Kitura
Swift
50
star
25

CircuitBreaker

A Swift Circuit Breaker library – Improves application stability and reliability.
Swift
45
star
26

Kitura-Credentials

A pluggable framework for validating user credentials in a Swift server using Kitura
Swift
40
star
27

Kitura-NIO

A networking library for Kitura, based on SwiftNIO
Swift
37
star
28

Kitura-OpenAPI

OpenAPI support for Kitura
Swift
36
star
29

TypeDecoder

A Swift library to allow the runtime inspection of Swift language native and complex types.
Swift
35
star
30

SwiftKueryMySQL

MySQL plugin for Swift-Kuery framework
Swift
34
star
31

Package-Builder

Build and utility scripts used for continuous integration builds for Swift Package Manager projects on the Travis CI environment
Shell
33
star
32

CCurl

Modulemap for the libcurl library
Objective-C
30
star
33

Kitura-StencilTemplateEngine

Stencil templating for Kitura
Swift
26
star
34

kitura.dev

http://www.kitura.dev
JavaScript
26
star
35

LoggerAPI

Logger protocol
Swift
25
star
36

Kitura-Markdown

Templating engine for Kitura that uses Markdown based templates
C
24
star
37

Health

An application health library for Swift.
Swift
21
star
38

Kitura-Session

A pluggable framework for managing user sessions in a Swift server using Kitura
Swift
18
star
39

Kitura-WebSocket-NIO

A SwiftNIO based implementation of WebSocket for Kitura
Swift
17
star
40

CommonCrypto

CommonCrypto Module Map
Swift
17
star
41

FileKit

Swift
16
star
42

Swift-Kuery-SQLite

An SQLite plugin for the Swift-Kuery framework
Swift
16
star
43

Kitura-TemplateEngine

Kitura Template Engine protocol
Swift
15
star
44

Kitura-CredentialsHTTP

A plugin for the Kitura-Credentials framework that authenticates using HTTP Basic and Digest authentication
Swift
15
star
45

kitura-cli

⌨️ Kitura command-line interface
Go
13
star
46

KituraContracts

A library containing type definitions shared by client and server Kitura code.
Swift
12
star
47

CZlib

Module map for Zlib library
Swift
11
star
48

CloudEnvironment

Convenience Swift package for accessing environment variables, credentials.
Swift
11
star
49

Kitura-CredentialsFacebook

A plugin for the Kitura-Credentials framework that authenticates using the Facebook web login
Swift
9
star
50

Kitura-CORS

Kitura CORS middleware
Swift
9
star
51

Kitura-Cache

Kitura cache
Swift
9
star
52

Kitura-CredentialsGoogle

A plugin for the Kitura-Credentials framework that authenticates using the Google web login
Swift
8
star
53

Swift-cfenv

Easy access to Cloud Foundry application environment for Swift Packages.
Swift
8
star
54

Kitura-Compression

Kitura compression middleware
Swift
6
star
55

CEpoll

A modulemap file and include to help Swift code use epoll on Linux
Swift
5
star
56

Kitura-WebSocket-Client

A WebSocket client based on SwiftNIO
Swift
5
star
57

Kitura-CredentialsGitHub

A plugin for the Kitura-Credentials framework that authenticates using the GitHub web login
Swift
4
star
58

Kitura-MustacheTemplateEngine

Adapter of GRMustache Template Engine to Kitura Template Engine
Swift
4
star
59

CHTTPParser

Modulemap for the http-parser library
C
4
star
60

Kitura-WebSocket-Compression

A WebSocket compression library based on SwiftNIO
Swift
3
star
61

Kitura-Session-Redis

Kitura-Session store using Redis as the backing store
Swift
3
star
62

generator-swiftserver-projects

Autogenerated Kitura projects
Shell
2
star
63

Kitura-CredentialsJWT

A plugin for the Kitura-Credentials framework that supports JWT authentication.
Swift
2
star
64

homebrew-kitura

Homebrew tap
Ruby
2
star
65

Kitura-Benchmarks

Benchmarks for Kitura
Swift
2
star
66

anapistula

Simple standalone web server in swift
Swift
1
star
67

CLibpq

PostgreSQL wrapper
Swift
1
star
68

ShellToolKit

Utility classes to help with common system/shell actions in Swift
Swift
1
star