Skip to content

Commit

Permalink
Merge branch 'zeugwerk-docs' into doc/custom-doc-folder
Browse files Browse the repository at this point in the history
  • Loading branch information
bengeisler authored Sep 18, 2023
2 parents 94a0f3b + 1ff0545 commit f8ab258
Show file tree
Hide file tree
Showing 32 changed files with 742 additions and 1,037 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- main
paths:
- 'docs/**'
- 'TcLog/**'
- 'src/**'
pull_request:
workflow_dispatch:
jobs:
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Please make sure that your pull request
#### TwinCAT and Visual Studio
The project uses TwinCAT 3.1.4024.29 and Visual Studio 2019 with .NET 7.0.

Please use the recommended [Zeugwerk IDE settings.](https://doc.zeugwerk.dev/contribute/recom_xae_settings.html)

#### Unit tests

[TcUnit](https://tcunit.org/) is used for unit tests in plc project itself.
Expand Down
39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
![](docs/images/TcLog_header.svg "TcLog_header")
![](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:

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;
_myInt : INT := 10;
_myVarInfo : __SYSTEM.VAR_INFO := __VARINFO(_myInt);
_logger: TcLog;
_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('');
```
This will log both messages to both the ADS output and the file system.

**Features**
🚀 **Features** 🚀

- Log to ADS output
- Log to file system
- Fluent interface for easy configuration and usage
Expand All @@ -43,16 +44,18 @@ This will log both messages to both the ADS output and the file system.
- Log messages with or without timestamp
- Custom log message formatting

🧪 **Tests** 🧪

The project contains both unit ([TcUnit](https://tcunit.org)) and integration tests ([xUnit](https://xunit.net)).

## Install TcLog
See the [installation guide](docs/userguide/installation.html) for instructions on how to install TcLog.
See the [installation guide](https://bengeisler.github.io/TcLog/userguide/installation.html) for instructions on how to install TcLog.

## Getting started
Get quickly up and running with TcLog: [Get Started](docs/userguide/getting_started.html)
Get quickly up and running with TcLog: [Get Started](https://bengeisler.github.io/TcLog/userguide/getting_started.html)

## API reference
Find the full API reference [here](docs/reference/TcLog/Constants.html).
Find the full API reference [here](https://bengeisler.github.io/TcLog/reference/TcLog/Constants.html).

## License
The library is licensed under the [MIT License](LICENSE).
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ TcLog offers with `.IncludeInstancePath()` the possibility to include the locati

```
_coreLogger
.WriteToAds()
.IncludeInstancePath()
.MinimumLevel(LogLevels.Warning)
.RunLogger();
.WriteToAds()
.IncludeInstancePath()
.MinimumLevel(LogLevels.Warning)
.RunLogger();
_logger.Error('This is an error message.');
```

Expand All @@ -36,14 +36,14 @@ TcLog brings the option to store logs in the file system in the form of text fil

```
_coreLogger
.IncludeInstancePath()
.MinimumLevel(LogLevels.Warning)
.WriteToFile('c:\logs\', 'test.txt')
.RunLogger();
.IncludeInstancePath()
.MinimumLevel(LogLevels.Warning)
.WriteToFile('c:\logs\', 'test.txt')
.RunLogger();
_loggerTrig
.OnRisingEdge(_log)
.Error('rTrig Test');
.OnRisingEdge(_log)
.Error('rTrig Test');
```

![Logging to the file system](https://benediktgeisler.de/LogMessageInFiileSystem.png "Logging to the file system")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@ As wrapper we use an function block that encapsulates `TcLog` and enforces the d
```
FUNCTION_BLOCK UserLog IMPLEMENTS ILog
VAR_INPUT
Condition: BOOL;
Identification: STRING;
Value: REAL;
Unit: STRING;
Condition: BOOL;
Identification: STRING;
Value: REAL;
Unit: STRING;
END_VAR
VAR
_getTimeData: DateTime;
_timestamp: STRING;
_getTimeData: DateTime;
_timestamp: STRING;
END_VAR
VAR_STAT
_logger: TcLog;
_logger: TcLog;
END_VAR
_getTimeData();
_timestamp := _getTimeData.ToString('hh:mm:ss');
_logger
.OnCondition(Condition)
.AppendString(_timestamp)
.AppendString(';')
.AppendString(Identification)
.AppendString(';')
.AppendAny(Value)
.AppendString(';')
.AppendString(Unit)
.ToCustomFormat('');
.OnCondition(Condition)
.AppendString(_timestamp)
.AppendString(';')
.AppendString(Identification)
.AppendString(';')
.AppendAny(Value)
.AppendString(';')
.AppendString(Unit)
.ToCustomFormat('');
```

We can use the helper function `GenerateTimeData`, which returns the current date and time formatted via the `.ToString(Format)` method. With its help we generate the timestamp of the sensor data.
Expand All @@ -60,7 +60,7 @@ The interface is implemented by passing the logger reference to the `TcLog` inst
```
METHOD SetLogger : BOOL
VAR_INPUT
ref2Core : REFERENCE TO TcLogCore;
ref2Core : REFERENCE TO TcLogCore;
END_VAR
_logger.SetLogger(ref2Core);
Expand All @@ -72,35 +72,35 @@ Somewhere in our program `TcLogCore` is called cyclically. If there is more than

```
VAR
_newLogger: TcLogCore;
_rTrigLog : R_TRIG;
_log : BOOL;
_myLog : UserLog;
_myValue: REAL := 1.0;
_myValue2: REAL := 2.0;
_newLogger: TcLogCore;
_rTrigLog : R_TRIG;
_log : BOOL;
_myLog : UserLog;
_myValue: REAL := 1.0;
_myValue2: REAL := 2.0;
END_VAR
_newLogger
.MinimumLevel(LogLevels.Information)
.SetRollingInterval(RollingIntervals.Hourly)
.WriteToFile('c:\logs\', 'sensor.csv')
.DeleteLogFilesAfterDays(1)
.RunLogger();
.MinimumLevel(LogLevels.Information)
.SetRollingInterval(RollingIntervals.Hourly)
.WriteToFile('c:\logs\', 'sensor.csv')
.DeleteLogFilesAfterDays(1)
.RunLogger();
_myLog.SetLogger(_newLogger);
_rTrigLog(CLK := _log);
_myLog(
Condition := _rTrigLog.Q,
Condition := _rTrigLog.Q,
Identification := '+CC1-B31',
Value := _myValue,
Unit := '°C');
Value := _myValue,
Unit := '°C');
_myLog(
Condition := _rTrigLog.Q,
Identification := '+CC1-B32',
Value := _myValue2,
Unit := '°C');
Condition := _rTrigLog.Q,
Identification := '+CC1-B32',
Value := _myValue2,
Unit := '°C');
```

As soon as logging is triggered via `_log`, the csv file and the entries in it are created:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ END_VAR
_coreLogger
.WriteToAds()
.WriteToFile('c:\logs\', 'sensor_data.txt')
.WriteToFile('c:\logs\', 'sensor_data.txt')
.MinimumLevel(LogLevels.Debug)
.RunLogger();
```
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# 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:

Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions docs/userguide/toc.yml → documentation/userguide/toc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
- name: Installation
href: installation.md
- name: User Guide
href: getting_started.md
- name: User guide
items:
- name: Getting started
Expand Down
18 changes: 0 additions & 18 deletions src/TcLog.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,6 @@ Global
{84E2C694-C6B7-48C0-A46A-93E9E79E1E4B}.Release|TwinCAT RT (x64).Build.0 = Release|TwinCAT RT (x64)
{84E2C694-C6B7-48C0-A46A-93E9E79E1E4B}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86)
{84E2C694-C6B7-48C0-A46A-93E9E79E1E4B}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Debug|Any CPU.ActiveCfg = Debug|TwinCAT OS (ARMT2)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Debug|TwinCAT CE7 (ARMV7).ActiveCfg = Debug|TwinCAT CE7 (ARMV7)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Debug|TwinCAT CE7 (ARMV7).Build.0 = Debug|TwinCAT CE7 (ARMV7)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Debug|TwinCAT OS (ARMT2).ActiveCfg = Debug|TwinCAT OS (ARMT2)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Debug|TwinCAT OS (ARMT2).Build.0 = Debug|TwinCAT OS (ARMT2)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Debug|TwinCAT RT (x64).ActiveCfg = Debug|TwinCAT RT (x64)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Debug|TwinCAT RT (x64).Build.0 = Debug|TwinCAT RT (x64)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Debug|TwinCAT RT (x86).ActiveCfg = Debug|TwinCAT RT (x86)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Debug|TwinCAT RT (x86).Build.0 = Debug|TwinCAT RT (x86)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Release|Any CPU.ActiveCfg = Release|TwinCAT OS (ARMT2)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Release|TwinCAT CE7 (ARMV7).ActiveCfg = Release|TwinCAT CE7 (ARMV7)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Release|TwinCAT CE7 (ARMV7).Build.0 = Release|TwinCAT CE7 (ARMV7)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Release|TwinCAT OS (ARMT2).ActiveCfg = Release|TwinCAT OS (ARMT2)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Release|TwinCAT OS (ARMT2).Build.0 = Release|TwinCAT OS (ARMT2)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Release|TwinCAT RT (x64).ActiveCfg = Release|TwinCAT RT (x64)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Release|TwinCAT RT (x64).Build.0 = Release|TwinCAT RT (x64)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86)
{4D70D393-C90D-46C3-86AE-BDC75C79053F}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86)
{534B7BB3-9B49-4F2B-86CC-2317930EA23D}.Debug|Any CPU.ActiveCfg = Debug|TwinCAT RT (x64)
{534B7BB3-9B49-4F2B-86CC-2317930EA23D}.Debug|Any CPU.Build.0 = Debug|TwinCAT RT (x64)
{534B7BB3-9B49-4F2B-86CC-2317930EA23D}.Debug|TwinCAT CE7 (ARMV7).ActiveCfg = Debug|TwinCAT CE7 (ARMV7)
Expand Down
24 changes: 10 additions & 14 deletions src/TcLogProj/TcLog/Logger/LogLevelToAdsLogMsgType.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@
<POU Name="LogLevelToAdsLogMsgType" Id="{c5255ff0-b51b-42de-ab62-e7b30a9b316a}" SpecialFunc="None">
<Declaration><![CDATA[FUNCTION INTERNAL LogLevelToAdsLogMsgType : DWORD
VAR_INPUT
logLevel : LogLevels;
logLevel : LogLevels;
END_VAR
VAR
_retVal : DWORD;
_retVal : DWORD;
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[CASE logLevel OF
LogLevels.Debug, LogLevels.Information:
_retVal := Tc2_System.ADSLOG_MSGTYPE_HINT;
LogLevels.Warning:
_retVal := Tc2_System.ADSLOG_MSGTYPE_WARN;
LogLevels.Error, LogLevels.Fatal:
_retVal := Tc2_System.ADSLOG_MSGTYPE_ERROR;
ELSE
_retVal := Tc2_System.ADSLOG_MSGTYPE_HINT;
LogLevels.Debug, LogLevels.Information:
_retVal := Tc2_System.ADSLOG_MSGTYPE_HINT;
LogLevels.Warning:
_retVal := Tc2_System.ADSLOG_MSGTYPE_WARN;
LogLevels.Error, LogLevels.Fatal:
_retVal := Tc2_System.ADSLOG_MSGTYPE_ERROR;
ELSE
_retVal := Tc2_System.ADSLOG_MSGTYPE_HINT;
END_CASE
LogLevelToAdsLogMsgType := _retVal;]]></ST>
</Implementation>
<LineIds Name="LogLevelToAdsLogMsgType">
<LineId Id="53" Count="10" />
<LineId Id="2" Count="0" />
</LineIds>
</POU>
</TcPlcObject>
Loading

0 comments on commit f8ab258

Please sign in to comment.