Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SwiftRex Logger Middleware

License

NotificationsYou must be signed in to change notification settings

SwiftRex/LoggerMiddleware

Repository files navigation

Usage

Simple usage, logging all actions and state changes for whole app

LoggerMiddleware.default()<>MyOtherMiddleware().lift(...)

Log a single middleware, only actions and state within that middleware field

MyOtherMiddleware().logger().lift(...)

Log a single middleware, but including actions and state changes for the whole app

(same as adding LoggerMiddleware.default() in the chain as seen in the first option)

MyOtherMiddleware().lift(...).logger()

Log a specific group of actions and state tree

IdentityMiddleware<InterestingAction,InterestingAction,InterestingState>().logger().lift(...) // lift InterestingAction and InterestingState to AppAction and AppState<>MyOtherMiddleware().lift(...)

Parameters

actionTransform

Gives the Input Action and Action Source to be formatted as a string.

Default:

actionTransform: @escaping(InputActionType, ActionSource)-> String={"\n🕹\($0)\n🎪\($1.file.split(separator:"/").last??""):\($1.line)\($1.function)"}

actionPrinter

Gives the action and action source string, formatted from previous parameter, to be logged or saved into a file

Default:

actionPrinter: @escaping(String)-> Void={os_log(.debug, log:.default,"%{PUBLIC}@", $0)}

stateDiffTransform

Gives the previous state, and the state after the reducers have changed it, so a diff string can be created.Difference struct contains helpers to compare multiline strings, anddumpToString free function is a helper to stringify anything.Alternatively you could stringify using JSONEncoder or any other tool. Be careful with performance, or provide an alternative queueto avoid locking the main queue with heavy log task.Returningnil means that nothing has changed.The default logger will give a "git diff" output, containing + and - for changed lines, including 2 lines of context before and after the change.

Default:

stateDiffTransform: @escaping(StateType?, StateType)-> String?={letstateBefore=dumpToString($0)letstateAfter=dumpToString($1)returnDifference.diff(old: stateBefore, new: stateAfter, linesOfContext:2, prefixLines:"🏛")}

stateDiffPrinter

Gives the state diff string, formatted from previous parameter, to be logged or saved into a file.Receivingnil means that the state hasn't changed with this action.

Default:

stateDiffPrinter: @escaping(String?)-> Void={ stateiniflet state= state{os_log(.debug, log:.default,"%{PUBLIC}@", state)}else{os_log(.debug, log:.default,"%{PUBLIC}@","🏛 No state mutation")}}

queue

The queue to run the string transformation and printer. Use an alternative, low priority, serial queue to avoid locking the UIwith logging operations.

Default:

queue: DispatchQueue=.main

About

SwiftRex Logger Middleware

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp