diff --git a/lib/bb/build.py b/lib/bb/build.py
index b38936fc360c..72f1c7bc72d2 100644
--- a/lib/bb/build.py
+++ b/lib/bb/build.py
@@ -21,6 +21,7 @@ import time
 import re
 import stat
 import datetime
+import json
 import bb
 import bb.msg
 import bb.process
@@ -668,6 +669,13 @@ def _exec_task(fn, task, d, quieterr):
         except OSError:
            pass
 
+    # Task log records, for sstate log replay. Written right after the task
+    # body, before the postfuncs, so the sstate packaging postfunc can read them.
+    # Stored under TMPDIR, keyed by multiconfig, virtual class and recipe, so
+    # any sstate task can reach the records of covered tasks from other recipes.
+    logrecords = bb.utils.logrecords_path(localdata, fn, task)
+    bb.utils.remove(logrecords)
+
     prefuncs = localdata.getVarFlag(task, 'prefuncs', expand=True)
     postfuncs = localdata.getVarFlag(task, 'postfuncs', expand=True)
 
@@ -710,6 +718,9 @@ def _exec_task(fn, task, d, quieterr):
     errchk = ErrorCheckHandler()
     bblogger.addHandler(errchk)
 
+    tasklogcatcher = bb.utils.LogCatcher()
+    bblogger.addHandler(tasklogcatcher)
+
     localdata.setVar('BB_LOGFILE', logfn)
     localdata.setVar('BB_RUNTASK', task)
     localdata.setVar('BB_TASK_LOGGER', bblogger)
@@ -723,6 +734,9 @@ def _exec_task(fn, task, d, quieterr):
             for func in (prefuncs or '').split():
                 exec_func(func, localdata)
             exec_func(task, localdata)
+            bb.utils.mkdirhier(os.path.dirname(logrecords))
+            with open(logrecords, 'w') as f:
+                json.dump(tasklogcatcher.records, f)
             for func in (postfuncs or '').split():
                 exec_func(func, localdata)
         finally:
@@ -732,6 +746,7 @@ def _exec_task(fn, task, d, quieterr):
             sys.stderr.flush()
 
             bblogger.removeHandler(handler)
+            bblogger.removeHandler(tasklogcatcher)
 
             # Restore the backup fds
             os.dup2(osi[0], osi[1])
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 4a4e911b0f8a..3728e8b6a02b 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -2150,6 +2150,15 @@ def load_plugins(logger, plugins, pluginpath):
                 plugins.append(plugin)
 
 
+def logrecords_path(d, fn, task):
+    from bb.cache import virtualfn2realfn
+
+    realfn, cls, mc = virtualfn2realfn(fn)
+    mc = "mc:" + mc if mc else ""
+    recipe = os.path.splitext(os.path.basename(realfn))[0]
+    return os.path.join(d.getVar("TMPDIR"), "logrecords", mc, cls, recipe,
+                        "logrecords.%s.json" % task)
+
 class LogCatcher(logging.Handler):
     """Logging handler for collecting logged messages so you can check them later"""
     def __init__(self):
