You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by kvineeth <vi...@gmail.com> on 2008/03/15 14:22:19 UTC

suggest a makefile

Hi  
 
I have a code which i need to compile on a linux machine. 
here is the code 
#include "Category.hh" 
#include "FileAppender.hh" 
#include "BasicLayout.hh" 
 
int main(int argc, char* argv[]) 
{ 
// 1 instantiate an appender object that  
// will append to a log file 
log4cpp::Appender* app = new  
log4cpp::FileAppender("FileAppender", 
"/logs/testlog4cpp.log"); 
 
// 2. Instantiate a layout object 
// Two layouts come already available in log4cpp 
// unless you create your own. 
// BasicLayout includes a time stamp 
log4cpp::Layout* layout =  
new log4cpp::BasicLayout(); 
 
// 3. attach the layout object to the  
// appender object 
app->setLayout(layout); 
 
// 4. Instantiate the category object 
// you may extract the root category, but it is 
// usually more practical to directly instance 
// a child category 
log4cpp::Category main_cat =  
log4cpp::Category::getInstance("main_cat"); 
 
 
 
// 5. Step 1  
// an Appender when added to a category becomes 
// an additional output destination unless  
// Additivity is set to false when it is false, 
// the appender added to the category replaces 
// all previously existing appenders 
main_cat.setAdditivity(false); 
 
// 5. Step 2 
// this appender becomes the only one 
main_cat.setAppender(app); 
 
// 6. Set up the priority for the category 
// and is given INFO priority 
// attempts to log DEBUG messages will fail 
main_cat.setPriority(log4cpp::Priority::INFO); 
 
// so we log some examples 
main_cat.info("This is some info"); 
main_cat.debug("This debug message will  
fail to write"); 
main_cat.alert("All hands abandon ship"); 
 
// you can log by using a log() method with  
// a priority 
main_cat.log(log4cpp::Priority::WARN, "This will  
be a logged warning"); 
 
// gives you some programmatic control over  
// priority levels 
log4cpp::Priority::PriorityLevel priority; 
bool this_is_critical = true; 
if(this_is_critical) 
priority = log4cpp::Priority::CRIT; 
else 
priority = log4cpp::Priority::DEBUG; 
 
// this would not be logged if priority  
// == DEBUG, because the category priority is  
// set to INFO 
main_cat.log(priority,"Importance depends on  
context"); 
 
// You may also log by using stream style 
// operations on  
main_cat.critStream() << "This will show up  
<< as " << 1 << " critical message"  
<< log4cpp::CategoryStream::ENDLINE; 
main_cat.emergStream() << "This will show up as "  
<< 1 << " emergency message" <<  
log4cpp::CategoryStream::ENDLINE; 
 
// Stream operations can be used directly  
// with the main object, but are  
// preceded by the severity level 
main_cat << log4cpp::Priority::ERROR  
<< "And this will be an error"  
<< log4cpp::CategoryStream::ENDLINE; 
 
// This illustrates a small bug in version  
// 2.5 of log4cpp 
main_cat.debug("debug"); // this is correctly  
// skipped 
main_cat.info("info"); 
main_cat.notice("notice"); 
main_cat.warn("warn"); 
main_cat.error("error"); 
main_cat.crit("crit"); // this prints ALERT  
// main_cat : crit  
main_cat.alert("alert");// this prints PANIC  
// main_cat : alert 
main_cat.emerg("emerg");// this prints UNKOWN  
// main_cat : emerg 
 
 
main_cat.debug("Shutting down");// this will  
// be skipped 
 
// clean up and flush all appenders 
log4cpp::Category::shutdown(); 
return 0; 
} 
 
Can anybody suggest me what i need to give as an compilation option to
compile it properly. 
I tried it from command line this way 
@ubuntu:/home/users/vineeth/LOG4C++/log4cpp-1.0/vini$ g++ handle.cpp 
handle.cpp: In function âint main(int, char**)â: 
/usr/local/include/log4cpp/Category.hh:624: error:
âlog4cpp::Category::Category(const log4cpp::Category&)â is private 
handle.cpp:20: error: within this context 
handle.cpp:51: error: âENDLINEâ is not a member of âlog4cpp::CategoryStreamâ 
handle.cpp:52: error: âENDLINEâ is not a member of âlog4cpp::CategoryStreamâ 
handle.cpp:55: error: âENDLINEâ is not a member of âlog4cpp::CategoryStreamâ 
 
and it gave me the foll erros


 

-- 
View this message in context: http://www.nabble.com/suggest-a-makefile-tp16067610p16067610.html
Sent from the Log4cxx - Users mailing list archive at Nabble.com.


Re: suggest a makefile

Posted by Curt Arnold <ca...@apache.org>.
On Mar 15, 2008, at 8:22 AM, kvineeth wrote:
>
> Can anybody suggest me what i need to give as an compilation option to
> compile it properly.
> I tried it from command line this way
> @ubuntu:/home/users/vineeth/LOG4C++/log4cpp-1.0/vini$ g++ handle.cpp
> handle.cpp: In function âint main(int, char**)â:
> /usr/local/include/log4cpp/Category.hh:624: error:
> âlog4cpp::Category::Category(const log4cpp::Category&)â is private
> handle.cpp:20: error: within this context
> handle.cpp:51: error: âENDLINEâ is not a member of  
> âlog4cpp::CategoryStreamâ
> handle.cpp:52: error: âENDLINEâ is not a member of  
> âlog4cpp::CategoryStreamâ
> handle.cpp:55: error: âENDLINEâ is not a member of  
> âlog4cpp::CategoryStreamâ
>
> and it gave me the foll erros
>
>
>


This mailing list for for users of log4cxx, not log4cpp.  You may get  
better support on the right mailing list.

Re: suggest a makefile

Posted by Andreas Fester <af...@apache.org>.
Hi,

you seem to have a mixture between log4cxx and log4cpp:

/usr/local/include/log4cpp/Category.hh:624: error:
                  ^^^^^^^^^

The easiest solution might be to remove the liblog4cpp4/5-dev package.
Or, add "-I/path/to/log4cxx/include" as a compiler option.
A good starting point could also be the src/examples/cpp directory
of the log4cxx distribution.
Also note that Category is deprecated; use the Logger class instead
(well, as long as you still have the #include "Category.h" in your source code,
adding -I would not really help because the compiler still finds the include
file from log4cpp; thus, I would really recommend removing the log4cpp-dev
package at least until your log4cxx source compiles).

Best Regards,

	Andreas


kvineeth wrote:
> Hi  
>  
> I have a code which i need to compile on a linux machine. 
> here is the code 
> #include "Category.hh" 
> #include "FileAppender.hh" 
> #include "BasicLayout.hh" 
>  
[...]