Say we have a view page where users perform actions in multiple steps, some of these actions would involve DB operations with transactions (the snippets are in pseudo-code like from):View 1:    Step 1:        ...    Step 2:        ...        Call ActionX    Step 3:        ...    ActionX: # can be called from different points in the view    ...    Begin Transaction    DB ops    End TransactionSay we want to log the user progress in the view (or save some states) in a persistent manner in the DB, so that if the program/app is interrupted we can re-establish the state to the last user action inside a view:View1:    Step 1:        ...        Logger.log('view1-step1-done')    Step 2:        ...        Call ActionX        Logger.log('view1-step2-done')    Step 3:        ...        Logger.log('view1-step3-done')Now ideally, we would want to have the persistent logging and the DB based transactional  actions to be both done in the same DB transaction, because we don't want to create an inconsistent state where an action is performedbut is not reflected in the log state, or vice versa. The question is: how to achieve the said goal with minimum inter-dependency and SOC. Some suggestions for example:View 1:    Step 1:        ...    Step 2:        ...        Begin Transaction        Call ActionX    # begin/end transaction statements will be removed from ActionX        Logger.log('view1-step3-done')        End Transaction    Step 3:        ...Don't like this because the handling of transactions belongs naturally in the action itself.Or, another one:View 1:    Step 1:        ...    Step 2:        ...        Call ActionX (logMsg='view1-step3-done')     Step 3:        ...ActionX (logMsg):     ...    Begin Transaction    DB ops    Logger.log(logMsg)    End TransactionDon't like this one either. The log message handling doesn't belong in the actions.
Mingling DB transactions and logging from a design perspective
design patterns;transaction
The primary guidance for this question is to separate out the responsibilities.It appears that you are trying to link an Action's transactional state with the Log's transactional state, and I think that's a mistake.  Record the Action changes based upon the Action.  Record the Log status based upon the resulting (returned) status.  If the Action succeeds, then Log a success status message.  Likewise, if the Action failed, then Log an error message to that effect.  Since your log messages appear to be indicating status from the Views, then it is the Views' responsibility to handling the logging.  If the log messages are related to the internal aspects of the Action, then the Action should take the responsibility of logging.Please keep in mind that those two positions are not exclusive of each other.  You might find that you need to log both the Views' progress as well as internal aspects of the Action.  At that point, you would have both areas (Views and Action) making logging calls.