Skip to content

Commit

Permalink
Merged zeugwerk-docs into main
Browse files Browse the repository at this point in the history
  • Loading branch information
bengeisler committed Sep 18, 2023
1 parent ed86ab8 commit d99617a
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 421 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ jobs:
with:
username: ${{ secrets.ACTIONS_ZGWK_USERNAME }}
password: ${{ secrets.ACTIONS_ZGWK_PASSWORD }}
filepath: "src/TcLogProj/TcLog/TcLog.plcproj"
filepath: "."
doc-folder: "docs"
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: archive/documentation/html
publish_dir: archive/docs/html
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
![](documentation/images/TcLog_header.svg "TcLog_header")

*Logging in TwinCAT with the on-board means is limited to the output as ADS event. The TcLog library presented here enables flexible logging to the file system.*

It's usage is as simple as this:
Expand Down Expand Up @@ -68,4 +69,4 @@ With [log4TC](https://mbc-engineering.github.io/log4TC/index.html) there is anot
The code for log4TC has been published as open source on [GitHub](https://github.com/mbc-engineering/log4TC/releases).

## Disclaimer
This project is not affiliated with Beckhoff Automation GmbH & Co. KG and was first published in 2021 at [my blog](https://benediktgeisler.de/en/blog/tclog/).
This project is not affiliated with Beckhoff Automation GmbH & Co. KG and was first published in 2021 at [my blog](https://benediktgeisler.de/en/blog/tclog/).
16 changes: 8 additions & 8 deletions documentation/userguide/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ You would typically call `TcLogCore` once in your project and configure the logg
Configure the core logger in your project:
```
VAR
_coreLogger : TcLogCore(bufferSize := 100 * SIZEOF(BYTE) * MAX_STRINGLENGTH);
_coreLogger : TcLogCore(bufferSize := 100 * SIZEOF(BYTE) * MAX_STRINGLENGTH);
END_VAR
_coreLogger
.WriteToAds()
.WriteToFile('c:\logs\', 'sensor_data.txt')
.MinimumLevel(LogLevels.Debug)
.RunLogger();
.WriteToAds()
.WriteToFile('c:\logs\', 'sensor_data.txt')
.MinimumLevel(LogLevels.Debug)
.RunLogger();
```
Then, maybe in a different POU, use `TcLog` to log messages:
```
VAR
_logger : TcLog;
_logger : TcLog;
END_VAR
_logger.Debug('This is a debug message.');
_logger.Error('This is an error message.');
_logger.Debug('This is a debug message.');
_logger.Error('This is an error message.');
```
This will log both messages to both the ADS output and the file system.

Expand Down
52 changes: 27 additions & 25 deletions documentation/userguide/logging.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Logging
Next, we will look at the logging options of TcLog.

## Flexible logging
TcLog implements a [StringBuilder](https://www.plccoder.com/fluent-code/) which makes it easy to build your own message text:

```
VAR
_logger: TcLog;
_myInt : INT := 10;
_myVarInfo : __SYSTEM.VAR_INFO := __VARINFO(_myInt);
_myInt : INT := 10;
_myVarInfo : __SYSTEM.VAR_INFO := __VARINFO(_myInt);
END_VAR
_logger
.AppendString('Let´s log some values: ')
.AppendAny(_myInt)
.AppendString(' - or some symbols: ')
.AppendVariable(_myVarInfo, _myInt)
.Error('');
.AppendString('Let´s log some values: ')
.AppendAny(_myInt)
.AppendString(' - or some symbols: ')
.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")

Expand All @@ -30,28 +32,28 @@ The most common use of logging will be in the form `IF ... THEN log() END_IF`. T
```
VAR
_logger: TcLog;
_triggerLogging : R_TRIG;
_log : BOOL;
_triggerLogging : R_TRIG;
_log : BOOL;
END_VAR
_triggerLogging(CLK := _log);
_logger
.OnCondition(_triggerLogging.Q)
.Error('Only logs when OnCondition evaluates to TRUE.');
.OnCondition(_triggerLogging.Q)
.Error('Only logs when OnCondition evaluates to TRUE.');
```

## Logging on rising/falling edges
Since a log message is usually to be sent once in the event of a *status change*, TcLog also provides a block for this purpose: `TcLogTrig`. In contrast to `TcLog`, a separate instance must be created for each use of this block, since the edge state is stored internally. The conditional execution can thus be further simplified:

```
VAR
_loggerTrig : TcLogTRIG;
_loggerTrig : TcLogTRIG;
_log : BOOL;
END_VAR
_loggerTrig
.OnRisingEdge(_log)
.Error('rTrig Test');
.OnRisingEdge(_log)
.Error('rTrig Test');
```

Likewise, logging can be triggered on falling edges with `OnFallingEdge(cond)`.
Expand All @@ -61,24 +63,24 @@ Even though the logger was primarily designed as a singleton, it is possible to

```
VAR
_newLogger: TcLogCore;
_logger: TcLog;
_myInt : INT := 10;
_newLogger: TcLogCore;
_logger: TcLog;
_myInt : INT := 10;
END_VAR
_newLogger
.MinimumLevel(LogLevels.Information)
.SetRollingInterval(RollingIntervals.Hourly)
.WriteToFile('c:\logs\', 'sensor_data.txt')
.DeleteLogFilesAfterDays(7)
.RunLogger();
.MinimumLevel(LogLevels.Information)
.SetRollingInterval(RollingIntervals.Hourly)
.WriteToFile('c:\logs\', 'sensor_data.txt')
.DeleteLogFilesAfterDays(7)
.RunLogger();
// Bind the new logger to the TcLog instance
_logger.SetLogger(_newLogger);
_logger.AppendString('Sensor xy: ')
.AppendAny(_myInt)
.Information('');
.AppendAny(_myInt)
.Information('');
```

From now on `_logger` considers the configuration of `_newLogger`.
4 changes: 0 additions & 4 deletions src/TcLogProj/TcLog/Logger/LogLevelToAdsLogMsgType.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,5 @@ END_CASE
LogLevelToAdsLogMsgType := _retVal;]]></ST>
</Implementation>
<LineIds Name="LogLevelToAdsLogMsgType">
<LineId Id="53" Count="10" />
<LineId Id="2" Count="0" />
</LineIds>
</POU>
</TcPlcObject>
60 changes: 0 additions & 60 deletions src/TcLogProj/TcLog/Logger/TcLog.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -348,65 +348,5 @@ END_IF
_logDataInitialized := FALSE;]]></ST>
</Implementation>
</Method>
<LineIds Name="TcLog">
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.AppendAny">
<LineId Id="3" Count="3" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.AppendString">
<LineId Id="3" Count="3" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.AppendVariable">
<LineId Id="86" Count="12" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.Debug">
<LineId Id="3" Count="7" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.Error">
<LineId Id="3" Count="8" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.Fatal">
<LineId Id="3" Count="7" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.Information">
<LineId Id="3" Count="7" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.Init">
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.InitializeLogData">
<LineId Id="3" Count="4" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.OnCondition">
<LineId Id="3" Count="3" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.SetLogger">
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.ShortenInstancePath">
<LineId Id="3" Count="19" />
</LineIds>
<LineIds Name="TcLog.ToAdsLog">
<LineId Id="3" Count="5" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.ToCustomFormat">
<LineId Id="3" Count="7" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="TcLog.Warning">
<LineId Id="3" Count="7" />
<LineId Id="2" Count="0" />
</LineIds>
</POU>
</TcPlcObject>
Loading

0 comments on commit d99617a

Please sign in to comment.