Using the built-in device log

Hello,

I need to implement a basic event log functionality and I was wondering if it is possible to use the built in device log for that purpose:

If it is possible what is the maximum number of events that can be stored?

Thanks,
Borislav

The system log (as shown on your screenshot above) is reserved for internal purpose, only. It is strongly discouraged to use it for applicative logs.
Furthermore the system log is very limited in it’s functionality - it consist of just a 16bit code plus a single 16bit parameter.

The recommended ways to implement an applicative log are

  1. Use the built-in #applog container
  2. Implement your own applog container using #histdata9 (or similar) to solve more sophisticated needs

Built-in #applog container

Note: This is an upcoming solution actually supported by the backend and device API’s, only. It is not visible at the backend portal at the moment (announced for early 2022).

Add this line anywhere to the file dde/main.dde to invoke the applog container:

#applog
  1. Use the applog_xxx() functions in your DLO code, such as in main.p:
#callback onButton( pressed) {
	static _step= 0;
	_step++;
	applog( "test.normal", "step=%d;pressed=%d", _step, pressed);
	// ^-- or use applog_debug(), applog_warning(),... to apply a log level
}

Seach for “applog” in the studio’s help for further information.

  1. Retreive your applog items from the backend’s API at cloud.microtronics.com/api/1:
GET /1/customers/$cid/sites/$sid/applog

Replace $cid and $sid with your individual customer and site names.


Custom applog container

  1. Define your custom container in the file dde/main.dde:
#histdata9 applog up+ dlo="wu"
	prio 	astr.1
	code 	astr.15
	params 	astr.100
	// ^-- this is just a recommendation, 
	// you may add here any fields helpful for the special logging-needs of your application
  1. Define your custom logging functions for your DLO such as:
stock applog( const code{15+1}, const params{100+1}) {	// normal level
	DDE_applog_write( 0, " ", code, params);
}
stock applog_debug( const code{15+1}, const params{100+1}) {	// debug level
	DDE_applog_write( 0, "~", code, params);
}
stock applog_ok( const code{15+1}, const params{100+1}) {	// ok confirmation
	DDE_applog_write( 0,"$", code, params);
}
stock applog_warning( const code{15+1}, const params{100+1}) {	// warning level
	DDE_applog_write( 0, "?", code, params);
}
stock applog_alarm( const code{15+1}, const params{100+1}) {	// error level
	DDE_applog_write( 0, "!", code, params);
}
stock applog_fatal( const code{15+1}, const params{100+1}) {	// assertion level
	DDE_applog_write( 0,"§", code, params);
}
  1. And use your custom applog functions in your DLO code, such as in main.p:
#callback onButton( pressed) {
	static _step= 0;
	_step++;

	new params{100+1};
	sprintf( params,_ , "step=%d;pressed=%d", _step, pressed);
	applog( "test.normal", params);
	// ^-- or use applog_debug(), applog_warning(),... to apply a log level
}
  1. To instantly visualize your applog items, create a report at the backend’s portal:

  2. Furthermore your custom applog is avaliable on the backend’s API at cloud.microtronics.com/api/1:

GET /1/customers/$cid/sites/$sid/histdata9
{ "select": ["prio","code","params"],
  "from": "20211201",
  "until": "*"
}

Replace $cid and $sid with your individual customer and site names.


SUMMARY

The built-in #applog container has some advantages:

  • DLO functions applog_xxx() support variable parameters similar to printf (custom applog requires a separate sprintf)
  • Backend portal and API will be able to merge the applog items with several other sources (such as system log)
  • Instant user interface at the portal (announced early 2022)

The custom applog trumps at:

  • Degrees of freedom of the log parameters
  • It’s the only possibility to show log items at the portal without programming work (POV coding) before early 2022
1 Like