Open log file in html

Logback HTMLLayout

Logback HTMLLayout outputs events in an HTML table. The content of the table columns is specified using a conversion pattern in the encoder property.

1. HTMLLayout Sample Configuration

For quick reference, this is the configuration file we will be referring. It logs into c:/temp/logs/applicationLogs.html file and rolls-over daily.

     %d [%thread] %-5level %logger - %msg%n   $/$.html  $/$-%d.%i.html.gz 10MB 30 100GB, it will delete old archived file --> 100GB  UTF-8 %d%thread%level%logger%line%msg         

Logback requires three modules in the application runtime i.e. logback-core, logback-classic and slf4j-api.

 ch.qos.logback logback-core 1.2.10  ch.qos.logback logback-classic 1.2.10  org.slf4j slf4j-api 1.7.32 

Note that logback-classic will automatically pull in the logback-core and slf4j-api, so adding logback-classic dependency is enough.

3.1. Default Conversion Pattern

By default, the HTMLLayout uses the following conversion pattern.

%date%thread%level%logger%mdc%msg

It creates a table containing the following data:

  • Date – Log event date time.
  • Thread – Thread name.
  • Level – Log level.
  • Logger – Logger name.
  • MDC – MDC (Mapped Diagnostic Context) information, if available.
  • Message – Log message.

We can customize the columns and information using the custom pattern in the encoder property.

It seems that Logback does not support the extensive table formatting as supported by Log4j2 HTMLLayout.

We are using the custom pattern for demo purpose. We have removed MDC info, rather we are printing the line number in the classes.

%d%thread%level%logger%line%msg

Let’s quickly write a few log statements, and see the output.

import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.howtodoinjava.demo.lombok.Article; public class Main < public static void main(final String[] args) < Logger logger = LoggerFactory.getLogger(Main.class); logger.debug("Debug Message Logged . "); logger.info("Info Message Logged . "); logger.error("Error Message Logged . ", new NullPointerException("Something is NULL")); Article a = Article.builder(1L).title("Test Article").tag("Data").build(); logger.info("Article fecthed for id : <>is : <>", 1, a); > >

Open the Log output file in the browser.

In this logback HTML Layout tutorial, we learned to create logs in HTML files with rolling capabilities. These HTML formatted logs can be helpful in generating nice-looking reports for sending the logs in the emails with SMTPAppender.

But if logs are being generated in very high amounts then we should be logging plain string logs, use specialized tools (such as Splunk) for log processing.

Источник

How to View CodeIgniter Log Files in the Browser

How to View CodeIgniter Log Files in the Browser

How to View CodeIgniter Log Files in the Browser

Just like any other page, it is now possible to read CodeIgniter log files in the browser. My Sweet Goodness!

d-k2Dfg0rgazIaeVdTY2NdzxgYN-2nUJxiQJ

I began using CodeIgniter in my day to day coding after joining an awesome company. The company’s tech stack includes the PHP Framework — among others. Hitherto now, I’ve used (and still use) Laravel to build some awesome apps.

Laravel has a great logging system that is simple and elegant. Furthermore, there’s a library for showing the logs in the browser. Being able to read the logs in the browser is good for application debugging and insight. Especially in a production environment.

Читайте также:  Create website with css and html

So here I am in the world of CodeIgniter and couldn’t find an equivalent library to read my logs for debugging and insight.

So I took up the challenge and created my first Open Source project of the year — codeigniter-log-viewer.

Usage

First, let’s add it to a dependency. We can do that by executing:

composer require seunmatt/codeigniter-log-viewer

Then, we can create a CodeIgniter application controller, LogViewerController.php:

public function __construct() < $this->logViewer = new \CILogViewer\CILogViewer(); //. >
public function index() < echo $this->logViewer->showLogs(); return;>

What we did is to instantiate $logViewer in the constructor and then echo the result of showLogs() in the index() function.

The showLogs() method of codeigniter-log-viewer will parse the content of the log files in application/logs . It will return it for display on the browser.

Finally, we can map any route of our choice to the index() we created above. This can be done by adding an entry to the $route array in application/config/routes.php:

$route['logs'] = "logViewerController/index";

Now we can visit /logs on the browser and see all the log files there. It’s also possible to delete and download the log files.

Note: It is advisable to use a protected route in production environment to avoid general public access.

How it works

Internally, the library read the name of all the log files that are available in the default logs directory into an array and reverse it. If no file is specified in the URL query parameters, the latest log file is processed for display by default.

Processing of a log file for display involves reading its contents, using regex to determine the log level and the CSS class and icon of each entry.

Each entry is also checked to know if it’s a new log line or a continuation of the previous line (due to a newline character).

Finally, the log entries are processed into HTML content that is then sent to the browser for display.

The complete source code is available on Github if you want to play around with it or/and adapt it for use in other frameworks.

Conclusion

Now it’s easier and faster to debug CodeIgniter application — even in production. Spread the word around to friends and colleagues at work.

I want to hear about your experience (and opinions) of using the library in the comment section. Thanks!

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

PyLog2html can log to a html file. There is plenty of reasons that we need a html log: colored file, marked file, readable.

License

trelay/PyLog2html

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Читайте также:  Php declare class abstract

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Support both Python2 and Python3

PyLog2Html can save log to HTML file, there is plenty of reasons to save log into HTML file:

pip install PyLog2html or pip3 install PyLog2html 
from HTMLLogger import HTMLLogger logger=HTMLLogger(name="Test App", html_filename="log.html", console_log=True) logger.info('This is info') logger.debug('This is debug') logger.warning("This is warning") logger.error('This is an error') logger.table('Add html table:
.
'
)

