dbprintflog

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Debug
Introduced first in SolidGeometry 5.3, Creation date: 2023-01-29, Last change: 2025-09-15

fnct that logs similar to former frintf(2,) a text tino a log file

Description

The more batch programs rund the more difiult it is to debug those files that have no output anymore, since the batch files run in the background without an terminal output. Therefor, this function allows to log into a logfile; Function name and date time stamp are added automatically.
It is used in spindumpkill

See Also: dbreturn , dbsave , dbprintmode , fprintfvec , fprintfvec2 , str2codelines , sprintfvec

Example Illustration

 missing image of dbprintflog (argslist)

Syntax

dbprintflog([argslist])

Input Parameter

argslist: liat of arguments equal to to sprintf

Examples


dbprintflog('This is a test log file line')
openbydoubleclick(desktopdir('Matlablog.txt'))




Copyright 2023-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This function, dbprintflog, is designed to log messages into a log file, which is particularly useful for debugging batch programs that run in the background without terminal output. The function automatically adds the function name and a date-time stamp to each log entry.

Input Parameters

Algorithm Steps

  1. Retrieve the function parameters using getfuncparams with the input varargin.
  2. Determine the caller function's name and line number using dbstack. If the function is called directly, use verML for the name and set the line number to 0.
  3. Format the input arguments into a string using sprintf.
  4. Get the current date and time using datestr(now).
  5. Concatenate the date-time stamp, caller name, and formatted text into a single string, appending a newline character.
  6. Determine the log file path using desktopdir('Matlablog.txt').
  7. Open the log file in append mode using fopen.
  8. Write the formatted log entry to the file using fprintf.
  9. Close the file using fclose.

Example Usage

To log a message, you can call the function as follows:

dbprintflog('This is a test log file line')

To view the log file, you can use:

openbydoubleclick(desktopdir('Matlablog.txt'))
Algorithm explaination created using ChatGPT on 2025-08-19 07:26. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21