# Built in logger to a different file

**URL:** <https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252>\
**Category:** Ignition\
**Created:** [December 17, 2021, 3:57pm UTC](https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252 "2021-12-17T15:57:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [December 17, 2021, 3:57pm UTC](https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252/1 "2021-12-17T15:57:54Z")

</div>

I would like to use the built in logger to log data into a custom file. Is this possible? Or do I need to just build my own logger? Could I just build an instance of `LoggerEx` and provide it a file path in some way?

I would use the wrapper logs, however I need make sure these log files only have the content I am intending to log and the wrapper logs have too much extra in this case.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 17, 2021, 4:41pm UTC](https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252/2 "2021-12-17T16:41:20Z")

</div>

You could theoretically do this with `logback`, via the `logback.xml` file. You’d basically just hardcode your custom logger name to go to a specific file appender:

> <https://stackoverflow.com/questions/2488558/logback-to-log-different-messages-to-two-files/2489569#2489569>

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [December 17, 2021, 5:46pm UTC](https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252/3 "2021-12-17T17:46:43Z")

</div>

Okay so I think this is definitely what I am looking for. However for some reason I am struggling to get it to work, want to make sure its not ignitions implementation of `logback` that is affecting what I did.

I updated my logback.xml to include the following:  
**Appender:**

```xml
<appender name="CUSTOM-LOGGER-FILE" class="ch.qos.logback.core.FileAppender">
      <file>logs/custom-logger.log</file>
      <append>true</append>
      <encoder>
          <pattern>%.-1p [%-30c{1}] [%d{HH:mm:ss,SSS}]: %m %X%n</pattern>
      </encoder>
  </appender>

```

**Logger:**

```xml
 <logger name="custom-logger" level="TRACE" additivity="false">
      <appender-ref ref="CUSTOM-LOGGER-FILE"/>
  </logger>

```

> **Full logback.xml**
>
> ```xml
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <!-- For assistance related to logback-translator or configuration -->
> <!-- files in general, please contact the logback user mailing list -->
> <!-- at http://www.qos.ch/mailman/listinfo/logback-user -->
> <!-- -->
> <!-- For professional support please see -->
> <!-- http://www.qos.ch/shop/products/professionalSupport -->
> <!-- -->
> <configuration debug="true">
> <appender name="SysoutAppender" class="ch.qos.logback.core.ConsoleAppender">
> <encoder>
> <pattern>%.-1p [%-30c{1}] [%d{HH:mm:ss,SSS}]: %m %X%n</pattern>
> </encoder>
> </appender>
> <appender name="CUSTOM-LOGGER-FILE" class="ch.qos.logback.core.FileAppender">
> <file>logs/custom-logger.log</file>
> <append>true</append>
> <encoder>
> <pattern>%.-1p [%-30c{1}] [%d{HH:mm:ss,SSS}]: %m %X%n</pattern>
> </encoder>
> </appender>
> <appender name="DB" class="com.inductiveautomation.logging.SQLiteAppender">
> <dir>logs</dir>
> <!--
> Maintenance Settings
> entryLimit: The maximum number of entries in the database. However, at any given time, there may be more than this number, due to how cleanup works.
> maxEventsPerMaintenance: The number of event that can happen before a maintenance cycle occurs.
> minTimeBetweenMaintenance: The minimum time (max frequency) between maintenance events. Takes precedent over max events.
> vacuumFrequency: The number of maintenance cycles before a "vacuum" is performed, to recover disk space.
> 
> On disk, most log events are between 600-800 bytes.
> <entryLimit>50000</entryLimit>
> <maxEventsPerMaintenance>5000</maxEventsPerMaintenance>
> <minTimeBetweenMaintenance>60000</minTimeBetweenMaintenance>
> <vacuumFrequency>3</vacuumFrequency>
> -->
> </appender>
> <appender name="SysoutAsync" class="ch.qos.logback.classic.AsyncAppender" queueSize="1000" discardingThreshold="0">
> <appender-ref ref="SysoutAppender" />
> </appender>
> <appender name="DBAsync" class="ch.qos.logback.classic.AsyncAppender" queueSize="100000" discardingThreshold="0">
> <appender-ref ref="DB" />
> </appender>
> <logger name="custom-logger" level="TRACE" additivity="false">
> <appender-ref ref="CUSTOM-LOGGER-FILE"/>
> </logger>
> <root level="INFO">
> <appender-ref ref="SysoutAsync"/>
> <appender-ref ref="DBAsync"/>
> </root>
> </configuration>
> 
> ```

And then I tried to run this in both the script console and a perspective button to test different scopes:

```auto
logger = system.util.getLogger("custom-logger")
logger.trace("trace")
logger.debug("debug")
logger.info("info")
logger.warn("warn")
logger.error("error")

```

However I only get the logs when I do it from the perspective button, not the script console.