Optional Text

  • Open log file «log.html» in browser, it takes a while to open the log file, it depends on the performance of your computer.
  • Select a level name to dedicate on particular messages.
  • Or type a keyword to find your interesting message(select checkbox to mismatch case)
  • If you set console_log to True when you’ll see the log would also print to console
  • [HTMLFileHandler]: The derived class of Python logging.handlers.RotatingFileHandler
  • [HTMLFormatter]: The derived class of Python logging.Formatter
  • [CONFormatter]: The derived class of Python logging.Formatter

The sub class of logging.handlers.RotatingFileHandler, you can see this class is to extend the function of Rotating HTML file, comparing to its parent class, it has following advantages:

  • The format of log file name will be saved as «log_1.html» & «log_2.html».
  • Write the beginning and end strings in HTML, like «.«
  • Have a switch to let user choose if need to rotate files: If it’s False, the log file will be added and rollover occurs whenever the current log file is nearly maxBytes in length. If it’s True, it behaves like logging.handlers.RotatingFileHandler.

The sub class of logging.Formatter, you can see this class is to add HTML tags, comparing to its parent class, it has following advantages:

  • Highlight keyword by setting its size and the Italic
  • Find the correct color to display for particular messages in Html file.
  • The keyword should be decorated by keyword(which can be found in config file or variables you defined.)

The sub class of logging.Formatter, this module is to print log to console with color if console_log was set to True when you instance class PyLogger and raise errors if the color you chose is not supported by Console.

Currently, Only following color are supported in Console:

The main logger creator, the sub class of logging.Logger, use to instance a single logging channel. By default, you should use this class rather than use logging.Logger. If you’d like to create a logger with the specified name, you should call function and add HTMLFormatter and HTMLFileHandler using addFilter and addHandler.

You have two options here:

  • Use oslo.config _ , and read variables from the config file
  • Set Variables in your script.
from HTMLLogger import HTMLLogger app_name="Red_Fish" Keyword_Italic=True Keyword_FontSize=5 HighLight_msg_tag_start="" HighLight_msg_tag_end="" msg_color=dict( err_color="magenta", warn_color="orange", info_color="white", dbg_color="white") log_format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s' HtmlmaxBytes=1024*1024*5 console_log=True html_title="Default Title" html_filename="Redfish_log.html" logger=PyLogger(name=app_name, html_filename=html_filename, mode='a', html_title=html_title,level=logging.DEBUG, HtmlmaxBytes=HtmlmaxBytes, encoding=None, delay=False, html_format=log_format, msg_color=msg_color, Keyword_Italic=Keyword_Italic,Keyword_FontSize=Keyword_FontSize, HighLight_msg_tag_start=HighLight_msg_tag_start, HighLight_msg_tag_end=HighLight_msg_tag_end,console_log=console_log, Html_Rotating=False,Html_backupCount=5) logger.debug('This is debug') logger.info('This is info') logger.warning("This is warning") logger.error('This is error xxx') logger.table('Add html table:
.
'
)

Free Software, Hell Yeah!

.. (Contact trelwan@celestica.com if you have any questions.)

About

PyLog2html can log to a html file. There is plenty of reasons that we need a html log: colored file, marked file, readable.

Источник

PyLog2html 1.0.4

PyLog2Html can save log to HTML file, there is plenty of reasons to save log into HTML file:

Installation

Quick Start

View the log:

  • Open log file “log.html” in browser, it takes a while to open the log file, it depends on the performance of your computer.
  • Select a level name to dedicate on particular messages.
  • Or type a keyword to find your interesting message(select checkbox to mismatch case)
  • If you set console_log to True when you’ll see the log would also print to console

Version

Class Inheritance:

  • [HTMLFileHandler]: The derived class of Python logging.handlers.RotatingFileHandler
  • [HTMLFormatter]: The derived class of Python logging.Formatter
  • [CONFormatter]: The derived class of Python logging.Formatter

HTMLFileHandler

The sub class of logging.handlers.RotatingFileHandler, you can see this class is to extend the function of Rotating HTML file, comparing to its parent class, it has following advantages:

  • The format of log file name will be saved as “log_1.html” & “log_2.html”.
  • Write the beginning and end strings in HTML, like “…”
  • Have a switch to let user choose if need to rotate files: If it’s False, the log file will be added and rollover occurs whenever the current log file is nearly maxBytes in length. If it’s True, it behaves like logging.handlers.RotatingFileHandler.

HTMLFormatter

The sub class of logging.Formatter, you can see this class is to add HTML tags, comparing to its parent class, it has following advantages:

  • Highlight keyword by setting its size and the Italic
  • Find the correct color to display for particular messages in Html file.
  • The keyword should be decorated by keyword(which can be found in config file or variables you defined.)

CONFormatter

The sub class of logging.Formatter, this module is to print log to console with color if console_log was set to True when you instance class PyLogger and raise errors if the color you chose is not supported by Console.

Currently, Only following color are supported in Console:

HTMLLogger

The main logger creator, the sub class of logging.Logger, use to instance a single logging channel. By default, you should use this class rather than use logging.Logger. If you’d like to create a logger with the specified name, you should call function and add HTMLFormatter and HTMLFileHandler using addFilter and addHandler.

The config

You have two options here:

warning"error xxx'. 'Free Software, Hell Yeah!

Источник

Оцените статью