{"id":2645,"date":"2019-05-09T09:19:12","date_gmt":"2019-05-09T08:19:12","guid":{"rendered":"http:\/\/www.robertprice.co.uk\/robblog\/?p=2645"},"modified":"2019-05-09T09:19:14","modified_gmt":"2019-05-09T08:19:14","slug":"logging-from-a-mendix-java-action","status":"publish","type":"post","link":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/","title":{"rendered":"Logging from a Mendix Java action"},"content":{"rendered":"<p>It is a common requirement to be able to log data from an application. Mendix has a good logging system built in, but how do we access this from a custom Java action?<\/p>\n<p>The Mendix development team have already thought of this, and have provided a method called <a href=\"https:\/\/apidocs.mendix.com\/7\/runtime\/com\/mendix\/core\/Core.html#getLogger-java.lang.String-\">getLogger<\/a> in the Core.<\/p>\n<p>To use the logger from a Java action, we first need to add a couple of imports.<\/p>\n<pre>import com.mendix.core.Core;\nimport com.mendix.logging.ILogNode;\n<\/pre>\n<p>Now we need to provide access to the logger. We can do this by providing a static variable which we&#8217;ll call <var>LOG<\/var>. We use the getLogger method we mentioned earlier, passing in the name of the log node name we want to use. In this case, we&#8217;ll use &#8220;RobTest&#8221; as the log node name.<\/p>\n<pre>\/\/ BEGIN EXTRA CODE\npublic static ILogNode LOG = Core.getLogger(\"RobTest\");\n\/\/ END EXTRA CODE\n<\/pre>\n<p>Now, this is in place, we can access <var>LOG<\/var> from elsewhere in our Java action.<\/p>\n<p>Let&#8217;s say our action wants to log when it starts and also wants to list all the microflows available within the App. We can change the log levels, so the start notification is at &#8220;info&#8221; level, and the microflows are at &#8220;debug&#8221; level. We can do this using the following.<\/p>\n<pre>public java.lang.Boolean executeAction() throws Exception\n{\n    \/\/ BEGIN USER CODE\n    LOG.info(\"Running executeAction()\");\n\n    for (String mf : Core.getMicroflowNames()) {\n        LOG.debug(\"Microflow: \" + mf);\n    }\n    return true;\n    \/\/ END USER CODE\n}\n<\/pre>\n<p>When we execute the Java action, we see the following on the Mendix console.<\/p>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"373\" src=\"https:\/\/www.robertprice.co.uk\/robblog\/assets\/mendixconsole-1024x373.png\" alt=\"\" class=\"wp-image-2646\" srcset=\"https:\/\/www.robertprice.co.uk\/robblog\/assets\/mendixconsole-1024x373.png 1024w, https:\/\/www.robertprice.co.uk\/robblog\/assets\/mendixconsole-300x109.png 300w, https:\/\/www.robertprice.co.uk\/robblog\/assets\/mendixconsole-768x280.png 768w, https:\/\/www.robertprice.co.uk\/robblog\/assets\/mendixconsole-1200x437.png 1200w, https:\/\/www.robertprice.co.uk\/robblog\/assets\/mendixconsole.png 1258w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>How to add logging to a Mendix Java action. <\/p>\n","protected":false},"author":1,"featured_media":2646,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[98],"class_list":["post-2645","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev","tag-mendix"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Logging from a Mendix Java action - Robert Price<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Logging from a Mendix Java action - Robert Price\" \/>\n<meta property=\"og:description\" content=\"How to add logging to a Mendix Java action.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-09T08:19:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-05-09T08:19:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/assets\/mendixconsole.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1258\" \/>\n\t<meta property=\"og:image:height\" content=\"458\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"rob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/logging-from-a-mendix-java-action\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/logging-from-a-mendix-java-action\\\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"Logging from a Mendix Java action\",\"datePublished\":\"2019-05-09T08:19:12+00:00\",\"dateModified\":\"2019-05-09T08:19:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/logging-from-a-mendix-java-action\\\/\"},\"wordCount\":211,\"image\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/logging-from-a-mendix-java-action\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/assets\\\/mendixconsole.png\",\"keywords\":[\"Mendix\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/logging-from-a-mendix-java-action\\\/\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/logging-from-a-mendix-java-action\\\/\",\"name\":\"Logging from a Mendix Java action - Robert Price\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/logging-from-a-mendix-java-action\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/logging-from-a-mendix-java-action\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/assets\\\/mendixconsole.png\",\"datePublished\":\"2019-05-09T08:19:12+00:00\",\"dateModified\":\"2019-05-09T08:19:14+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/logging-from-a-mendix-java-action\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/logging-from-a-mendix-java-action\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/logging-from-a-mendix-java-action\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/assets\\\/mendixconsole.png\",\"contentUrl\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/assets\\\/mendixconsole.png\",\"width\":1258,\"height\":458},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/logging-from-a-mendix-java-action\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Logging from a Mendix Java action\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\",\"name\":\"Robert Price\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\",\"name\":\"rob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"caption\":\"rob\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Logging from a Mendix Java action - Robert Price","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/","og_locale":"en_GB","og_type":"article","og_title":"Logging from a Mendix Java action - Robert Price","og_description":"How to add logging to a Mendix Java action.","og_url":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/","og_site_name":"Robert Price","article_published_time":"2019-05-09T08:19:12+00:00","article_modified_time":"2019-05-09T08:19:14+00:00","og_image":[{"width":1258,"height":458,"url":"https:\/\/www.robertprice.co.uk\/robblog\/assets\/mendixconsole.png","type":"image\/png"}],"author":"rob","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rob","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/#article","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/"},"author":{"name":"rob","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"Logging from a Mendix Java action","datePublished":"2019-05-09T08:19:12+00:00","dateModified":"2019-05-09T08:19:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/"},"wordCount":211,"image":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/#primaryimage"},"thumbnailUrl":"https:\/\/www.robertprice.co.uk\/robblog\/assets\/mendixconsole.png","keywords":["Mendix"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/","url":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/","name":"Logging from a Mendix Java action - Robert Price","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/#primaryimage"},"image":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/#primaryimage"},"thumbnailUrl":"https:\/\/www.robertprice.co.uk\/robblog\/assets\/mendixconsole.png","datePublished":"2019-05-09T08:19:12+00:00","dateModified":"2019-05-09T08:19:14+00:00","author":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"breadcrumb":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/#primaryimage","url":"https:\/\/www.robertprice.co.uk\/robblog\/assets\/mendixconsole.png","contentUrl":"https:\/\/www.robertprice.co.uk\/robblog\/assets\/mendixconsole.png","width":1258,"height":458},{"@type":"BreadcrumbList","@id":"https:\/\/www.robertprice.co.uk\/robblog\/logging-from-a-mendix-java-action\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"Logging from a Mendix Java action"}]},{"@type":"WebSite","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website","url":"https:\/\/www.robertprice.co.uk\/robblog\/","name":"Robert Price","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5","name":"rob","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","caption":"rob"}}]}},"_links":{"self":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/2645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/comments?post=2645"}],"version-history":[{"count":2,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/2645\/revisions"}],"predecessor-version":[{"id":2648,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/2645\/revisions\/2648"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media\/2646"}],"wp:attachment":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=2645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=2645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=2645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}