17

I have a putty log file that contains color markup, e.g.:

[0m[33mSome colored error text
[35mSome more colored error text
[0mSome stuff

Is there a way to easily view these log files in color? Bonus points for solutions that:

  • Use notepad++
  • Don't display the color sequence (e.g. [35m) , and instead just colors the text
1

3 Answers 3

5

You can install MINGW64 (Cygwin should also works) and run:

less -R your_putty_logfile.log

Notice -R option. For me it works pretty fine.

1
  • 1
    Can't believe this actually worked in Windows 11 cmd with cygwin installed.
    – Bob Stein
    Aug 11, 2021 at 14:11
3

Recently, someone created a Python script by which to enable ASCII color coding in NotePad++.

https://github.com/notepad-plus-plus/notepad-plus-plus/issues/8078

The actual script is at: https://github.com/Ekopalypse/NppPythonScripts/blob/master/npp/error_list_lexer_support.py

And for easier use, I've copied it below:

# -*- coding: utf-8 -*-
'''
    Makes the builtin errorlist lexer available for npp.
    
    To toggle the escape characters on/off one can
    create another script with these two lines of code.
    
    error_list_lexer.show_escape_chars = not error_list_lexer.show_escape_chars
    editor.styleSetVisible(error_list_lexer.SCE_ERR_ESCSEQ, error_list_lexer.show_escape_chars)
'''

from Npp import notepad, editor, NOTIFICATION


class ErrorListLexer:

    def __init__(self):
        '''
            Initialize the class, should be called only once.
        '''

        # **************** configuration area ****************
        # files with these extensions and a null lexer,
        # aka normal text, assigned do get handled
        self.known_extensions = ['log', 'txt']
        #
        self.show_escape_chars = False
        self.separate_path_and_line_number = '0'
        self.interpret_escape_sequences = '1'
        # ****************************************************
        
        self.SCE_ERR_DEFAULT =0
        self.SCE_ERR_PYTHON =1
        self.SCE_ERR_GCC =2
        self.SCE_ERR_MS =3
        self.SCE_ERR_CMD =4
        self.SCE_ERR_BORLAND =5
        self.SCE_ERR_PERL =6
        self.SCE_ERR_NET =7
        self.SCE_ERR_LUA =8
        self.SCE_ERR_CTAG =9
        self.SCE_ERR_DIFF_CHANGED = 10
        self.SCE_ERR_DIFF_ADDITION = 11
        self.SCE_ERR_DIFF_DELETION = 12
        self.SCE_ERR_DIFF_MESSAGE = 13
        self.SCE_ERR_PHP = 14
        self.SCE_ERR_ELF = 15
        self.SCE_ERR_IFC = 16
        self.SCE_ERR_IFORT = 17
        self.SCE_ERR_ABSF = 18
        self.SCE_ERR_TIDY = 19
        self.SCE_ERR_JAVA_STACK = 20
        self.SCE_ERR_VALUE = 21
        self.SCE_ERR_GCC_INCLUDED_FROM = 22
        self.SCE_ERR_ESCSEQ = 23
        self.SCE_ERR_ESCSEQ_UNKNOWN = 24
        self.SCE_ERR_ES_BLACK = 40
        self.SCE_ERR_ES_RED = 41
        self.SCE_ERR_ES_GREEN = 42
        self.SCE_ERR_ES_BROWN = 43
        self.SCE_ERR_ES_BLUE = 44
        self.SCE_ERR_ES_MAGENTA = 45
        self.SCE_ERR_ES_CYAN = 46
        self.SCE_ERR_ES_GRAY = 47
        self.SCE_ERR_ES_DARK_GRAY = 48
        self.SCE_ERR_ES_BRIGHT_RED = 49
        self.SCE_ERR_ES_BRIGHT_GREEN = 50
        self.SCE_ERR_ES_YELLOW = 51
        self.SCE_ERR_ES_BRIGHT_BLUE = 52
        self.SCE_ERR_ES_BRIGHT_MAGENTA = 53
        self.SCE_ERR_ES_BRIGHT_CYAN = 54
        self.SCE_ERR_ES_WHITE = 55

        notepad.callback(self.on_langchanged, [NOTIFICATION.LANGCHANGED])
        notepad.callback(self.on_bufferactivated, [NOTIFICATION.BUFFERACTIVATED])


    def init_lexer(self):
        '''
            Initializes the lexer and its properties
            Args:
                None
            Returns:
                None
        '''
        editor.styleSetFore(self.SCE_ERR_DEFAULT, notepad.getEditorDefaultForegroundColor())
        editor.styleSetFore(self.SCE_ERR_PYTHON, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_GCC, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_MS, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_CMD, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_BORLAND, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_PERL, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_NET, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_LUA, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_CTAG, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_DIFF_CHANGED, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_DIFF_ADDITION, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_DIFF_DELETION, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_DIFF_MESSAGE, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_PHP, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_ELF, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_IFC, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_IFORT, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_ABSF, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_TIDY, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_JAVA_STACK, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_VALUE, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_GCC_INCLUDED_FROM, (255,0,0))

        editor.styleSetFore(self.SCE_ERR_ESCSEQ, (30,30,30))
        editor.styleSetVisible(self.SCE_ERR_ESCSEQ, self.show_escape_chars)
        editor.styleSetFore(self.SCE_ERR_ESCSEQ_UNKNOWN, (255,255,120))
        editor.styleSetVisible(self.SCE_ERR_ESCSEQ_UNKNOWN, self.show_escape_chars)

        editor.styleSetFore(self.SCE_ERR_ES_BLACK, (0,0,0))
        editor.styleSetFore(self.SCE_ERR_ES_RED, (255,0,0))
        editor.styleSetFore(self.SCE_ERR_ES_GREEN, (0,255,0))
        editor.styleSetFore(self.SCE_ERR_ES_BROWN, (150,75,0))
        editor.styleSetFore(self.SCE_ERR_ES_BLUE, (0,0,255))
        editor.styleSetFore(self.SCE_ERR_ES_MAGENTA, (255,200,255))
        editor.styleSetFore(self.SCE_ERR_ES_CYAN, (255,200,100))
        editor.styleSetFore(self.SCE_ERR_ES_GRAY, (128,128,128))
        editor.styleSetFore(self.SCE_ERR_ES_DARK_GRAY, (255,200,100))
        editor.styleSetFore(self.SCE_ERR_ES_BRIGHT_RED, (170, 1, 20))
        editor.styleSetFore(self.SCE_ERR_ES_BRIGHT_GREEN, (255,200,100))
        editor.styleSetFore(self.SCE_ERR_ES_YELLOW, (255,255,0))
        editor.styleSetFore(self.SCE_ERR_ES_BRIGHT_BLUE, (9,84,190))
        editor.styleSetFore(self.SCE_ERR_ES_BRIGHT_MAGENTA, (229,8,194))
        editor.styleSetFore(self.SCE_ERR_ES_BRIGHT_CYAN, (27,244,207))
        editor.styleSetFore(self.SCE_ERR_ES_WHITE, (255,255,255))

        editor.setLexer(10)
        # ordering is important
        editor.setProperty('lexer.errorlist.value.separate', self.separate_path_and_line_number)
        editor.setProperty('lexer.errorlist.escape.sequences', self.interpret_escape_sequences)


    def check_lexers(self):
        '''
            Checks if the current document is of interest.
            Args:
                None
            Returns:
                None
        '''

        has_no_lexer_assigned = editor.getLexerLanguage() == 'null'
        _, _, file_extension = notepad.getCurrentFilename().rpartition('.')
        if has_no_lexer_assigned and file_extension in self.known_extensions:
            self.init_lexer()


    def on_bufferactivated(self, args):
        '''
            Callback which gets called every time one switches a document.
            Triggers the check if the document is of interest.
            Args:
                provided by notepad object but none are of interest
            Returns:
                None
        '''
        self.check_lexers()


    def on_langchanged(self, args):
        '''
            Callback gets called every time one uses the Language menu to set a lexer
            Triggers the check if the document is of interest
            Args:
                provided by notepad object but none are of interest
            Returns:
                None
        '''
        self.check_lexers()


    def main(self):
        '''
            Main function entry point.
            Simulates the buffer_activated event to enforce 
            detection of current document and potential styling.
            Args:
                None
            Returns:
                None
        '''
        self.on_bufferactivated(None)


error_list_lexer = ErrorListLexer()
error_list_lexer.main()
1

You can replay the log file in TeraTerm. File -> New Connection -> TCPI/IP: /R="C:\somelofile.log"

B.T.W In TeraTerm you can log escape commands when log to binary file format.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .