# \[SOLVED\] Logging client scoped events to gateway

**URL:** <https://forum.inductiveautomation.com/t/solved-logging-client-scoped-events-to-gateway/37330>\
**Category:** Ignition\
**Created:** [August 3, 2020, 6:34pm UTC](https://forum.inductiveautomation.com/t/solved-logging-client-scoped-events-to-gateway/37330 "2020-08-03T18:34:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [August 3, 2020, 6:34pm UTC](https://forum.inductiveautomation.com/t/solved-logging-client-scoped-events-to-gateway/37330/1 "2020-08-03T18:34:54Z")

</div>

Good afternoon,

I log events (info and errors) in several places of my code. Some of those errors go to the gateway and some go to the client. I want to move all client logs so they appear in the gateway.

Is there a setting I should look under? Or is this a feature of Ignition that events go their separate way depending on where they are run from?

One solution I've found on the forums is log my errors and info to a database.

> [@Logging Messages to aid debugging](http://forum.inductiveautomation.com/t/logging-messages-to-aid-debugging/7460/4):
>
> You could write directly to a database table when you wanted to log something. This would work in all contexts: message = "My latest log message" severity = "info" system.db.runPrepUpdate("INSERT INTO logging (Message,Severity) VALUES (?,?)",[message,info]) Probably best to write a function that wraps the database insert so you could just pass the message and severity to the function as arguments. The only downside to this method is that in the client it takes a bit of time to run a database q…

Any thoughts on the subject are appreciated.

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [August 4, 2020, 5:36am UTC](https://forum.inductiveautomation.com/t/solved-logging-client-scoped-events-to-gateway/37330/2 "2020-08-04T05:36:52Z")

</div>

You can use [system.util.sendMessage](https://docs.inductiveautomation.com/display/DOC80/system.util.sendMessage) in your code to send your log info from the client to the gateway and create the log there with [system.util.getLogger](https://docs.inductiveautomation.com/display/DOC80/system.util.getLogger). If you have code that is executed in both client and gateway contexts, I’m guessing this would work in code that executes on the gateway too (sending the log message to itself). But I haven’t tested that case. Here’s an example of a gateway message handler for this:

```auto
def handleMessage(payload):
	"""
	This message handler will be called each time a message of this
	type is received.

	Arguments:
		payload: A dictionary that holds the objects passed to this
		         message handler. Retrieve them with a subscript, e.g.
		         myObject = payload['argumentName']
	"""
	logger = system.util.getLogger(payload['loggerName'])
	if payload['level'] == 'fatal':
		logger.fatal(payload['message'])
	elif payload['level'] == 'error':
		logger.error(payload['message'])
	elif payload['level'] == 'warn':
		logger.warn(payload['message'])
	elif payload['level'] == 'info':
		logger.info(payload['message'])
	elif payload['level'] == 'debug':
		logger.debug(payload['message'])
	elif payload['level'] == 'trace':
		logger.trace(payload['message'])

```

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [August 4, 2020, 12:43pm UTC](https://forum.inductiveautomation.com/t/solved-logging-client-scoped-events-to-gateway/37330/3 "2020-08-04T12:43:26Z")

</div>

That is remarkably useful… I found this vido on the subject for anyone who doesn’t understand.

[https://inductiveuniversity.com/videos/script-messaging/8.0](https://inductiveuniversity.com/videos/script-messaging/8.0)

---

<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:** [August 4, 2020, 12:53pm UTC](https://forum.inductiveautomation.com/t/solved-logging-client-scoped-events-to-gateway/37330/4 "2020-08-04T12:53:19Z")

</div>

> [@witman](#):
>
> logger = system.util.getLogger(payload['loggerName']) if payload['level'] == 'fatal': logger.fatal(payload['message'])

Psst! Try this:

```auto
	logger = system.util.getLogger(payload['loggerName'])
	m = getattr(logger, payload['level'])
	m(payload['message'])

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 16, 2021, 4:02am UTC](https://forum.inductiveautomation.com/t/solved-logging-client-scoped-events-to-gateway/37330/5 "2021-11-16T04:02:19Z")

</div>

ahem, you could also use:

```auto
def handleMessage(payload):
	"""
	This message handler will be called each time a message of this
	type is received.

	Arguments:
		payload: A dictionary that holds the objects passed to this
		         message handler. Retrieve them with a subscript, e.g.
		         myObject = payload['argumentName']
	"""
	logger = system.util.getLogger(payload['loggerName'])
	getattr(logger, payload['level'])(payload['message'])

```

Edit:  
Oh, @pturmel beat me to it… by a year. Sounds about right 😂
