drupal 8

Similar to drupal 7, Drupal 8 also provide the logging functionality but little different to use it because the drupal 8 is symphony base architecture, so can use the logger service of drupal 8 to reload your logs on dblog

For Notice type:

<?php

\Drupal::logger('module_name')->notice($message_string);

?>

For Error Type:

<?php

\Drupal::logger('module_name')->error($message_string);

?>

But, If you want to print a array or object using logger, you can use following code also -

\Drupal::logger('module_name')->notice('<pre><code>' . print_r($array, TRUE) . '</code></pre>' );

Note- please use this logger in class function to avoid any further error - see example below:

<?php
/**
 * @file
 * Contains \Drupal\module_name\Controller\FirstController.
 */
 
namespace Drupal\module_name\Controller;
 
use Drupal\Core\Controller\ControllerBase;
 
class FirstController extends ControllerBase {
  public function content() {
     $array_to_print = array(
      'abc' => 'markup',
      'cdg' => 134654,
    );

    \Drupal::logger('module_name')->notice('<pre><code>' . print_r($array_to_print, TRUE) . '</code></pre>'    );

    return array(
      '#type' => 'markup',
      '#markup' => t('This is test example'),
    );
  }
}


Please Comment your thoughts and feedback below and add something if you found good in anywhere to help others

Hit a like Button If you like the Post.

Many Thanks

Comments

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Other Articles

Getting permission error when installing CiviCRM under Drupal with Xampp

If you are getting permission error while installing CiviCRM on xampp then, its is default CiviCRM user permission error,

Drupal Country code default array

include_once DRUPAL_ROOT . '/includes/locale.inc'; country_get_list();  

Import Database using xampp mysql command prompt windows

As we all know the xampp is most popular tool at machine level programming work, but sometime we need to deal with the bigger databases to import into mysql of xampp that provide and we import that

Install Apache Solr on Ubuntu

Install Apache Solr 7.7 on Ubuntu 18.04 & 16.04 LTS This tutorials explains how to install solr 7 on ubuntu system 1) Install or Check Java

Recursively delete all files of a specific extension

Usually we all use "rm" command to delete or remove the files and folder on linux, but if we want to delete the specific type of content/files then we can use "find" command to find and "delete" co

page templates for content types in Drupal 8

If you know how to make a content type template in drupal 7 then you can easily understand in drupal 8, Here there is not much change except that the template is in twig format. 

Flexslider Arrows Changed by arrow Images

Flexslider uses the arrows of its own flexslider family icons, if you want to change or replace with yours images you can do using following css.  

Convert a certificate into the cer,crt,der,pem format

For different reason we need the different format of certificates for different operating system, many of sites offering you to convert the certificates in different format online but if you have b

Embed Google maps on website (Static address )

Here using this website  we can get the embed the static map on our website.

Import Mysql database using SSH

Follow these steps to Import the database Mysql (Putty Terminal). 1. Login to your putty terminal. 2.You need to login in to Mysql, for this type

Center the div vertically and horizontally using css

hey, below you can find the simple example of centering a div vertically and horizontally using css

Export Mysql database using SSH

Export The database directly from command line is Easy and Fast. Follow these steps to export the database using SSH (putty terminal)

WAI-ARIA Roles

See Details Here https://www.drupal.org/node/1179668

How to create the directories and sub directories in one command linux

Many times we are want to create multiple directories and sub-directories under it and usually we do cd and mkdir one by one, it is very time consuming and it sometimes slow down our workflow.

Scroll to top button with html and jquery

Are you searching to add a button scroll to top, then this article is for you.

Render menu on page template in custom way Drupal 8

If you want to render the menu items in custom way in page or node twig template of drupal 8 then this article is for you :  

Update Drupal 8 core manually

This is small tutorial to how to update the Drupal 8 core manually using shell or FTP, Let start -

Slice array Elements using Keys PHP

Many Helpful Function are available to exact the specific set of keys of an array $sliced-arr = array_slice($new_tags, 0, 6);

Prevent to Load a js file on particular page using hook_js_alter Drupal 7

Drupal provided the lots of hook to extents its functionality, using this we can prevent a js file to load on particular page using HOOK_JS_ALTER

Import and Export Drupal 8 Views, Or Import and Export any configuration Drupal 8

Import and Export configuration is the basic protocol to staging the website or production website deployment, In Drupal 7, we need the extra modules to import and export or we can use features mod

check if a string contains a specific word with PHP

In PHP sometimes we need to find the specific word in the string for the programitically use the code, there is a function called "

Render block and views block drupal 7 programmatically

This is article is for Drupal 7 to render block in templates and custom blocks using php codes Actually there is very simple ways to render block pro-grammatically 

Recent Posts

Create a Flag link programmatically and render flag link in twig template drupal 8

This article is refer to generate the flag link programmatically and render in drupal 8 twig template, before in drupal 7 its was quiet easy to render or generate flag link in just a single line of

Jquery prevent enter to submit form

If you want to prevent the form submit using jquery, then this page helps you to doing this.

Code:

Play Pause HTML5 Video using Jquery

HTML5 video playing on any web page is very easy, in this tutorial we can show you how to add video on html and make it play and pause without using html controls.

Import and Export Drupal 8 Views, Or Import and Export any configuration Drupal 8

Import and Export configuration is the basic protocol to staging the website or production website deployment, In Drupal 7, we need the extra modules to import and export or we can use features mod

How to override different version of Jquery in Drupal 8 using theme

Drupal 8 use its own jquery version by default and if you want to use the other version of jQuery instead of default than this tutorials steps is for you, sometimes we need different version to oth

Subscribe to Mailchimp programmatically via api with PHP

In this tutorial we can see how to subscribe to the mailchimp subscribe list using php programmatically via api,

For this you need a mailchimp account, api key and list id 

How you can get Mailchimp API KEY

By Follow steps below, you can find the api key or create the api key at mailchimp and use it to your website to connected the site with mailchimp to collect the subscribe in fastest way.

How to get your MailChimp LIST ID

Mailchimp is marketing automation platform and is provide email for marketing your product or business whatever you like, today its most trusted service providing all over the globe.

Drupal 8 add custom menu classes to using menu.html.twig

In Drupal 8 Twig templates give extra power to drupal to add dynamic content in twig style, In this tutorial we can see how we can add the custom menu classes to menu ul li using menu.html.twig.

How to create the directories and sub directories in one command linux

Many times we are want to create multiple directories and sub-directories under it and usually we do cd and mkdir one by one, it is very time consuming and it sometimes slow down our workflow.

Create Node drupal 8 programmatically with image upload using custom module

As we know drupal 8 use symphony, so module structure of drupal 8 is change and workflow functionality of doing thing also change.