Pulse Documentation Beta

Class Logger​Store

public final class LoggerStore 

LoggerStore persistently stores all of the logged messages, network requests, and blobs. Use .default store to log messages.

Nested Types

LoggerStore.Options
LoggerStore.MetadataValue
LoggerStore.Level

Nested Type Aliases

Metadata

typealias Metadata = [String: MetadataValue]

Initializers

init(store​URL:​options:​)

public convenience init(storeURL: URL, options: Options = []) throws 

Initializes the store with the given URL.

There are two types of URLs that the store supports:

  • A plain directory with a Pulse database (optimized for writing)

  • A document with .pulse extension (readonly, archive)

Logger.default is a plain directory optimized for writing. When you are ready to share the store, create a Pulse document using archive() or copy(to:) methods. The document format is optimized to use the least amount of space possible.

Parameters

store​URL URL

The store URL.

options Options

By default, empty. To create a new store, pass .create option.

Properties

model

static let model: NSManagedObjectModel 

Returns Core Data model used by the store.

store​URL

public let storeURL: URL

The URL the store was initialized with.

is​Readonly

public let isReadonly: Bool

Returns true if the store was opened with a Pulse archive (a document with .pulse extension). The archives are readonly.

info

public private(set) var info: LoggerStoreInfo?

Returns the store info (only available for archives).

container

public let container: NSPersistentContainer

Returns the Core Data container associated with the store.

background​Context

public let backgroundContext: NSManagedObjectContext

Returns the background managed object context used for all write operations.

database​Size​Limit

public static var databaseSizeLimit: Int = 1024 * 1024 * 30

Size limit in bytes. 30 Mb by default. The limit is approximate.

blobs​Size​Limit

public static var blobsSizeLimit: Int = 1024 * 1024 * 200

Size limit in bytes. 200 Mb by default.

`default`

public static let `default` 

The default store.

logs​URL

public static var logsURL: URL 

Returns a URL for the directory where all Pulse stores are located. The current store is located in the "./current" directory, the rest the stores are in "./archive".

empty

public static var empty: LoggerStore 

A placeholder store, no persistent store.

Methods

store​Message(date:​label:​level:​message:​metadata:​file:​function:​line:​)

public func storeMessage(date: Date? = nil, label: String, level: Level, message: String, metadata: [String: MetadataValue]?, file: String, function: String, line: UInt) 

Stores the given message.

get​Data(for​Key:​)

public func getData(forKey key: String) -> Data? 

Returns blob data for the given key.

sweep()

func sweep() 

copy(to:​)

@discardableResult
    func copy(to targetURL: URL) throws -> LoggerStoreInfo 

Creates a copy of the current store at the given URL. The created copy has .pulse extension (actually a .zip archive).

The destination directory must already exist. But if the file at the destination URL already exists, throws an error.

Thread-safe. But must not be called inside the backgroundContext queue.

all​Messages()

func allMessages() throws -> [LoggerMessageEntity] 

Returns all recorded messages, least recent messages come first.

all​Network​Requests()

func allNetworkRequests() throws -> [LoggerNetworkRequestEntity] 

Returns all recorded network requests, least recent messages come first.

remove​All()

func removeAll() 

Removes all of the previously recorded messages.