Using alt key code in logstash

Hi all, i am using logstash to write some data into txt file so that my output configuration of logstash is as following:

output {
csv {
fields => ["My_Data"]
path => "D:\app_%{year}_%{mounth}_%{day}.txt"
}
  stdout { codec => rubydebug }

}

it is note that "My_Data" is as following which is based on the some other data:

mutate {
	add_field => {
		"My_Data" => "%{Com}-%{Ser}-%{year}-%{mounth}-%{day}-%{count}"
	}
}

I am using "-" (dash) in order to separate the items. But, our customer tells us that the separator should be "alt0173" which leads to "-". How can i use "alt0173" instead of direct "-" in my script so that convert to dash in output txt?
Any advise will be so appreciated.
Regards

sorry. i think it has been solved just by using alt0173 in script

For reference, in Unicode, this would be U+00AD, although I doubt that the input would be in any Unicode encoding.

You're likely going to want to set the charset in your csv input to match your input file. Eg:

input{
    file{
        ...
        codec => csv{ charset=>"Windows-1250" }
    }
}

Unfortunately Logstash (still) doesn't have a mechanism for expressing Unicode escape sequences in its configuration, but the configuration file is meant to be UTF-8, so you can (as you've experienced) put literal Unicode characters into it.

Many thanks for your reply,
I used ­alt0173 in csv output fields and when open the output on my PC with Notepad++ it works fine and can find alt0173 (-). But when i open this file on another PC, it cannot find alt0173. Any advise will be so appreciated.

I checked out put in Notepad++ using Encode in ANSI which is as following:

O1ÂO2­2020­06­23­O3­4­0

where there is  instead of "-" (alt0173)

when i check my config file in notepad++ using Encoding in ANSI , Â exists in output filed:

when i delete Â, starting logstash face with following error:

`> [ERROR][logstash.agent           ] An exception happened when converging configuration 
{:exception=>RuntimeError, :message=>"Could not fetch the configuration, message: The 
following config files contains non-ascii characters but are not UTF-8 encoded 
 [\"F:/ELK_Windows/logstash-6.6.0/logstash-6.6.0/bin/OB13.conf\"]", :backtrace=>["F:/ELK_Windows/logstash-6.6.0/logstash-6.6.0/logstash-core/lib/logstash/agent.rb:157:in `converge_state_and_update'", "F:/ELK_Windows/logstash-6.6.0/logstash-6.6.0/logstash-core/lib/logstash/agent.rb:101:in `execute'", "F:/ELK_Windows/logstash-6.6.0/logstash-6.6.0/logstash-core/lib/logstash/runner.rb:362:in `block in execute'", "F:/ELK_Windows/logstash-6.6.0/logstash-6.6.0/vendor/bundle/jruby/2.3.0/gems/stud-0.0.23/lib/stud/task.rb:24:in `block in initialize'"]}`

That's to be expected; the configuration file is expected to be in UTF-8. Nothing else will do. Logstash can process other encodings, but its configuration file must be UTF-8.

On Windows, you can use the Character Map application (if you can't type the character yourself). You'll want a Unicode font, such as Arial, tick the Advanced box, and in the 'Go to Unicode' box, enter 00AD. You'll find two things:

  • Unicode calls this character 'Soft Hyphen'
  • It also shows the Windows Alt-Keypad keystroke sequence (Alt+0173)

You can click on the Select the character for the 'Characters to copy' if you want to just copy it into your logstash configuration.

Hope that helps.

Many thanks for your reply. I type alt0173 for output field in the logstash config as fields separator, but the problem is in the output txt. txt file separator has been shown as "Â-" instead of "-". my config file is creating a txt file daily which includes some data separated using alt0173. customer is using ANSI encoding and they are seeing output separator as "Â-" instead of "-". how can i handle this issue so that output txt file separator automatically shows alt0173 (-) instead of (Â-).

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.