GithubHelp home page GithubHelp logo

davewoodcom / xcglogger Goto Github PK

View Code? Open in Web Editor NEW
3.9K 102.0 474.0 1.83 MB

A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.

License: MIT License

Ruby 1.15% Swift 98.15% Objective-C 0.71%
logging logging-library ios tvos macos watchos swift swift-library swift-framework debug

xcglogger's Introduction

XCGLogger

badge-language badge-platforms badge-license

badge-swiftpm badge-cocoapods badge-carthage

badge-mastodon badge-twitter

badge-sponsors badge-patreon

tl;dr

XCGLogger is the original debug log module for use in Swift projects.

Swift does not include a C preprocessor so developers are unable to use the debug log #define macros they would use in Objective-C. This means our traditional way of generating nice debug logs no longer works. Resorting to just plain old print calls means you lose a lot of helpful information, or requires you to type a lot more code.

XCGLogger allows you to log details to the console (and optionally a file, or other custom destinations), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.

Go from this:

Simple message

to this:

2014-06-09 06:44:43.600 [Debug] [AppDelegate.swift:40] application(_:didFinishLaunchingWithOptions:): Simple message

Example

Example

Communication (Hat Tip AlamoFire)

  • If you need help, use Stack Overflow (Tag 'xcglogger').
  • If you'd like to ask a general question, use Stack Overflow.
  • If you've found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.
  • If you use XCGLogger, please Star the project on GitHub

Installation

Git Submodule

Execute:

git submodule add https://github.com/DaveWoodCom/XCGLogger.git

in your repository folder.

Add the following line to your Cartfile.

github "DaveWoodCom/XCGLogger" ~> 7.1.1

Then run carthage update --no-use-binaries or just carthage update. For details of the installation and usage of Carthage, visit its project page.

Developers running 5.0 and above in Swift will need to add $(SRCROOT)/Carthage/Build/iOS/ObjcExceptionBridging.framework to their Input Files in the Copy Carthage Frameworks Build Phase.

Add something similar to the following lines to your Podfile. You may need to adjust based on your platform, version/branch etc.

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '15.0'
use_frameworks!

pod 'XCGLogger', '~> 7.1.1'

Specifying the pod XCGLogger on its own will include the core framework. We're starting to add subspecs to allow you to include optional components as well:

pod 'XCGLogger/UserInfoHelpers', '~> 7.1.1': Include some experimental code to help deal with using UserInfo dictionaries to tag log messages.

Then run pod install. For details of the installation and usage of CocoaPods, visit its official web site.

Note: Before CocoaPods 1.4.0 it was not possible to use multiple pods with a mixture of Swift versions. You may need to ensure each pod is configured for the correct Swift version (check the targets in the pod project of your workspace). If you manually adjust the Swift version for a project, it'll reset the next time you run pod install. You can add a post_install hook into your podfile to automate setting the correct Swift versions. This is largely untested, and I'm not sure it's a good solution, but it seems to work:

post_install do |installer|
    installer.pods_project.targets.each do |target|
        if ['SomeTarget-iOS', 'SomeTarget-watchOS'].include? "#{target}"
            print "Setting #{target}'s SWIFT_VERSION to 4.2\n"
            target.build_configurations.each do |config|
                config.build_settings['SWIFT_VERSION'] = '4.2'
            end
        else
            print "Setting #{target}'s SWIFT_VERSION to Undefined (Xcode will automatically resolve)\n"
            target.build_configurations.each do |config|
                config.build_settings.delete('SWIFT_VERSION')
            end
        end
    end

    print "Setting the default SWIFT_VERSION to 3.2\n"
    installer.pods_project.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '3.2'
    end
end

You can adjust that to suit your needs of course.

Add the following entry to your package's dependencies:

.Package(url: "https://github.com/DaveWoodCom/XCGLogger.git", majorVersion: 7)

Backwards Compatibility

Use:

  • XCGLogger version 7.1.1 for Swift 5.0
  • XCGLogger version 6.1.0 for Swift 4.2
  • XCGLogger version 6.0.4 for Swift 4.1
  • XCGLogger version 6.0.2 for Swift 4.0
  • XCGLogger version 5.0.5 for Swift 3.0-3.2
  • XCGLogger version 3.6.0 for Swift 2.3
  • XCGLogger version 3.5.3 for Swift 2.2
  • XCGLogger version 3.2 for Swift 2.0-2.1
  • XCGLogger version 2.x for Swift 1.2
  • XCGLogger version 1.x for Swift 1.1 and below.

Basic Usage (Quick Start)

This quick start method is intended just to get you up and running with the logger. You should however use the advanced usage below to get the most out of this library.

Add the XCGLogger project as a subproject to your project, and add the appropriate library as a dependency of your target(s). Under the General tab of your target, add XCGLogger.framework and ObjcExceptionBridging.framework to the Embedded Binaries section.

Then, in each source file:

import XCGLogger

In your AppDelegate (or other global file), declare a global constant to the default XCGLogger instance.

let log = XCGLogger.default

In the

application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? = nil) // iOS, tvOS

or

applicationDidFinishLaunching(_ notification: Notification) // macOS

function, configure the options you need:

log.setup(level: .debug, showThreadName: true, showLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: "path/to/file", fileLevel: .debug)

The value for writeToFile: can be a String or URL. If the file already exists, it will be cleared before we use it. Omit the parameter or set it to nil to log to the console only. You can optionally set a different log level for the file output using the fileLevel: parameter. Set it to nil or omit it to use the same log level as the console.

Then, whenever you'd like to log something, use one of the convenience methods:

