Skip to content

Commit

Permalink
- Updated docs, fixes #12. - U�pdated to Zeugwerk naming conventions,…
Browse files Browse the repository at this point in the history
… this might introduce breaking changes in the API signature. - Fixed bug where no newline is inserted when logging message with > 254 chars to the file system.
  • Loading branch information
bengeisler committed Nov 2, 2023
1 parent dff3286 commit f69995a
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Configure the core logger in your project:

```st
VAR
_coreLogger : TcLogCore(bufferSize := 100 * (MAX_STRINGLENGTH + Constants.FifoOverhead));
_coreLogger : TcLogCore(bufferSize := 100 * (Tc2_System.MAX_STRING_LENGTH + Constants.FifoOverhead));
END_VAR
_coreLogger
Expand Down
6 changes: 3 additions & 3 deletions docs/userguide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _coreLogger
_logger.Error('This is an error message.');
```

![Including the instance path](https://benediktgeisler.de/InstancePath.png "Including the instance path")
![Including the instance path](https://www.benediktgeisler.de/InstancePath.png "Including the instance path")

## Log to ADS output
When adding the method `.WriteToAds()` to `TcLogCore`, the log messages are sent to the ADS output:
Expand All @@ -46,7 +46,7 @@ _loggerTrig
.Error('rTrig Test');
```

![Logging to the file system](https://benediktgeisler.de/LogMessageInFiileSystem.png "Logging to the file system")
![Logging to the file system](https://www.benediktgeisler.de/LogMessageInFiileSystem.png "Logging to the file system")

### Timestamp
The file name is additionally prefixed with the creation date of the log file. The format of the date can be defined arbitrarily by means of a format string. Example:
Expand Down Expand Up @@ -89,7 +89,7 @@ Different scenarios may require different logging strategies. For example, you m

```st
VAR
_coreLogger : TcLogCore(bufferSize := 100 * SIZEOF(BYTE) * MAX_STRINGLENGTH);
_coreLogger : TcLogCore(bufferSize := 100 * (Tc2_System.MAX_STRING_LENGTH + Constants.FifoOverhead));
_logger : TcLog;
_isDevelopment : BOOL := TRUE;
END_VAR
Expand Down
2 changes: 1 addition & 1 deletion docs/userguide/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ _myLog(

As soon as logging is triggered via `_log`, the csv file and the entries in it are created:

![Custom logging](https://benediktgeisler.de/CustomLogging.png "Custom logging")
![Custom logging](https://www.benediktgeisler.de/CustomLogging.png "Custom logging")

## Use of custom loggers
`TcLogCore` implements the `ILogCore` interface which defines the `LogCustomFormat` and `LogStandardFormat` methods.
Expand Down
2 changes: 1 addition & 1 deletion docs/userguide/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Configure the core logger in your project:

```st
VAR
_coreLogger : TcLogCore(bufferSize := 100 * (MAX_STRINGLENGTH + FifoOverhead));
_coreLogger : TcLogCore(bufferSize := 100 * (Tc2_System.MAX_STRING_LENGTH + Constants.FifoOverhead));
END_VAR
_coreLogger
Expand Down
4 changes: 2 additions & 2 deletions docs/userguide/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ _logger
.AppendVariable(_myVarInfo, _myInt)
.Error('');
```
![Using a StringBuilder to generate the message text](https://benediktgeisler.de/StringBuilder_in_message_text.png "Using a StringBuilder to generate the message text")
![Using a StringBuilder to generate the message text](https://www.benediktgeisler.de/StringBuilder_in_message_text.png "Using a StringBuilder to generate the message text")

Thus any amount of information can be appended to the message without having to implement `TcLog` with a large number of input parameters, since TwinCAT (at least in version before build 4026.0) does not allow optional input parameters.

Expand Down Expand Up @@ -63,7 +63,7 @@ Even though the logger was primarily designed as a singleton, it is possible to

```st
VAR
_newLogger: TcLogCore(bufferSize := 100 * (MAX_STRING_LENGTH + Constants.FifoOverhead));
_newLogger: TcLogCore(bufferSize := 100 * (Tc2_System.MAX_STRING_LENGTH + Constants.FifoOverhead));
_logger: TcLog;
_myInt : INT := 10;
END_VAR
Expand Down
2 changes: 1 addition & 1 deletion src/TcLogProj/TcLog/CONSTANTS.TcGVL
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ VAR_GLOBAL CONSTANT
/// Fifo overhead needed to manage the string buffer
FifoOverhead : INT := 10;
/// Buffer size of temporary buffer used to persist all log messages in one cycle.
BufferSize : INT := (100 * (UDINT_TO_INT(Tc2_System.MAX_STRING_LENGTH) + FifoOverhead));
BufferSize : INT := (100 * (UDINT_TO_INT(Tc2_System.Tc2_System.MAX_STRING_LENGTH) + FifoOverhead));
END_VAR]]></Declaration>
</GVL>
</TcPlcObject>
6 changes: 3 additions & 3 deletions src/TcLogProj/TcLog/Logger/TcLog.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ VAR
END_VAR
VAR_STAT
{attribute 'hide'}
_loggerSingletonInstance : ILogCore; // Wires up TcLog ("Client") to TcLogCore ("Server") (Singleton-Behaviour)
s_loggerSingletonInstance : ILogCore; // Wires up TcLog ("Client") to TcLogCore ("Server") (Singleton-Behaviour)
END_VAR
VAR CONSTANT
InvalidLoggerReference : UDINT := 0;
Expand Down Expand Up @@ -208,7 +208,7 @@ VAR_INPUT
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[_loggerSingletonInstance := ref2Core;]]></ST>
<ST><![CDATA[s_loggerSingletonInstance := ref2Core;]]></ST>
</Implementation>
</Method>
<Method Name="InitializeLogData" Id="{b4d317d9-a916-4484-9cf0-3391543593aa}">
Expand All @@ -221,7 +221,7 @@ METHOD PRIVATE InitializeLogData : BOOL
_logConditionSatisfied := TRUE;
_logData := '';
_logDataInitialized := TRUE;
IF _usedLogger = 0 THEN _usedLogger := _loggerSingletonInstance; END_IF
IF _usedLogger = 0 THEN _usedLogger := s_loggerSingletonInstance; END_IF
END_IF]]></ST>
</Implementation>
</Method>
Expand Down
2 changes: 1 addition & 1 deletion src/TcLogProj/TcLog/Logger/TcLogCore.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
///
/// ```st
/// VAR
/// myLogger: TcLogCore(BufferSize := 100 * SIZEOF(BYTE) * Tc2_System.MAX_STRING_LENGTH);
/// myLogger: TcLogCore(BufferSize := 100 * (Tc2_System.Tc2_System.MAX_STRING_LENGTH * Constants.FifoOverhead));
/// END_VAR
/// ```
///
Expand Down
2 changes: 1 addition & 1 deletion src/TcLogProj/TcLog/Logger/_Interfaces/ILog.TcIO
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Method Name="SetLogger" Id="{d997efda-3f08-4614-802a-e86242c0eb02}">
<Declaration><![CDATA[METHOD SetLogger : BOOL
VAR_INPUT
Ref2Core : ILogCore;
ref2Core : ILogCore;
END_VAR
]]></Declaration>
</Method>
Expand Down
8 changes: 4 additions & 4 deletions src/TcLogProj/TcLog/Logger/_Interfaces/ILogCore.TcIO
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Logs data in custom format. No additional formatting will be done.
METHOD LogCustomFormat : BOOL
VAR_INPUT
Data : Tc2_System.T_MaxString; // Data to be logged. No additional formatting will be done.
data : Tc2_System.T_MaxString; // Data to be logged. No additional formatting will be done.
END_VAR
]]></Declaration>
</Method>
Expand All @@ -22,9 +22,9 @@ END_VAR
// The message will only be logged if the logging level exceeds the configured minimum logging level.
METHOD LogStandardFormat : BOOL
VAR_INPUT
Data : Tc2_System.T_MaxString; // Data to be logged. Additional formatting wil be done.
InstancePath : Tc2_System.T_MaxString; // Instance path of calling logger to locate source of logging message.
LogLevel : LogLevels; // Log level of message.
data : Tc2_System.T_MaxString; // Data to be logged. Additional formatting wil be done.
instancePath : Tc2_System.T_MaxString; // Instance path of calling logger to locate source of logging message.
logLevel : LogLevels; // Log level of message.
END_VAR
]]></Declaration>
</Method>
Expand Down
2 changes: 1 addition & 1 deletion src/TcLogProj/TcLog/Logger/_Tests/TestWrapper_NET.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<POU Name="TestWrapper_NET" Id="{32780ead-f361-4f91-ae5e-047717d14d80}" SpecialFunc="None">
<Declaration><![CDATA[FUNCTION_BLOCK TestWrapper_NET
VAR
_coreLogger : TcLogCore(BufferSize:=50 * 50 * (UDINT_TO_DINT(MAX_STRING_LENGTH) + INT_TO_DINT(Constants.FifoOverhead)));
_coreLogger : TcLogCore(BufferSize:=50 * 50 * (UDINT_TO_DINT(Tc2_System.MAX_STRING_LENGTH) + INT_TO_DINT(Constants.FifoOverhead)));
_logger : TcLog;
_flushCache : BOOL;
Expand Down
4 changes: 2 additions & 2 deletions src/TcLogProj/TcLog/TcLog.plcproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<Implicit_Jitter_Distribution>{d696fa89-a5b7-4359-9420-e6a3f2f66b93}</Implicit_Jitter_Distribution>
<LibraryReferences>{e556042a-b034-4e51-bfa4-92060eb4b7b8}</LibraryReferences>
<Company>Benedikt Geisler</Company>
<Released>false</Released>
<Released>true</Released>
<Title>TcLog</Title>
<ProjectVersion>0.2.2</ProjectVersion>
<ProjectVersion>0.3.0</ProjectVersion>
<CombineIds>false</CombineIds>
<DefaultNamespace>TcLog</DefaultNamespace>
<Author>Benedikt Geisler</Author>
Expand Down
8 changes: 4 additions & 4 deletions src/TcLogProj/TcLog/Utils/DynamicStringBuffer.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ VAR_INST
currentBufferPos : UDINT;
fifoHeadString : Tc2_System.T_MaxString;
fifoHeadLength : UDINT;
fifoHeadBytes : ARRAY[0..Tc2_System.MAX_STRING_LENGTH] OF BYTE;
fifoHeadBytes : ARRAY[0..Tc2_System.Tc2_System.MAX_STRING_LENGTH] OF BYTE;
i : UINT;
END_VAR
VAR CONSTANT
NetId : STRING := '';
Timeout : TIME := DEFAULT_ADS_TIMEOUT;
MaxLogsPerCycle : UINT := DINT_TO_UINT(CONSTANTS.BufferSize / UDINT_TO_DINT(MAX_STRING_LENGTH));
MaxBufferPosition : UDINT := (SIZEOF(buffer)-MAX_STRING_LENGTH);
MaxLogsPerCycle : UINT := DINT_TO_UINT(CONSTANTS.BufferSize / UDINT_TO_DINT(Tc2_System.MAX_STRING_LENGTH));
MaxBufferPosition : UDINT := (SIZEOF(buffer)-Tc2_System.MAX_STRING_LENGTH);
END_VAR
]]></Declaration>
<Implementation>
Expand Down Expand Up @@ -279,7 +279,7 @@ VAR
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[requiredSize := _fifo.cbSize + (Tc2_System.MAX_STRING_LENGTH + INT_TO_UDINT(Constants.FifoOverhead));
<ST><![CDATA[requiredSize := _fifo.cbSize + (Tc2_System.Tc2_System.MAX_STRING_LENGTH + INT_TO_UDINT(Constants.FifoOverhead));
IF requiredSize > _fifo.cbBuffer THEN
_dynamicMemoryBuffer.Resize(nSize := requiredSize*SIZEOF(BYTE), bPreserve:=TRUE, bReset:=TRUE);
Expand Down
12 changes: 6 additions & 6 deletions src/TcLogProj/TcLog/Utils/GetFileAgeInSeconds.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<Declaration><![CDATA[{attribute 'hide'}
FUNCTION INTERNAL GetFileAgeInSeconds : DINT
VAR_INPUT
CurrentUtcTime : Tc2_Utilities.T_FILETIME;
FindFileEntry : Tc2_Utilities.ST_FindFileEntry;
currentUtcTime : Tc2_Utilities.T_FILETIME;
findFileEntry : Tc2_Utilities.ST_FindFileEntry;
END_VAR
VAR
_timeLastWriteAccess : Tc2_Utilities.T_ULARGE_INTEGER;
Expand All @@ -18,12 +18,12 @@ END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[// Local file time
_fileTimeAsULINT.dwLowPart := CurrentUtcTime.dwLowDateTime;
_fileTimeAsULINT.dwHighPart := CurrentUtcTime.dwHighDateTime;
_fileTimeAsULINT.dwLowPart := currentUtcTime.dwLowDateTime;
_fileTimeAsULINT.dwHighPart := currentUtcTime.dwHighDateTime;
// Write access is UTC
_timeLastWriteAccess.dwLowPart := FindFileEntry.lastWriteTime.dwLowDateTime;
_timeLastWriteAccess.dwHighPart := FindFileEntry.lastWriteTime.dwHighDateTime;
_timeLastWriteAccess.dwLowPart := findFileEntry.lastWriteTime.dwLowDateTime;
_timeLastWriteAccess.dwHighPart := findFileEntry.lastWriteTime.dwHighDateTime;
_fileTimeDifference := UInt64Sub64(_fileTimeAsULINT, _timeLastWriteAccess);
GetFileAgeInSeconds := LREAL_TO_DINT(UINT64_TO_LREAL(_fileTimeDifference)/(OneSecondInOneHundredNanoSecondsIntervals));]]></ST>
Expand Down
3 changes: 1 addition & 2 deletions src/TcLogProj/TcLog/Version/Global_Version.TcGVL
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
<Declaration><![CDATA[{attribute 'TcGenerated'}
{attribute 'no-analysis'}
{attribute 'linkalways'}
{attribute 'hide'}
// This function has been automatically generated from the project information.
VAR_GLOBAL CONSTANT
{attribute 'const_non_replaced'}
stLibVersion_TcLog : ST_LibVersion := (iMajor := 0, iMinor := 2, iBuild := 2, iRevision := 0, nFlags := 1, sVersion := '0.2.2');
stLibVersion_TcLog : ST_LibVersion := (iMajor := 0, iMinor := 3, iBuild := 0, iRevision := 0, nFlags := 1, sVersion := '0.3.0');
END_VAR
]]></Declaration>
</GVL>
Expand Down

0 comments on commit f69995a

Please sign in to comment.