Where does Lollipop stores notification log? Android 4.3 and above allows access to a list of historical notifications using the Settings widget. The scope of "historical" is limited to current session of Android and the list is populated with new entries once the system is rebooted. 

(Click image to enlarge)



So, where does this notification log is stored in Android?


I had no luck finding anything good named "notification". I already did a system-wide search with nothing positive to report here.

find / -iname "*notification*"

I watched the real-time output of adb logcat -v long (tried with explicit root access as well) but there was no common event  when a notification popped up in notification drawer. I was monitoring the ping request (shows up as a notification) to KDE Connect sent from my Slackware Linux, for the test case. 
The entries that are visible in Notification drawer can be traced back to the output of notification service,

adb shell dumpsys notification


As said, you get the current ones but not the historical ones.
The real name or codename (I suppose) of notification service is android.app.INotificationManager.   I attempted to dive into its  source
code and there is nothing positive to report. It is very likely that being not a programmer, I might have missed a thing or two of importance.
I, while being reluctant for being illogical, did peek into the data directory of Settings (com.android.settings) and Settings Storage (com.android.providers.settings) apps. Nothing interesting there.


I presume that either the log is managed in the memory by a program or at some location in storage where the logs are frequently flushed after current Android session ends. I've no idea what I'm talking here.

Edit:

I've the Notification access to Tasker under Settings &rarr; Notification manager already enabled. So that's definitely not the roadblock here.

(Asked by Lucky) The intent associated with that Notification log window accessible through Settings widget has the following things:


Action: android.intent.action.MAIN
Category: com.android.settings.SHORTCUT
Flag: 0x10200000
Component: com.android.settings/.Settings$NotificationStationActivity




Note


I've a rooted OnePlus One running COS12 (Xposed Framework installed) and many Android 5.1 ROMs. 
I'm absolutely aware about many apps which can record notifications and lets you see them. But as you would've guessed by now, I'm not interested in futuristic past but the past related to present moment. In short, I want access to native raw files or logs to see both the historical and current notifications without depending on third-party apps. 




My goal

When a secondary user is in focus, Tasker (running under Primary user) misses any profile which depends upon an incoming notification. Google has noted the fact here:


  Notifications for other users do not appear until they are active.  


But you can still see those new notifications in the output of adb shell dumpsys notification. So I want to access the logs directly to make my task(s) work, thereby removing the dependence on notifications showing up in Notification drawer.
The historical record is stored in memory, and is not directly available in the service API (as far as I'm aware). The Settings activity accesses it through the NotificationService.getHistoricalNotifications() method, but this method is not exposed in the NotificationManager API (only getActiveNotifications() is). You might be able to do it through reflection (not tested) but you definitely will not be able to find a file with this information. My understanding of most apps that display these records is that they actually keep their own list somewhere, and add new items as they are posted. Hence, they would not be able to access your historical record from before the time of installation.

All of the logic for managing the queue is in the NotificationManagerService$Archive inner class. The gist of it is that when a new notification comes in, the system sends it to the the service which then calls Archive.record(notification). By default, AOSP has the configuration set so that the Archive will hold a maximum of 100 records, then it will start popping the front item from the queue each time a new one is added.

Your only real option here is likely going to be polling the output of either adb dumpsys or the NotificationManager.