log.verbose("A verbose message, usually useful when working on a specific problem")
log.debug("A debug message")
log.info("An info message, probably useful to power users looking in console.app")
log.notice("A notice message")
log.warning("A warning message, may indicate a possible error")
log.error("An error occurred, but it's recoverable, just info about what happened")
log.severe("A severe error occurred, we are likely about to crash now")
log.alert("An alert error occurred, a log destination could be made to email someone")
log.emergency("An emergency error occurred, a log destination could be made to text someone")

The different methods set the log level of the message. XCGLogger will only print messages with a log level that is greater to or equal to its current log level setting. So a logger with a level of .error will only output log messages with a level of .error, .severe, .alert, or .emergency.

Advanced Usage (Recommended)

XCGLogger aims to be simple to use and get you up and running quickly with as few as 2 lines of code above. But it allows for much greater control and flexibility.

A logger can be configured to deliver log messages to a variety of destinations. Using the basic setup above, the logger will output log messages to the standard Xcode debug console, and optionally a file if a path is provided. It's quite likely you'll want to send logs to more interesting places, such as the Apple System Console, a database, third party server, or another application such as NSLogger. This is accomplished by adding the destination to the logger.

Here's an example of configuring the logger to output to the Apple System Log as well as a file.

// Create a logger object with no destinations
let log = XCGLogger(identifier: "advancedLogger", includeDefaultDestinations: false)

// Create a destination for the system console log (via NSLog)
let systemDestination = AppleSystemLogDestination(identifier: "advancedLogger.systemDestination")

// Optionally set some configuration options
systemDestination.outputLevel = .debug
systemDestination.showLogIdentifier = false
systemDestination.showFunctionName = true
systemDestination.showThreadName = true
systemDestination.showLevel = true
systemDestination.showFileName = true
systemDestination.showLineNumber = true
systemDestination.showDate = true

// Add the destination to the logger
log.add(destination: systemDestination)

// Create a file log destination
let fileDestination = FileDestination(writeToFile: "/path/to/file", identifier: "advancedLogger.fileDestination")

// Optionally set some configuration options
fileDestination.outputLevel = .debug
fileDestination.showLogIdentifier = false
fileDestination.showFunctionName = true
fileDestination.showThreadName = true
fileDestination.showLevel = true
fileDestination.showFileName = true
fileDestination.showLineNumber = true
fileDestination.showDate = true

// Process this destination in the background
fileDestination.logQueue = XCGLogger.logQueue

// Add the destination to the logger
log.add(destination: fileDestination)

// Add basic app info, version info etc, to the start of the logs
log.logAppDetails()

You can configure each log destination with different options depending on your needs.

Another common usage pattern is to have multiple loggers, perhaps one for UI issues, one for networking, and another for data issues.

Each log destination can have its own log level. As a convenience, you can set the log level on the log object itself and it will pass that level to each destination. Then set the destinations that need to be different.

Note: A destination object can only be added to one logger object, adding it to a second will remove it from the first.

Initialization Using A Closure

Alternatively you can use a closure to initialize your global variable, so that all initialization is done in one place

let log: XCGLogger = {
    let log = XCGLogger(identifier: "advancedLogger", includeDefaultDestinations: false)

	// Customize as needed
    
    return log
}()

Note: This creates the log object lazily, which means it's not created until it's actually needed. This delays the initial output of the app information details. Because of this, I recommend forcing the log object to be created at app launch by adding the line let _ = log at the top of your didFinishLaunching method if you don't already log something on app launch.

Log Anything

You can log strings:

log.debug("Hi there!")

or pretty much anything you want:

log.debug(true)
log.debug(CGPoint(x: 1.1, y: 2.2))
log.debug(MyEnum.Option)
log.debug((4, 2))
log.debug(["Device": "iPhone", "Version": 7])

Filtering Log Messages

New to XCGLogger 4, you can now create filters to apply to your logger (or to specific destinations). Create and configure your filters (examples below), and then add them to the logger or destination objects by setting the optional filters property to an array containing the filters. Filters are applied in the order they exist in the array. During processing, each filter is asked if the log message should be excluded from the log. If any filter excludes the log message, it's excluded. Filters have no way to reverse the exclusion of another filter.

If a destination's filters property is nil, the log's filters property is used instead. To have one destination log everything, while having all other destinations filter something, add the filters to the log object and set the one destination's filters property to an empty array [].

Note: Unlike destinations, you can add the same filter object to multiple loggers and/or multiple destinations.

Filter by Filename

To exclude all log messages from a specific file, create an exclusion filter like so:

log.filters = [FileNameFilter(excludeFrom: ["AppDelegate.swift"], excludePathWhenMatching: true)]

excludeFrom: takes an Array<String> or Set<String> so you can specify multiple files at the same time.

excludePathWhenMatching: defaults to true so you can omit it unless you want to match path's as well.

To include log messages only for a specific set to files, create the filter using the includeFrom: initializer. It's also possible to just toggle the inverse property to flip the exclusion filter to an inclusion filter.

Filter by Tag

In order to filter log messages by tag, you must of course be able to set a tag on the log messages. Each log message can now have additional, user defined data attached to them, to be used by filters (and/or formatters etc). This is handled with a userInfo: Dictionary<String, Any> object. The dictionary key should be a namespaced string to avoid collisions with future additions. Official keys will begin with com.cerebralgardens.xcglogger. The tag key can be accessed by XCGLogger.Constants.userInfoKeyTags. You definitely don't want to be typing that, so feel free to create a global shortcut: let tags = XCGLogger.Constants.userInfoKeyTags. Now you can easily tag your logs:

let sensitiveTag = "Sensitive"
log.debug("A tagged log message", userInfo: [tags: sensitiveTag])

The value for tags can be an Array<String>, Set<String>, or just a String, depending on your needs. They'll all work the same way when filtered.

