# Project-Wide Logger

**URL:** <https://forum.inductiveautomation.com/t/project-wide-logger/81305>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [November 1, 2023, 2:23pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305 "2023-11-01T14:23:44Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 1, 2023, 2:23pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/1 "2023-11-01T14:23:44Z")

</div>

I have a project script library that I would like to use one common logger for, but I can't seem to get the syntax correct.

I think the issue is that I need to be able to define the logger before calling `system.util.getLogger()` so that it's available at the global level.

I tried

```auto
logger = system.util.getLogger('Navigation')

```

But of course that didn't work because it was outside of a function, so it's not called and the logger is never created.

Then I tried.

```auto
logger
def startLogger():
	Navigation.logger = system.util.getLogger('Navigation')

```

and calling Navigation.startLogger() on client startup, but I get a 'logger not defined' error.

Is this possible to do so that I can have multiple scripts log to the same logger without using `system.util.getLogger()` in every function?

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [November 1, 2023, 2:26pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/2 "2023-11-01T14:26:59Z")

</div>

Putting it at the top of the script library file should definitely work, it runs once on scripting restart (basically whenever you save a script anywhere) and would define it then.

It's how I do all my logging in library scripts:

```auto
logger = system.util.getLogger('FCRM.Project.Library')

#rest of file

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 1, 2023, 2:28pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/3 "2023-11-01T14:28:12Z")

</div>

You don’t need a common instance, just getting the logger by the same name is enough.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 1, 2023, 2:29pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/4 "2023-11-01T14:29:02Z")

</div>

Yes, but I'd rather just call ` logger = system.util.getLogger('Navigation')` once and then use `Navigation.logger('text')` throughout.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [November 1, 2023, 2:29pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/5 "2023-11-01T14:29:08Z")

</div>

I hate retyping the name (and it's error-prone for my clumsy fingers) so I like to define it once.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 1, 2023, 2:30pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/6 "2023-11-01T14:30:44Z")

</div>

When I do it this way I get a `'com.inductiveautomation.ignition.common.util.LoggerEx' object is not callable` error

Do you specify file.logger or just use logger? - same error either way

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 1, 2023, 2:31pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/7 "2023-11-01T14:31:42Z")

</div>

Because that’s just the logger instance. The log methods are info, debug, warn, etc…

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 1, 2023, 2:32pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/8 "2023-11-01T14:32:05Z")

</div>

🤦‍♂️

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [November 1, 2023, 2:36pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/9 "2023-11-01T14:36:21Z")

</div>

Good catch, Kevin, I actually didn't notice that usage in the earlier post.  
Also, you don't need to use `foo.logger` as the namespace is already implied to be the same library script you're referring to it from.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 1, 2023, 3:27pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/10 "2023-11-01T15:27:36Z")

</div>

I tend to put this at the top of my scripts:

```auto
logger = system.util.getLogger(system.util.getProjectName() + '.' + __name__ )

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 1, 2023, 4:10pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/11 "2023-11-01T16:10:34Z")

</div>

I think he wants to be able to call it anywhere, not just the script where it was defined.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 1, 2023, 4:14pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/12 "2023-11-01T16:14:21Z")

</div>

Both, actually.

It can be called from within the library where it is defined using `logger.info()` and outside of that library using `Library.logger.info()`. Technically, it can also be called within the library using `Library.logger.info()`, it's just redundant.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 1, 2023, 4:25pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/13 "2023-11-01T16:25:50Z")

</div>

> [@pascal.fragnoud](#):
>
> not just the script where it was defined.

Ewww! Then you struggle to find the source of a particular log entry.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 1, 2023, 4:37pm UTC](https://forum.inductiveautomation.com/t/project-wide-logger/81305/14 "2023-11-01T16:37:27Z")

</div>

You could, yes but the only other place I'm using it is on the docked navigation page.
