Git Product home page Git Product logo

tclog's Introduction

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 : TcLogLib.TcLogCore(bufferSize := 100 * (Tc2_System.MAX_STRING_LENGTH + TcLogLib.Constants.FifoOverhead));
END_VAR

_coreLogger
  .WriteToAds()
  .WriteToFile('c:\logs\', 'sensor_data.txt')
  .MinimumLevel(TcLogLib.LogLevels.Debug)
  .RunLogger();

Then, maybe in a different POU, use TcLog to log messages:

VAR
  _logger: TcLogLib.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.

tclog's People

Contributors

bengeisler avatar seehma avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.