Depending on your workflow and usage, you'll probably create faster methods to set up the userInfo dictionary. See below for other possible shortcuts.

Now that you have your logs tagged, you can filter easily:

log.filters = [TagFilter(excludeFrom: [sensitiveTag])]

Just like the FileNameFilter, you can use includeFrom: or toggle inverse to include only log messages that have the specified tags.

Filter by Developer

Filtering by developer is exactly like filtering by tag, only using the userInfo key of XCGLogger.Constants.userInfoKeyDevs. In fact, both filters are subclasses of the UserInfoFilter class that you can use to create additional filters. See Extending XCGLogger below.

Mixing and Matching

In large projects with multiple developers, you'll probably want to start tagging log messages, as well as indicate the developer that added the message.

While extremely flexible, the userInfo dictionary can be a little cumbersome to use. There are a few possible methods you can use to simply things. I'm still testing these out myself so they're not officially part of the library yet (I'd love feedback or other suggestions).

I have created some experimental code to help create the UserInfo dictionaries. (Include the optional UserInfoHelpers subspec if using CocoaPods). Check the iOS Demo app to see it in use.

There are two structs that conform to the UserInfoTaggingProtocol protocol. Tag and Dev.

You can create an extension on each of these that suit your project. For example:

extension Tag {
    static let sensitive = Tag("sensitive")
    static let ui = Tag("ui")
    static let data = Tag("data")
}

extension Dev {
    static let dave = Dev("dave")
    static let sabby = Dev("sabby")
}

Along with these types, there's an overloaded operator | that can be used to merge them together into a dictionary compatible with the UserInfo: parameter of the logging calls.

Then you can log messages like this:

log.debug("A tagged log message", userInfo: Dev.dave | Tag.sensitive)

There are some current issues I see with these UserInfoHelpers, which is why I've made it optional/experimental for now. I'd love to hear comments/suggestions for improvements.

  1. The overloaded operator | merges dictionaries so long as there are no Sets. If one of the dictionaries contains a Set, it'll use one of them, without merging them. Preferring the left hand side if both sides have a set for the same key.
  2. Since the userInfo: parameter needs a dictionary, you can't pass in a single Dev or Tag object. You need to use at least two with the | operator to have it automatically convert to a compatible dictionary. If you only want one Tag for example, you must access the .dictionary parameter manually: userInfo: Tag("Blah").dictionary.

Selectively Executing Code

All log methods operate on closures. Using the same syntactic sugar as Swift's assert() function, this approach ensures we don't waste resources building log messages that won't be output anyway, while at the same time preserving a clean call site.

For example, the following log statement won't waste resources if the debug log level is suppressed:

log.debug("The description of \(thisObject) is really expensive to create")

Similarly, let's say you have to iterate through a loop in order to do some calculation before logging the result. In Objective-C, you could put that code block between #if #endif, and prevent the code from running. But in Swift, previously you would need to still process that loop, wasting resources. With XCGLogger it's as simple as:

log.debug {
    var total = 0.0
    for receipt in receipts {
        total += receipt.total
    }

    return "Total of all receipts: \(total)"
}

In cases where you wish to selectively execute code without generating a log line, return nil, or use one of the methods: verboseExec, debugExec, infoExec, warningExec, errorExec, and severeExec.

Custom Date Formats

You can create your own DateFormatter object and assign it to the logger.

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM/dd/yyyy hh:mma"
dateFormatter.locale = Locale.current
log.dateFormatter = dateFormatter

Enhancing Log Messages With Colour

XCGLogger supports adding formatting codes to your log messages to enable colour in various places. The original option was to use the XcodeColors plug-in. However, Xcode (as of version 8) no longer officially supports plug-ins. You can still view your logs in colour, just not in Xcode at the moment. You can use the ANSI colour support to add colour to your fileDestination objects and view your logs via a terminal window. This gives you some extra options such as adding Bold, Italics, or (please don't) Blinking!

Once enabled, each log level can have its own colour. These colours can be customized as desired. If using multiple loggers, you could alternatively set each logger to its own colour.

An example of setting up the ANSI formatter:

if let fileDestination: FileDestination = log.destination(withIdentifier: XCGLogger.Constants.fileDestinationIdentifier) as? FileDestination {
    let ansiColorLogFormatter: ANSIColorLogFormatter = ANSIColorLogFormatter()
    ansiColorLogFormatter.colorize(level: .verbose, with: .colorIndex(number: 244), options: [.faint])
    ansiColorLogFormatter.colorize(level: .debug, with: .black)
    ansiColorLogFormatter.colorize(level: .info, with: .blue, options: [.underline])
    ansiColorLogFormatter.colorize(level: .notice, with: .green, options: [.italic])
    ansiColorLogFormatter.colorize(level: .warning, with: .red, options: [.faint])
    ansiColorLogFormatter.colorize(level: .error, with: .red, options: [.bold])
    ansiColorLogFormatter.colorize(level: .severe, with: .white, on: .red)
    ansiColorLogFormatter.colorize(level: .alert, with: .white, on: .red, options: [.bold])
    ansiColorLogFormatter.colorize(level: .emergency, with: .white, on: .red, options: [.bold, .blink])
    fileDestination.formatters = [ansiColorLogFormatter]
}

As with filters, you can use the same formatter objects for multiple loggers and/or multiple destinations. If a destination's formatters property is nil, the logger's formatters property will be used instead.

See Extending XCGLogger below for info on creating your own custom formatters.

Alternate Configurations

By using Swift build flags, different log levels can be used in debugging versus staging/production. Go to Build Settings -> Swift Compiler - Custom Flags -> Other Swift Flags and add -DDEBUG to the Debug entry.

#if DEBUG
    log.setup(level: .debug, showThreadName: true, showLevel: true, showFileNames: true, showLineNumbers: true)
#else
    log.setup(level: .severe, showThreadName: true, showLevel: true, showFileNames: true, showLineNumbers: true)
#endif

You can set any number of options up in a similar fashion. See the updated iOSDemo app for an example of using different log destinations based on options, search for USE_NSLOG.

Background Log Processing

By default, the supplied log destinations will process the logs on the thread they're called on. This is to ensure the log message is displayed immediately when debugging an application. You can add a breakpoint immediately after a log call and see the results when the breakpoint hits.

However, if you're not actively debugging the application, processing the logs on the current thread can introduce a performance hit. You can now specify a destination process its logs on a dispatch queue of your choice (or even use a default supplied one).

fileDestination.logQueue = XCGLogger.logQueue

or even

fileDestination.logQueue = DispatchQueue.global(qos: .background)

This works extremely well when combined with the Alternate Configurations method above.

#if DEBUG
    log.setup(level: .debug, showThreadName: true, showLevel: true, showFileNames: true, showLineNumbers: true)
#else
    log.setup(level: .severe, showThreadName: true, showLevel: true, showFileNames: true, showLineNumbers: true)
    if let consoleLog = log.logDestination(XCGLogger.Constants.baseConsoleDestinationIdentifier) as? ConsoleDestination {
        consoleLog.logQueue = XCGLogger.logQueue
    }
#endif

Append To Existing Log File

When using the advanced configuration of the logger (see Advanced Usage above), you can now specify that the logger append to an existing log file, instead of automatically overwriting it.

Add the optional shouldAppend: parameter when initializing the FileDestination object. You can also add the appendMarker: parameter to add a marker to the log file indicating where a new instance of your app started appending. By default we'll add -- ** ** ** -- if the parameter is omitted. Set it to nil to skip appending the marker.

let fileDestination = FileDestination(writeToFile: "/path/to/file", identifier: "advancedLogger.fileDestination", shouldAppend: true, appendMarker: "-- Relauched App --")

Automatic Log File Rotation

When logging to a file, you have the option to automatically rotate the log file to an archived destination, and have the logger automatically create a new log file in place of the old one.

Create a destination using the AutoRotatingFileDestination class and set the following properties:

targetMaxFileSize: Auto rotate once the file is larger than this

targetMaxTimeInterval: Auto rotate after this many seconds

targetMaxLogFiles: Number of archived log files to keep, older ones are automatically deleted

Those are all guidelines for the logger, not hard limits.

Extending XCGLogger

You can create alternate log destinations (besides the built in ones). Your custom log destination must implement the DestinationProtocol protocol. Instantiate your object, configure it, and then add it to the XCGLogger object with add(destination:). There are two base destination classes (BaseDestination and BaseQueuedDestination) you can inherit from to handle most of the process for you, requiring you to only implement one additional method in your custom class. Take a look at ConsoleDestination and FileDestination for examples.

You can also create custom filters or formatters. Take a look at the provided versions as a starting point. Note that filters and formatters have the ability to alter the log messages as they're processed. This means you can create a filter that strips passwords, highlights specific words, encrypts messages, etc.

Contributing

XCGLogger is the best logger available for Swift because of the contributions from the community like you. There are many ways you can help continue to make it great.

  1. Star the project on GitHub.
  2. Report issues/bugs you find.
  3. Suggest features.
  4. Submit pull requests.
  5. Download and install one of my apps: https://www.cerebralgardens.com/apps/ Try my newest app: All the Rings.
  6. You can visit my Patreon and contribute financially.

Note: when submitting a pull request, please use lots of small commits verses one huge commit. It makes it much easier to merge in when there are several pull requests that need to be combined for a new version.

To Do

  • Add more examples of some advanced use cases
  • Add additional log destination types
  • Add Objective-C support
  • Add Linux support

More

If you find this library helpful, you'll definitely find this other tool helpful:

Watchdog: https://watchdogforxcode.com/

Also, please check out some of my other projects:

Change Log

The change log is now in its own file: CHANGELOG.md

xcglogger's People

Contributors

bersaelor avatar bradsokol avatar bryant1410 avatar davewoodcom avatar davidthurman avatar dcharbonnier avatar dearprakash avatar esetnik avatar felixlam avatar germinator avatar heyzooi avatar ijaureguialzo avatar kaunteya avatar krbarnes avatar kylebrowning avatar laposheureux avatar larssondaniel avatar lutzifer avatar mokagio avatar mono0926 avatar mrgrauel avatar patters avatar rinkietheridge-ban avatar robnadin avatar romanroibu avatar simonrice avatar st3fan avatar tekknick avatar wadetregaskis avatar ymyzk 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  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

xcglogger's Issues

Distribution as a CocoaPod

I am looking for a logging framework and your project looks like a great tool! Unfortunately you are currently not offering the framework as a CocoaPod, which is my dependency management application.

Are you planing on including your framework to the CocoaPod project soon?

How to add embedded framework?

Hi
i was wondering how to add the library as an embedded framework to a new project?
The demo works fine, but I have no idea how to add the framework to my existing project.

thanks

Compilation crashes with Optimization level to Fastest

Compiling XCGLogger works fine with optimization level to "None" but the Swift compiler crashes when Optimisation level is set to "Fastest [-O]".

I use XCGlogger by including the XCGLogger.swift directly in my project.

Somes compiler traces:

0 swift 0x00000001101d6b68 llvm::sys::PrintStackTrace(sFILE) + 40
1 swift 0x00000001101d7054 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff8ccb2f1a sigtramp + 26
3 libsystem_platform.dylib 0x00007fe40ab10a28 sigtramp + 2112215848
4 swift 0x000000010ff6569f (anonymous namespace)::SimplifyCFGOpt::run(llvm::BasicBlock
) + 3487
5 swift 0x000000010ff648ef llvm::SimplifyCFG(llvm::BasicBlock
, llvm::TargetTransformInfo const&, llvm::DataLayout const
) + 31
6 swift 0x000000010fec7dc3 (anonymous namespace)::CFGSimplifyPass::runOnFunction(llvm::Function&) + 2051
7 swift 0x00000001100e9ced llvm::FPPassManager::runOnFunction(llvm::Function&) + 301
8 swift 0x00000001100e9edb llvm::FPPassManager::runOnModule(llvm::Module&) + 43
9 swift 0x00000001100ea39f llvm::legacy::PassManagerImpl::run(llvm::Module&) + 975
10 swift 0x000000010f5c81f4 performIRGeneration(swift::IRGenOptions&, swift::Module_, swift::SILModule_, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile_, unsigned int) + 3828
11 swift 0x000000010f5c8473 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule_, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51
12 swift 0x000000010f51d6f4 frontend_main(llvm::ArrayRef<char const*>, char const_, void_) + 5444
13 swift 0x000000010f51aa6d main + 1677
14 libdyld.dylib 0x00007fff8fbd85c9 start + 1
15 libdyld.dylib 0x0000000000000068 start + 1883404960

Background thread logging

Hey!

Great framework :) I really love it.

I just integrated it, and noticed that all the logging happens on the main thread. I haven't profiled, and it's likely not to be the bottle neck for my application at the moment. However I think it would be nice to configure, especially if we want to do some more verbose logging. Would this make sense?

Embedded dylibs/frameworks warning when compiling for 7.1

Dave, thanks for creating this useful framework.

I've included the framework in a project that is targeting iOS7.1, and building the framework generates "ld: warning: embedded dylibs/frameworks only run on iOS 8 or later". The code does link and executes on 7.1 devices, but I wonder if it will be stable and if so, whether it's possible to eliminate or suppress this warning. Thanks.

Malformed version number: 3.0b1

I got a linker error (Xcode 7 beta4) that this version number was not in a.b.c.d format after pod updating my project last night. I had to pin to the previous commit on this branch.

new setup call

In latest Xcode7 beta 6 the following line:

log.setup(logLevel: .Debug, showThreadName: true, showLogLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: "path/to/file", fileLogLevel: .Debug)

now should be:

log.setup(.Debug, showThreadName: true, showLogLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: "path/to/file", fileLogLevel: .Debug)

note the initial logLevel: is removed. Please confirm and update your instructions.

swift_2.0 branch: ld: symbol(s) not found for architecture x86_64

I'm not sure if this is an issue with the XCGLogger podfile or distribution, or with my build... however, with the latest swift_2.0 branch and Xcode 7 beta 6, when I try to use XCGLogger in my test target, I get:

ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/Developer/Library/Frameworks'
  "type metadata accessor for Glimpulse.GPLog", referenced from:
      GlimpulseIntegrationTests.GlimpulseIntegrationTests.spec (GlimpulseIntegrationTests.GlimpulseIntegrationTests)() -> () in GlimpulseIntegrationTests.o
  "static Glimpulse.GPLog.getLogger (Glimpulse.GPLog.Type)(Swift.String) -> XCGLogger.XCGLogger", referenced from:
      GlimpulseIntegrationTests.GlimpulseIntegrationTests.spec (GlimpulseIntegrationTests.GlimpulseIntegrationTests)() -> () in GlimpulseIntegrationTests.o
ld: symbol(s) not found for architecture x86_64

This would seem to indicate that the pod file was not build for x86_64 (or, at least, that it was not linked properly, or copied properly... also possibilities). I think Cocoapods has issues with multiple test targets but, not sure. It's a complicated system...

Replacement for deprecated debugExec functions

I like the idea and efficient usage of auto closures on your log messages and I understand why you deprecate the debugExec functions. Unfortunately I used this functionality mainly to let my application crash in specific scenarios, which should not happen in a production app using the following mechanism:

logger.debugExec { abort() }

Currently I only got the deprecated warning but if I want to comply with your newest version I had to change my function to sth like

logger.debug { abort(); return nil }

which produces a warning since the return statement is never reached (which is very true).

I would welcome if you could (re-) introduce a debug function which is not expecting any return value (just like debugExec). Of course I like the concise syntax of only using debug, so you could just overload this function a little bit.

Thanks!

Simpler singleton pattern?

I'm going to find XCGLogger very useful and appreciate the contribution. Thanks!

I happened to stumble across a singleton discussion on stackoverflow and, in my download of your repo, have changed the sharedInstance() method to be:

class func sharedInstance() -> XCGLogger {
    struct Singleton {
        static let instance = XCGLogger()
    }
    return Singleton.instance
}

which also allows me to get rid of the Static variables pragma portion as well. (I know this isn't an issue, but thought I'd share the link and say thanks for XCGLogger).

Option to dispatch/print on main queue

Currently everything logs to the xcglogger created dispatch queue. Things can get a little finicky (ordering and display wise) when using xcglogger, but also prints or NSLogs being used elsewhere (in my case, by containing app of the framework I'm working on) because those calls are on main.

Could there be an option in setup to have xcglogger log to just the main queue (or perhaps a user defined queue)?

Thanks!

Output to System Log

It would be nice to have an option to output in device logs to be able to debug when the app is not attached to the debugger.

I know I could use a file but it's not as convenient as doing a simple device log reading.

Version_3.0b3 with cocopods

Is there a way to use the Version_3.0b3 with cocopods. Tried a number of different ways but can get the version 3.x to load.

pod 'XCGLogger', 'Version_3.0b3'

Would it makes sense to remove XCG prefix?

Code is written in swift, swift by default has proper name-spacing. Would it makes sense to name it just Logger and keep XCG for branding purposes in README.md, but not in code?

Append to log file instead of overwrite?

Is there currently a way to just append logs to a log file instead of overwriting the file when re-opening the app? If not, I'd love to see this functionality.

Apple Mach-O Linker Warning

Hi, I'm building a project that supports back to iOS 7.1, and upon building, I see the following warning:
Apple Mach-O Linker Warning: Embedded dylibs/frameworks only run on iOS 8 or later

Is this something I should be concerned about?

Rolling Frequency, File Size etc...

Hi,

It's really great class for logging, but i feel like it would be nice if we have option to set rolling frequency, file limit etc... like CocoaLumberjack..

Read the log file while the app is running

We're doing a console for the app, and the idea is to print in a TextView the contents of the log file.

The writting is ok but when we try to read the file it fails because the file is not close.

Any workaround for this issue?

Thanks

Disable logging to console?

My purpose for using this library was that everything could be logged to files that I could go back and check later. This includes info logs, as well as error logs. I wanted to be able to track the course of my app, and see why a certain behaviour might have happened, or want to make sure that things have consistently ran as expected, but at the same time I'm likely to be busy developing new things, and not want to clutter up my console with info logs about these various parts of the app.

So my request is: I'd like to have the option to have everything logged to a file and not the console. Or perhaps console logs that start at a different level.

Integrating XCGLogger with Carthage fails

I have added XCGLogger (the swift 1.2 branch) to my Cartfile
Carthage builds fine.
I have added the built framework to my target and added the framework to my "copy-frameworks" step according to carthage documentation.
When I build my target I get the following error:

line 2: 47908 Illegal instruction: 4  /usr/local/bin/carthage copy-frameworks
fatal error: unexpectedly found nil while unwrapping an Optional value

I have also reported this issue to the carthage project since I don't know the cause yet.

Naming individual loggers

It would be great if individual logger instances had names, and emitted the name, e.g.:

11:06AM "testing" [Info] [main] [GPLog.swift:91] logger(_:withLevel:withDateFormat:) > testing logger initialized to level Info

This would help identify specific log "threads" in the output. In our system, we actually have seven different loggers for things like ux, security, web requests, core data... and adjust each independently so that we can zoom in on a particular area.

On a side note: I have a small class that loads and configures a set of loggers based on a property list file. Handy way to easily load preconfigured loggers. One logger instance created for each property list entry, with output level specified. If you take a logger out of the property list, then all logging is instead directed to the default logger. Would be great to see this kind of functionality evolve in XCGLogger. Happy to contribute a bit of code if you are interested, too...

Attempt to open log file for writing failed: nil

On XCode 6.0.1 in iOS demo app (XCGLogger 1.7), I get the following error message from library: "Attempt to open log file for writing failed: nil". It is happens with any file Path that i have tried.

xCode 6.3

Hi,

I only just updated to xCode 6.3 today. Oh man what a nightmare! Anyways your XCGLogger was working great in 6.2 though now it's doing the below.

The log message is corrupt.
I was trying to print this:

log.info("——>saveButtonClicked ")

Though I'm getting:

2015-04-10 12:47:13.133 [Info] [LocationSettingsUITable.swift:96] saveButtonClickedi(n)d:e x\342 \200i\224s\342 \2000\224

saivnedBeuxt tiosn C1l
icked

Any ideas how to fix this or where to look I'm happy to help.

Yours Sincerely
Gerard Grundy

cocoapod support

Hey there,

This looks very interesting, would it be possible to add cocoapod support to your logging framework please?

Thanks.

Problem running on iPhone 5s with iOS 8.1.3

I am using XCGLogger while developing my app and it is great in the simulator. However, I just tried to run it on my device.

I am building this using the framework as a sub-project, in my project Jeeves.

Does this error make any sense? It seems to be saying that dyld had issues loading the XCGLogger because of a missing image. But I don't see any images in the entire framework. Thoughts?

dyld: Library not loaded: @rpath/XCGLogger.framework/XCGLogger
Referenced from: /private/var/mobile/Containers/Bundle/Application/E406EE87-EA20-4B3E-A280-A754572E91E6/Jeeves.app/Jeeves
Reason: image not found

Log levels

Did you base your log levels on a common library? I think at least a warn log level is missing.
What about supporting synonyms for the different log levels? Like fatal for severe and trace for verbose?

Let me know if such a pull request would be appreciated

Runing demo app

XCGLogger.swift:208:16: 'XCGLogger.LogLevel' does not have a member named 'rawValue'
XCGLogger/XCGLogger.swift:220:45: Extra argument 'error' in call
XCGLogger.swift:490:16: 'XCGLogger.LogLevel' does not have a member named 'rawValue'
XCGLogger.swift:106:16: 'XCGLogger.LogLevel' does not have a member named 'rawValue'

Attempt to open log file for writing failed: Optional("The operation couldn’t be completed. (Cocoa error 2.)")

Hi. Thanks for the great library.
I get the following errors:
2015-01-14 23:44:11.316 [Info] : Share1 Version: 1.0 Build: 21 PID: 701
2015-01-14 23:44:11.316 [Info] : XCGLogger Version: 1.8.1 - LogLevel: Debug
2015-01-14 23:44:11.350 [Error] : Attempt to open log file for writing failed: Optional("The operation couldn’t be completed. (Cocoa error 2.)")

Version 6.1.1 (6A2008a)

Here is my config:
log.setup(logLevel: .Debug, showLogLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: "logging/debug")

Does the file need to already exist? If so what is the root of the path in the project?

Compiling for release build

When I compile for a release build I get the following error:

Running pass 'Function Pass Manager' on module '/Users/brianhickey/Library/Developer/Xcode/DerivedData/iOSDemo-alvljdwozlldssfsdvtrdkdmacua/Build/Intermediates/iOSDemo.build/Release-iphonesimulator/XCGLogger.build/Objects-normal/x86_64/XCGLogger.o'.
2. Running pass 'Simplify the CFG' on function '@TFC9XCGLogger9XCGLogger11verboseExecfMS0_FT7closureFT_T__T'

I pulled down your sample project and was able to get the same error when I build a release version. Is there any additional configuration we need to do when building for release?

Thx, really like this utility!!

Crash Compiling in Distribution

If I build the project in Distribution with Xcode 6.1 (6A1052d) the compiler crashes. Probably not much that can be done as it is apple's issue but thought you might want to know about it.

CompileSwift normal arm64 /Users/possen/XCGLogger/XCGLogger/Library/XCGLogger/XCGLogger.swift
cd /Users/possen/XCGLogger/XCGLogger/Library
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/possen/XCGLogger/XCGLogger/Library/XCGLogger/XCGLogger.swift /Users/possen/XCGLogger/XCGLogger/Library/XCGLoggerTests/XCGLoggerTests.swift -target arm64-apple-ios8.0 -Xllvm -aarch64-use-tbi -target-cpu cyclone -target-abi darwinpcs -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Products/Release-iphoneos -F /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Products/Release-iphoneos -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/Developer/Library/Frameworks -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/Developer/Library/Frameworks -g -module-cache-path /Users/possen/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/XCGLoggerTests-generated-files.hmap -Xcc -I/Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/XCGLoggerTests-own-target-headers.hmap -Xcc -I/Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/XCGLoggerTests-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/XCGLoggerTests-project-headers.hmap -Xcc -I/Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Products/Release-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/DerivedSources/arm64 -Xcc -I/Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/DerivedSources -emit-module-doc-path /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/Objects-normal/arm64/XCGLoggerpartial.swiftdoc -O -module-name XCGLoggerTests -emit-module-path /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/Objects-normal/arm64/XCGLoggerpartial.swiftmodule -serialize-diagnostics-path /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/Objects-normal/arm64/XCGLogger.dia -emit-dependencies-path /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/Objects-normal/arm64/XCGLogger.d -o /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/Objects-normal/arm64/XCGLogger.o

0 swift 0x00000001070eaa68 llvm::sys::PrintStackTrace(sFILE) + 40
1 swift 0x00000001070eaf54 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff8b20ef1a sigtramp + 26
3 libsystem_platform.dylib 0x00007fa3e3801828 sigtramp + 1482631464
4 swift 0x0000000106e7959f (anonymous namespace)::SimplifyCFGOpt::run(llvm::BasicBlock
) + 3487
5 swift 0x0000000106e787ef llvm::SimplifyCFG(llvm::BasicBlock
, llvm::TargetTransformInfo const&, llvm::DataLayout const
) + 31
6 swift 0x0000000106ddbcc3 (anonymous namespace)::CFGSimplifyPass::runOnFunction(llvm::Function&) + 2051
7 swift 0x0000000106ffdbed llvm::FPPassManager::runOnFunction(llvm::Function&) + 301
8 swift 0x0000000106ffdddb llvm::FPPassManager::runOnModule(llvm::Module&) + 43
9 swift 0x0000000106ffe29f llvm::legacy::PassManagerImpl::run(llvm::Module&) + 975
10 swift 0x00000001064dc064 performIRGeneration(swift::IRGenOptions&, swift::Module_, swift::SILModule_, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile_, unsigned int) + 3828
11 swift 0x00000001064dc2e3 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule_, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51
12 swift 0x00000001064315f4 frontend_main(llvm::ArrayRef<char const*>, char const_, void_) + 5444
13 swift 0x000000010642e96d main + 1677
14 libdyld.dylib 0x00007fff8fc765c9 start + 1
15 libdyld.dylib 0x0000000000000044 start + 1882757756
Stack dump:
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/possen/XCGLogger/XCGLogger/Library/XCGLogger/XCGLogger.swift /Users/possen/XCGLogger/XCGLogger/Library/XCGLoggerTests/XCGLoggerTests.swift -target arm64-apple-ios8.0 -Xllvm -aarch64-use-tbi -target-cpu cyclone -target-abi darwinpcs -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Products/Release-iphoneos -F /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Products/Release-iphoneos -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/Developer/Library/Frameworks -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/Developer/Library/Frameworks -g -module-cache-path /Users/possen/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/XCGLoggerTests-generated-files.hmap -Xcc -I/Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/XCGLoggerTests-own-target-headers.hmap -Xcc -I/Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/XCGLoggerTests-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/XCGLoggerTests-project-headers.hmap -Xcc -I/Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Products/Release-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/DerivedSources/arm64 -Xcc -I/Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/DerivedSources -emit-module-doc-path /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/Objects-normal/arm64/XCGLoggerpartial.swiftdoc -O -module-name XCGLoggerTests -emit-module-path /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/Objects-normal/arm64/XCGLoggerpartial.swiftmodule -serialize-diagnostics-path /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/Objects-normal/arm64/XCGLogger.dia -emit-dependencies-path /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/Objects-normal/arm64/XCGLogger.d -o /Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/Objects-normal/arm64/XCGLogger.o

  1. Running pass 'Function Pass Manager' on module '/Users/possen/Library/Developer/Xcode/DerivedData/XCGLogger-ahhbanemlukxykhjcjcmrbqsehbk/Build/Intermediates/XCGLogger.build/Release-iphoneos/XCGLoggerTests.build/Objects-normal/arm64/XCGLogger.o'.
  2. Running pass 'Simplify the CFG' on function '@TFC14XCGLoggerTests9XCGLogger11verboseExecfMS0_FT7closureFT_T__T'

Add the ability to remove all additional informations

This is a need I have: only log messages but additional informations such as date, function name...

Thank to multiple instances feature, I create a file log for a very specific usage to trace the evolution of some data structure. This is for a game where I want to log each player move in order to have the game history. It then allow me to replay that game, first for development purposes then for future additional game features.

By logging only the wanted data I then can format a file I can use as-is: i.e. in JSON or XML format or anything else.

XCGlogger output truncated when app crashes right after

Hi,

Just before a point where the app will crash, I have a log.verbose() line, which gets truncated:
2014-11-21 09:19:58.095 [Verbose] [MyViewController.swift:121] listDataCallback(_:response(lldb)

To compare, I added a println() and that gets printed out fine.

Project update status

The maintainer of XCGLogger @DaveWoodCom hasn't pushed a commit to github in over a month and the issues and pull requests are starting to pile up here. I would like to use XCGLogger in a shipping ios9 project but I'd rather not maintain a private fork.

It would be great if @DaveWoodCom jumped in here and posted an update on where things are headed. If he's too busy to be a maintainer then perhaps he could recruit a few other to take over the management of the pull requests?

I don't want to see this project die a death of a thousand forks.

iOS 7 compatibility

I recently started the process of validating my project in xcode for deployment inTunes connect. I currently receive a warning:

PBXCp Warning
warning: skipping copy phase strip, binary is code signed...

Regarding XLGLogger

Does the logger work with iOS7, which apparently iTunes connect requires currentlyfor distribution.

untitled 2

Use of unresolved identifier 'XCGLoggerVersionNumber'

I'm getting this error message when trying to run my project using XCGLogger:

/XCGLogger/XCGLogger.swift:389:90: Use of unresolved identifier 'XCGLoggerVersionNumber'

For now I've added the global var manually just to run the project.

Thanks.

compiler issues on Xcode6 GM

On Xcode6 Version 6.0 (6A313), I get the following (I tried the obvious fixes e.g. changing "rawValue" to "toRaw()", but it would then start complaining NSFileHandle initializers. is it something that I am missing?

/Users/ishaq/Projects/github/XCGLogger/XCGLogger/XCGLogger/XCGLogger.swift:106:16: error: 'XCGLogger.LogLevel' does not have a member named 'rawValue'
        return logLevel.rawValue >= self.outputLogLevel.rawValue
               ^        ~~~~~~~~
/Users/ishaq/Projects/github/XCGLogger/XCGLogger/XCGLogger/XCGLogger.swift:208:16: error: 'XCGLogger.LogLevel' does not have a member named 'rawValue'
        return logLevel.rawValue >= self.outputLogLevel.rawValue
               ^        ~~~~~~~~
/Users/ishaq/Projects/github/XCGLogger/XCGLogger/XCGLogger/XCGLogger.swift:220:45: error: extra argument 'error' in call
                logFileHandle = NSFileHandle(forWritingToURL: unwrappedWriteToFileURL, error: &fileError)
                                            ^                                                 ~~~~~~~~~~
/Users/ishaq/Projects/github/XCGLogger/XCGLogger/XCGLogger/XCGLogger.swift:490:16: error: 'XCGLogger.LogLevel' does not have a member named 'rawValue'
        return logLevel.rawValue >= self.outputLogLevel.rawValue

Swift 1.2 compatibility

Hi,
would like to use XCGLogger with Xcode 6.3 and Swift 1.2, but it won't compile.

Thanks,
O.

Is there anyway to wrap the usage?

Hello, we find very useful this Logger but we want to wrap it on our own Logger class, for the case that in a future we want to do more things on Log events (send to our servers, change to another framework...)

But we do not want to lose the functionality of print the file, class and line of the current log message.

¿any ideas?

Thanks

Can't close log file except with deinit

The only time the log file (XCGFileLogDestination) gets closed is in the deinit on the XCGFileLogDestination. I'm trying to allow the user to email the log file to report defects when they occur. As a workaround, instead of using the defaultInstance which never gets a deinit call, I create my own instance that is an optional so I can set it to nil to force a deinit. The basic flow

  • at app launch, create an XCGLogger and call setup with a log file.
  • to email the file, set the XCGLogger to nil, copy the log file to history, and email the history file
  • recreate the XCGLogger which start with a new empty log file.

I'm doing the same process when the app enters background to make sure I have a complete log file.

I also think processLogDetails() needs a call to synchronizeFile() at the end to make sure the log file is complete.

Error: cannot invoke 'debug' with an argument list of type '(String)'

Installing XCGLogger from the master branch using the method in the directions (as a subproject of my Xcode project and then adding dependency/framework) as well as just dragging XCGLogger.swift into my project produces the same build error:

error: cannot invoke 'debug' with an argument list of type '(String)'

In ApplicationDelegate.swift in global scope:

let log = XCGLogger.defaultInstance()

In application:didFinishLaunchingWithOptions::

log.setup(logLevel: .Debug, showLogLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: nil)

In another Swift file, this line of code inside a method causes the aforementioned build error:

log.debug("Message")

Xcode Version 6.3.2 (6D2105) building with iOS SDK 8.3

Make XCGLogger only use "App Extension" compatible API

Over at https://github.com/mozilla/firefox-ios we're using XCGLogger -- thanks! We'd like to use it everywhere, including in our App Extensions. We get a (spurious, I hope) warning like
ld: warning: linking against dylib not safe for use in application extensions ... XCGLogger because XCGLogger is not marked as using the restricted "App Extension" compatible API. Would you take a PR flipping the bit?

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.