diff options
author | Ariel Constenla-Haile <arielch@apache.org> | 2012-10-15 03:36:40 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-05-28 09:14:15 +0100 |
commit | 7e7e4c7a38764283ea334187fae4e21bd7d4f478 (patch) | |
tree | f1b33b52de5a859647cb524a99c6649817b4e59c | |
parent | 898a3e84807bccbb876e3f5583728f6d24e05e9a (diff) |
Resolves: #i121216# Allow unique logger file name
(cherry picked from commit a9606aa4d8a6bcb3955d991ee45c56cb93be2450)
Conflicts:
officecfg/registry/schema/org/openoffice/Office/Logging.xcs
Change-Id: I25719f2898df2f91ef9c71234e9eab83f8140b96
-rw-r--r-- | extensions/source/logging/loggerconfig.cxx | 43 | ||||
-rw-r--r-- | officecfg/registry/schema/org/openoffice/Office/Logging.xcs | 18 |
2 files changed, 57 insertions, 4 deletions
diff --git a/extensions/source/logging/loggerconfig.cxx b/extensions/source/logging/loggerconfig.cxx index af0fac9efa03..dae01ef2f96c 100644 --- a/extensions/source/logging/loggerconfig.cxx +++ b/extensions/source/logging/loggerconfig.cxx @@ -19,6 +19,7 @@ #include "loggerconfig.hxx" +#include <stdio.h> #include <com/sun/star/configuration/theDefaultProvider.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> @@ -33,6 +34,8 @@ #include <com/sun/star/logging/XLogFormatter.hpp> #include <tools/diagnose_ex.h> +#include <osl/process.h> +#include <rtl/ustrbuf.hxx> #include <comphelper/componentcontext.hxx> @@ -97,9 +100,47 @@ namespace logging try { sLoggerName = _rxLogger->getName(); } catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); } + TimeValue aTimeValue; + oslDateTime aDateTime; + OSL_VERIFY( osl_getSystemTime( &aTimeValue ) ); + OSL_VERIFY( osl_getDateTimeFromTimeValue( &aTimeValue, &aDateTime ) ); + + char buffer[ 30 ]; + const size_t buffer_size = sizeof( buffer ); + + snprintf( buffer, buffer_size, "%04i-%02i-%02i", + (int)aDateTime.Year, + (int)aDateTime.Month, + (int)aDateTime.Day ); + rtl::OUString sDate = rtl::OUString::createFromAscii( buffer ); + + snprintf( buffer, buffer_size, "%02i-%02i-%02i.%03i", + (int)aDateTime.Hours, + (int)aDateTime.Minutes, + (int)aDateTime.Seconds, + ::sal::static_int_cast< sal_Int16 >( aDateTime.NanoSeconds / 10000000 ) ); + rtl::OUString sTime = rtl::OUString::createFromAscii( buffer ); + + rtl::OUStringBuffer aBuff; + aBuff.append( sDate ); + aBuff.append( sal_Unicode( '.' ) ); + aBuff.append( sTime ); + rtl::OUString sDateTime = aBuff.makeStringAndClear(); + + oslProcessIdentifier aProcessId = 0; + oslProcessInfo info; + info.Size = sizeof (oslProcessInfo); + if ( osl_getProcessInfo ( 0, osl_Process_IDENTIFIER, &info ) == osl_Process_E_None) + aProcessId = info.Ident; + rtl::OUString aPID = rtl::OUString::valueOf( sal_Int64( aProcessId ) ); + Variable aVariables[] = { - Variable( RTL_CONSTASCII_USTRINGPARAM( "$(loggername)" ), sLoggerName ) + Variable( RTL_CONSTASCII_USTRINGPARAM( "$(loggername)" ), sLoggerName ), + Variable( RTL_CONSTASCII_USTRINGPARAM( "$(date)" ), sDate ), + Variable( RTL_CONSTASCII_USTRINGPARAM( "$(time)" ), sTime ), + Variable( RTL_CONSTASCII_USTRINGPARAM( "$(datetime)" ), sDateTime ), + Variable( RTL_CONSTASCII_USTRINGPARAM( "$(pid)" ), aPID ) }; for ( size_t i = 0; i < SAL_N_ELEMENTS( aVariables ); ++i ) diff --git a/officecfg/registry/schema/org/openoffice/Office/Logging.xcs b/officecfg/registry/schema/org/openoffice/Office/Logging.xcs index 2679d1f5eb94..580135909f80 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Logging.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Logging.xcs @@ -46,9 +46,21 @@ </info> <prop oor:name="FileURL" oor:type="xs:string" oor:nillable="false"> <info> - <desc>Specifies the file URL for the log handler. The default value here will expand to a file - with the same name as the logger for which the handler is used, with extension ".log". - It will be located in the user's OOo data folder.</desc> + <desc>Specifies the file URL for the log handler. + This URL will be resolved using the + ::com::sun::star::util::PathSubstitution service. That is, it is + allowed to include placeholders supported by that service, + such as $(userurl). Beside these, the following default + placeholders can also be included: + $(loggername) - the name of the logger + $(date) - the current date + $(time) - the current time + $(datetime) - the current date time + $(pid) - the process identifier + The default value here will expand to a file with the same name + as the logger for which the handler is used, with extension ".log". + It will be located in the user's OOo data folder. + </desc> </info> <value>$(userurl)/$(loggername).log</value> </prop> |