Skip to main content
johnrellis
Legend
September 15, 2025

P: SDK: LrLogger adds extra "\r" to logged new lines on Windows

  • September 15, 2025
  • 3 replies
  • 159 views

LrLogger adds an extra "\r" to each "\r\n" contained in logged strings on Windows. Tested on LR 14.5.1.

 

1. Save the attached file "logger-bug.txt" to the LR Scripts folder.  That script contains:

logger = import "LrLogger" ("MyLog")
logger:enable ("logfile")
logger:info ("line 1\r\nline 2\r\n")

 

2. Restart LR and execute the script.

 

3. Observe that %LOCALAPPDATA%\Adobe\Lightroom\Logs\LrClassicLogs\MyLog.log contains "line 1\r\r\nline 2\r\r\n" (incorrect) instead of "line 1\r\nline 2\r\n":

$ od -c MyLog.log 
0000000    0   9   /   2   3   /   2   0   2   5       1   6   :   4   9
0000020    :   4   4       I   N   F   O  \t   l   i   n   e       1  \r
0000040   \r  \n   l   i   n   e       2  \r  \r  \n  \0  \r  \n        

 

3 replies

Inspiring
September 25, 2025

Great that you figured out that is was in the LrLogs and not in the LrFileUtils module.

Rikk Flohr_Photography
Community Manager
September 24, 2025

Thanks @johnrellis  I will get this logged with the team.

Rikk Flohr: Adobe Photography Org
Inspiring
September 15, 2025

While reading a log file from a Python program I noticed that LrFileUtils.readFile adds "CR" character for every new line "CRLF" in Windows. 

In the sample script below I compare "LrFileUtils.readFile" with "io"

 

Is this normal or is this a bug?

 

File contents

line 1
line 2
line 3

 

To reproduce I use this small script

local LrDialogs         = import "LrDialogs"
local LrFunctionContext = import "LrFunctionContext"
local LrFileUtils       = import "LrFileUtils"

local JSON              = require "JSON"
local inspect           = require "inspect"

local logFilename       = 'TestReadFile'
local myLogger          = import 'LrLogger' (logFilename)
myLogger:enable("logfile")

local filePath = "D:/Temp/file.txt"

local function readJsonFile(path)
    local content
    local file = io.open(path, "r")

    if file then
        content = file:read("*all")
        file:close()
    else
        myLogger:info("Error opening file.")
    end

    return content
end

local function writeFile(content)
    local file = io.open(filePath, "w")
    if file then
        file:write(content)
        file:close()
        myLogger:info("String written to file successfully.")
    else
        myLogger:info("Error opening file.")
    end
end

local function main(context)
    local text = "line 1\nline 2\nline 3\n"
    writeFile(text)

    -- Open file file LrFileUtils.readFile( path )
    local contents = LrFileUtils.readFile(filePath)
    myLogger:info("File contents from LrFileUtils.readFile", contents)

    contents = readJsonFile(filePath)
    myLogger:info("File contents from io", contents)
end

LrFunctionContext.postAsyncTaskWithContext("Start culling", function(context)
    LrDialogs.attachErrorDialogToFunctionContext(context)
    main(context)
end)

In Windows using Notepad++ this is how the file look like:

File.txt

Lightroom logger file

 

johnrellis
Legend
September 23, 2025