Overview
Features
Download
Documentation
Community
Add-Ons & Services

Logger in embedded Linux - CortexA8

Please post support and help requests here.
buettner
Posts: 5
Joined: 18 Jun 2013, 10:23

Logger in embedded Linux - CortexA8

Postby buettner » 18 Jun 2013, 10:28

Hi,

i try to use the Logger Framework like this:

Code: Select all

    Poco::FormattingChannel *pFCFile = new Poco::FormattingChannel(new Poco::PatternFormatter("%Y-%m-%d %H:%M:%S.%c %N[%P]:%s: %q:%t"));
    pFCFile->setChannel(new Poco::FileChannel("test.log"));
    pFCFile->open();
    pLogger = &(Poco::Logger::create("FileLogger", pFCFile, Poco::Message::PRIO_INFORMATION));


I Crosscompile it with a gcc for the ARM CortexA8.
When i run the App i get in the first line allready:
*** glibc detected *** tests: malloc(): memory corruption: 0x0002bd00 ***

Is the Logger usable with this device?

Christian

guenter
Posts: 1178
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Logger in embedded Linux - CortexA8

Postby guenter » 18 Jun 2013, 13:03

The logger should also work on the A8 (of course).
The code looks good at a first glance, so there must be something else wrong with your application.
If you'd post a more complete example we might be able to help you.

buettner
Posts: 5
Joined: 18 Jun 2013, 10:23

Re: Logger in embedded Linux - CortexA8

Postby buettner » 18 Jun 2013, 13:12

Ok thank you..

Here is a bit more code:

The Header: File_HAL.h

Code: Select all

#ifndef FILE_HAL_H
#define FILE_HAL_H

#include "HAL_BUS_Abstraction.h"

class HAL_Entry_API File_HAL : public HAL_BUS_Abstraction {
public:
    File_HAL(void);
    ~File_HAL(void);
    virtual uint8_t Interface_Init();
    virtual void Interface_DeInit();

protected:
    uint8_t IsFrameAvailable();
    uint8_t WriteRead(uint8_t address,int16_t nWriteBytes, uint8_t *WriteData, int16_t nReadBytes,uint8_t *ReadData, int16_t Stop);
private:
};

#endif //FILE_HAL_H



The CPP: File_HAL.cpp


Code: Select all

#include "File_HAL.h"
#include "Poco/Exception.h"
#include "Poco/FileStream.h"

#include "Poco/FileChannel.h"
#include "Poco/FormattingChannel.h"
#include "Poco/Logger.h"
#include "Poco/Message.h"
#include "Poco/PatternFormatter.h"

using Poco::FileChannel;
using Poco::FormattingChannel;
using Poco::Logger;
using Poco::Message;
using Poco::PatternFormatter;

static Poco::Logger *pLogger;

File_HAL::File_HAL(void) {
}


File_HAL::~File_HAL(void) {
}


uint8_t File_HAL::Interface_Init() {
    printf("File_HAL Interface_Init\n");

    Poco::FormattingChannel *pFCFile = new Poco::FormattingChannel(new Poco::PatternFormatter("%Y-%m-%d %H:%M:%S.%c %N[%P]:%s: %q:%t"));
    pFCFile->setChannel(new Poco::FileChannel("test.log"));
    pFCFile->open();
    pLogger = &(Poco::Logger::create("FileLogger", pFCFile, Poco::Message::PRIO_INFORMATION));


    //call init of super class
    HAL_BUS_Abstraction::Interface_Init();

    return 1;
}

uint8_t File_HAL::IsFrameAvailable() {
    //return always 1 -> no data come back
    return 0;
}


uint8_t File_HAL::WriteRead(uint8_t address,int16_t nWriteBytes, uint8_t *WriteData, int16_t nReadBytes,uint8_t *ReadData, int16_t Stop) {
    int16_t nBytes = nWriteBytes + nReadBytes;
    uint8_t* outBuffer = new uint8_t[nBytes];
    uint8_t* inBuffer = new uint8_t[nBytes];
    uint8_t result = 0;

    memset(outBuffer,0,sizeof(outBuffer));
    memset(inBuffer,0,sizeof(inBuffer));
    memcpy(outBuffer, WriteData, nWriteBytes);

    // exchange data to interface - set result

    delete [] outBuffer;
    outBuffer = NULL;
    delete [] inBuffer;
    inBuffer = NULL;

    return result;
}

void File_HAL::Interface_DeInit() {
    HAL_BUS_Abstraction::Interface_DeInit();
}


Calling code is this:

Code: Select all

File_HAL* halEntry = new File_HAL();
halEntry->Interface_Init();
...

guenter
Posts: 1178
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Logger in embedded Linux - CortexA8

Postby guenter » 20 Jun 2013, 21:48

Not really sure what's the reason for your heap corruption, but generally, when using the logging framework, you should use it the following way:

In each class that needs a logger, add a reference member that's initialized in the constructor:

Code: Select all

class Sample
{
public:
    Sample():
        _logger(Poco::Logger::get("Sample"))
    {
    }

    void doSomething()
    {
        _logger.information("Doing something");
    }

private:
    ...
    Poco::Logger& _logger;
};


Generally, channels should be set up independent of the classes using the Loggers, preferrably using the configuration facilities of the Poco::Util::[Server]Application class, using the Poco::Util::LoggingConfigurator class, or by doing it "manually". In any case, Poco::Logger::create() should normally not be called, except maybe during application startup, if you know what you're doing. See these slides for more information.


Return to “Support”

Who is online

Users browsing this forum: No registered users and 2 guests

cron