```auto
T [custom-logger] [17:40:52]: trace component=root/Button, view=Button@D, project-name=TEST
D [custom-logger] [17:40:52]: debug component=root/Button, view=Button@D, project-name=TEST
I [custom-logger] [17:40:52]: info component=root/Button, view=Button@D, project-name=TEST
W [custom-logger] [17:40:52]: warn component=root/Button, view=Button@D, project-name=TEST
E [custom-logger] [17:40:52]: error component=root/Button, view=Button@D, project-name=TEST

```

Any idea if there is something I have configured wrong that is not allowing it to work from the client scope as well?

Note: I did try using `ch.qos.logback.core.ConsoleAppender` instead of `ch.qos.logback.core.FileAppender` but then I couldn’t get anything to write to the file, so I used the `FileAppender` class mentioned in the above link.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 17, 2021, 5:50pm UTC](https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252/4 "2021-12-17T17:50:17Z")

</div>

`logback.xml` only controls logs on the gateway. When you execute something in the script console, that’s happening on your local JVM where the designer is running.  
Perspective scripts are actually executing on the gateway, though, so you’ll end up with the right results.

If you want to automatically send logs from clients/designers to the gateway logs, you could do that (with a different pattern), but, y’know, [be careful](https://forum.inductiveautomation.com/t/apache-log4j-vulnerability-cve-2021-44228/54050/12).

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [December 17, 2021, 5:52pm UTC](https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252/5 "2021-12-17T17:52:58Z")

</div>

> [@paul-griffith](#):
>
> but, y’know, [be careful](https://forum.inductiveautomation.com/t/apache-log4j-vulnerability-cve-2021-44228/54050/12).

lol, I think I'll be good with gateway scoped logs 😉

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [December 17, 2021, 6:12pm UTC](https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252/6 "2021-12-17T18:12:17Z")

</div>

Just a check for future safety, will an upgrade possible blow this away?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 17, 2021, 6:12pm UTC](https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252/7 "2021-12-17T18:12:44Z")

</div>

I don’t think so, I’m pretty sure the `logback.xml` should be preserved in your .gwbk.

---

<div class="post-metadata">

**Author:** ![WPhan](https://avatars.discourse-cdn.com/v4/letter/w/82dd89/32.png) [@WPhan](https://forum.inductiveautomation.com/u/WPhan)\
**Post date:** [February 28, 2022, 1:42pm UTC](https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252/8 "2022-02-28T13:42:34Z")

</div>

@paul-griffith I was looking over this article. At the bottom, Steven mentions at the bottom that logback.xml is not contained in .gwbk. [How To Migrate the Ignition Loggers using Logback.XML – Inductive Automation Help Center](https://support.inductiveautomation.com/hc/en-us/articles/4420375030029)

Can anyone confirm that logback settings are in the .gwbk? If not can it be added in future release?

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [February 28, 2022, 4:57pm UTC](https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252/9 "2022-02-28T16:57:27Z")

</div>

̶T̶h̶e̶y̶ ̶a̶r̶e̶ ̶i̶n̶ ̶i̶t̶,̶ ̶I̶ ̶h̶a̶v̶e̶ ̶b̶e̶e̶n̶ ̶u̶s̶i̶n̶g̶ ̶t̶h̶a̶t̶ ̶t̶o̶ ̶m̶o̶v̶e̶ ̶i̶t̶ ̶a̶r̶o̶u̶n̶d̶ ̶t̶o̶ ̶o̶t̶h̶e̶r̶ ̶d̶e̶v̶e̶l̶o̶p̶m̶e̶n̶t̶ ̶g̶a̶t̶e̶w̶a̶y̶s̶

EDIT: I was not thinking, listen to Paul 🙂

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 28, 2022, 5:25pm UTC](https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252/10 "2022-02-28T17:25:55Z")

</div>

I’m not sure they are (at least, I don’t see why they would be from the current state of the code) but I filed a ticket to ensure that they _are_, so either we’ll make necessary changes or someone else will prove me wrong 🙂

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [February 28, 2022, 5:45pm UTC](https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252/11 "2022-02-28T17:45:22Z")

</div>

Oh wait you’re right! I actually have left a copy in my projects folder since that’s the folder I manage with `git` and move it that way. My bad I forgot that we had git automatically handling that guy as well!

---

<div class="post-metadata">

**Author:** ![WPhan](https://avatars.discourse-cdn.com/v4/letter/w/82dd89/32.png) [@WPhan](https://forum.inductiveautomation.com/u/WPhan)\
**Post date:** [May 3, 2022, 6:45pm UTC](https://forum.inductiveautomation.com/t/built-in-logger-to-a-different-file/54252/12 "2022-05-03T18:45:12Z")

</div>

[Ignition Release Notes for Version 8.1.17-rc1 | Inductive Automation](https://inductiveautomation.com/downloads/releasenotes/8.1.17-rc1)

Starting in 8.1.17, looks like logback is now included in .gwbk file.
