6 Replies Latest reply on Jul 24, 2013 1:38 AM by davealot

    How to output full image path to logger/console

    davealot

      Hi All

       

      I'm just starting to get my hands dirty with the lr sdk and could do with a little guidance.

       

      For part of a plugin I need to retrieve the full path to each image, and although I can achieve what I want I'm struggling to print the path to the console/logger and can't understand why.

       

      Here's a snippit of code to illustrate things:

       

      for photo in exportSession:photosToExport() do 
      
           filename = photo:getFormattedMetadata( "fileName" )
           outputToLog( filename )  -- Works as expected
           folderName = photo:getFormattedMetadata( "folderName" ) 
           outputToLog( folderName )  -- Works as expected
      
      
           local path = LrPathUtils.standardizePath(photo:getRawMetadata("path"))
           outputToLog( path ) -- Output is always blank
      
      
           -- and yet when passed to exiftool the path is correct and works as expected
      
           LrTasks.execute("exiftool  -Copyright=\"Imaginary person\" \""..path.."\"")
      
      
      
      end
      

       

      Basically I can get the path and use it as part of an exiftool command, but can't work out how to output the path to the log/console for debugging purposes. Am I missing something simple or is this an intentional limitation?

       

      Any help much appreciated.

        • 1. Re: How to output full image path to logger/console
          areohbee Level 5

          It would help if you posted outputToLog code too, but the problem could be due to backslashes if windoes environment - sometimes you need to double-'em up.

          • 2. Re: How to output full image path to logger/console
            davealot Level 1

            Here is the outputToLog code:

            local myLogger = LrLogger( 'libraryLogger' )

             

            function outputToLog( message )

              myLogger:trace( message )

            end

             

            Do I need to format the output using logger:tracef( format, ... ) instead?

             

            If it makes any difference I'm working in an OSX environment.

            • 3. Re: How to output full image path to logger/console
              areohbee Level 5

              I don't know what the problem is. What device are you outputting to?

               

              i.e. did you try logger:enable( "logfile" ) -- that works for me in OSX to log to a file.

               

              Here is the code I use:

               

              self.logger = LrLogger( logName )

              local function logToFile( msg )

                  local f = io.open ( self.logFilePath, "a" )

                  if f == nil then

                      Debug.pause( "can't open log file", self.logFilePath )

                      return

                  end

                  f:write ( LrDate.timeToUserFormat( LrDate.currentTime(), "%Y-%m-%d %H:%M:%S"), " ", msg, '\n' )

                  f:close ()

              end

              if self.verbose then

                  --self.logger:enable( 'logfile' ) -- enable everything to log file.

                  self.logger:enable( logToFile )

              else

                  local actions = {

                      -- debug output is suppressed when not logging verbosely

                      trace = logToFile,

                      info = logToFile,

                      warn = logToFile,

                      error = logToFile,

                      fatal = logToFile,

                  }

                  self.logger:enable( actions ) -- suppress trace & debug.

              end

               

              R

              • 4. Re: How to output full image path to logger/console
                johnrellis Most Valuable Participant

                Dave,

                 

                I can't add anything more specific than Rob has already said.  But you might look at my Debugging Toolkit (free).  It takes a bit of time to learn and hook up at first (about 30 minutes), but it can really save you time going forward.

                1 person found this helpful
                • 5. Re: How to output full image path to logger/console
                  davealot Level 1

                  Rob,

                   

                  You were right, the problem only exists when I use logger:enable( "print" ) in combination with osx console to view the output. If I use logger:enable( "logfile" ) then the path shows up as expected.

                   

                  For others it might be worth noting that in a Windows 7 environment logger:enable( "print " ) works fine with windbg to view the ouput.

                   

                  Thanks for your help and the logToFile function.

                  Dave

                  • 6. Re: How to output full image path to logger/console
                    davealot Level 1

                    John, thanks for the toolkit link, I've been meaning to give it a go.