TeamCity 9.0 Help

Plugin Development FAQ

How to Use Logging

The TeamCity code uses the Log4j logging library with a centralized configuration on the server and agent. Logging is usually done via a utility wrapper com.intellij.openapi.diagnostic.Logger rather than the default Log4j classes. You can use the class to get instances of the Loggers, e.g. use jetbrains.buildServer.log.Loggers.SERVER to add a message to the teamcity-server.log file.

For plugin-specific logging it is recommended to log into a log category matching the full name of your class. This is usually achieved by defining the logger field in a class as private static Logger LOG = Logger.getInstance(YourClass.class.getName()); If your plugin source code is located under the jetbrains.buildServer package, the logging will automatically go into teamcity-server.log. If you use another package, you might need to add a corresponding category handling into the conf/teamcity-server-log4j.xml file (mentioned at TeamCity Server Logs) or the corresponding agent file.

For debugging you might consider creating a customized Log4j configuration file and put it as a logging preset into <TeamCity Data Directory>\config\ TeamCity Server Logsdirectory. This way one will be able to activate the preset via the Administration | Diagnostics page, Troubleshooting tab.

Example:

Provided you have my.plugin.package.MyCurrentClassName class and want to log into teamcity-myPlugin.log file:

package my.plugin.package; class MyCurrentClassName { private static final com.intellij.openapi.diagnostic.Logger LOG = com.intellij.openapi.diagnostic.Logger.getInstance(MyCurrentClassName.class.getName()); void test(){ LOG.info("Initialized!"); } }

Edit <TeamCity server home>\conf\teamcity-server-log4j.xml file to add in the middle of it:

<appender name="MY_PLUGIN.LOG" class="jetbrains.buildServer.util.TCRollingFileAppender"> <param name="file" value="${teamcity_logs}teamcity-myPlugin.log"/> <param name="maxBackupIndex" value="3"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="[%d] %6p [%15.15t] - %30.30c - %m %n"/> </layout> </appender> <category name="my.plugin.package" additivity="false"> <priority value="INFO"/> <appender-ref ref="MY_PLUGIN.LOG"/> </category>
Last modified: 20 April 2023