Skip to content

bengeisler/TcLog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 * (Tc2_System.MAX_STRING_LENGTH + Constants.FifoOverhead));
END_VAR

_coreLogger
  .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);
END_VAR

_logger
  .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 🚀

  • Log to ADS output
  • Log to file system
  • Fluent interface for easy configuration and usage
  • Specification of minimum log level
  • Set rolling interval for log files
  • Delete old log files automatically
  • Dynamically expanding log buffer
  • Log messages with or without timestamp
  • Custom log message formatting

🧪 Tests 🧪

The project contains both unit (TcUnit) and integration tests (xUnit).

Install TcLog

See the installation guide for instructions on how to install TcLog.

Getting started

Get quickly up and running with TcLog: Get Started

API reference

Find the full API reference here.

License

The library is licensed under the MIT License.

Contributing

Contributions are welcome. Please see the contribution guide for details.

Further ways of logging in TwinCAT

With log4TC there is another logging option for TwinCAT. This enables structured logging, but an additional Windows service must be installed, which communicates with the PLC library. TcLog on the other hand comes as a pure PLC library. The code for log4TC has been published as open source on GitHub.

Disclaimer

This project is not affiliated with Beckhoff Automation GmbH & Co. KG and was first published in 2021 at my blog.