Code Monkey home page Code Monkey logo

heliumlogger's Introduction

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.

heliumlogger's People

Contributors

andrew-lees11 avatar bdhernand avatar carlbrown avatar dannys42 avatar dfirsht avatar djones6 avatar helenmasters avatar ianpartridge avatar kweinmeister avatar kyemaloy97 avatar mamabusi avatar mbarnach avatar na-gupta avatar naithar avatar nikitasullivan avatar quanvo87 avatar rfdickerson avatar rob-deans avatar rolivieri avatar shihabmehboob avatar shmuelk avatar swiftdevops avatar tkhuran avatar vadimeisenbergibm avatar wlisac avatar youming-lin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heliumlogger's Issues

how to use your module in project?

Hello developers. i realy can't found tutorials how to use (import in to project in xcode for example)your module or other modules from IBM Package Manager. i try to use founded here https://swiftpkgs.ng.bluemix.net/package/IBM-Swift/HeliumLogger in IBM Sandbox, but there only errors && crush :(. for example this link taken from IBM sandbox
https://swiftlang.ng.bluemix.net/#/repl?gitPackage=https:%2F%2Fgithub.com%2FIBM-Swift%2FHeliumLogger-Sample&swiftVersion=latest

Thanx for reply

README does not describe how to set LOG_LEVEL when using with Swift-log

I am using the HeliumStreamLogger with Swift-log Logging. I followed the README and used LoggingSystem.bootstrap(myStreamlogger.makeLogHandler).
The LogHandler created from the above has a hard-coded .info level and it took me a long time to work out how to change it. Maybe there are easier ways, but the following code works and I think it should be included in the README.

var handler = myStreamLogger.makeHandler(label: "StreamLogger")
handler.logLevel = .debug
LoggingSystem.bootstrap({ name in {return handler})

PackageDescription API v3 deprecation warning

Compilation results in a warning from the compiler:

warning: PackageDescription API v3 is deprecated and will be removed in the future;

Swift Version: 4.1
Platform: macOS 10.14 Mojave
HeliumLogger Version: 1.7.1

Error when building on Ubuntu 16.10 with Swift 3.0.2

Hi,
I tried to compile a simple hello world program using HeliumLogger and the swift compiler failed to compile due to an error with HeliumLogger.

Cheers,
Joe

.Package(url: "https://github.com/IBM-Swift/HeliumLogger.git", majorVersion: 1, minor: 6)

Here is the output:

Compile Swift Module 'SSLService' (1 sources)
Compile Swift Module 'HeliumLogger' (2 sources)
/home/user/hello-api/.build/checkouts/HeliumLogger.git-7972212279880105712/Sources/HeliumLogger/HeliumLogger.swift:116:39: error: use of undeclared type 'RegularExpression'
typealias RegularExpressionType = RegularExpression

^~~~~~~~~~~~~~~~~
/home/user/hello-api/.build/checkouts/HeliumLogger.git-7972212279880105712/Sources/HeliumLogger/HeliumLogger.swift:121:24: error: could not infer type for 'tokenRegex'
private static var tokenRegex: RegularExpressionType? = {

^
/home/user/hello-api/.build/checkouts/HeliumLogger.git-7972212279880105712/Sources/HeliumLogger/HeliumLogger.swift:116:39: error: use of undeclared type 'RegularExpression'
typealias RegularExpressionType = RegularExpression

^~~~~~~~~~~~~~~~~

JSON output

It would be great to support JSON formatted output, compatible with e.g. ElasticSearch / Kibana.

Set log file path

How can I add logging settings like setting log file path limiting the size of log file path similar to winston logger for nodejs.

Ability to optionally turn off code coloring

Running the HeliumLogger sample in the Sandbox yields the output below. It would be nice if there is a programmatic way to turn off the code coloring, so that it looks more presentable.

�[0;39m VERBOSE: HeliumLogger_Sample main.swift line 23 - This is a verbose log message. �[0;39m
�[0;39m INFO: HeliumLogger_Sample main.swift line 25 - This is an informational log message. �[0;39m
�[0;33m WARNING: HeliumLogger_Sample main.swift line 27 - This is a warning. �[0;39m
�[0;31m ERROR: HeliumLogger_Sample main.swift line 29 - This is an error. �[0;39m
�[0;39m DEBUG: HeliumLogger_Sample main.swift line 31 - This is a debug message. �[0;39m
�[0;39m INFO: no func main.swift line 34 - This a dynamic message �[0;39m

Set log file path

How can I add logging settings like setting log file path limiting the size of log file path similar to winston logger for nodejs?

Document log output (in readme)

not sure if i missed it, but i had to read through the code to find out where HeliumLogger logs to.

it is very nice that this is just a lightweight logger to stdout. would be great if it could be stated in the readme.

import LoggerAPI is required too

The usage example:

import HeliumLogger
Log.logger = HeliumLogger()
Log.verbose("This is a log message.")

doesn't actually compile.

import LoggerAPI

is required too. Can we remove the requirement to import LoggerAPI?

feature: log swift queue name

In an app using multiple dispatch queues it may be worth logging current queue with every message.

Would you be willing to accept a PR if I consider adding this support? I am using HeliumLogger in multiple server side swift projects and would be willing to open a PR.

thanks for great and simple component...

fail to staging swift application with latest 1.7.0 version

When running with the swift application https://github.com/IBM-Bluemix/Kitura-Starter, it is fine with HeliumLogger 1.6.x version.

But if I use majorVersion directly,
.Package(url: "https://github.com/IBM-Swift/HeliumLogger.git" , majorVersion: 1), then staging failed.

   Cloning https://github.com/IBM-Swift/HeliumLogger.git
   HEAD is now at 9b310ce IBM-Swift/Kitura#1047 Swift 3.1 changes

swift-build: error: The dependency graph could not be satisfied (https://github.com/IBM-Swift/LoggerAPI.git)
Failed to compile droplet
Exit status 223
Staging failed: Exited with status 223
Destroying container
Resolved version: 1.7.0
Successfully destroyed container

Dependencies

Quick info, LoggerAPI latest release is 5, I noticed you still force here for .4 version

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.