# Add country region in logs

**URL:** <https://www.ruby-forum.com/t/add-country-region-in-logs/236354>\
**Category:** NGINX\
**Created:** [August 28, 2013, 8:04pm UTC](https://www.ruby-forum.com/t/add-country-region-in-logs/236354 "2013-08-28T20:04:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [August 28, 2013, 8:04pm UTC](https://www.ruby-forum.com/t/add-country-region-in-logs/236354/1 "2013-08-28T20:04:20Z")

</div>

Hello nginx!

Iam trying to identify all my visitors based on their continent region,  
i want to log this info in each log entry. There is no geoip database  
for continent region so I want to map manually the countries within  
their regions.

I already have the GeoIP db loaded, and an example map for a region as  
follows:

map $geoip\_country\_code $north\_africa {  
default “”;  
##Northern Africa  
DZ 1; #“Algeria”  
EG 1; #“Egypt”  
EH 1; #“Western Sahara”  
LY 1; #“Libyan Arab Jamahiriya”  
MA 1; #“Morocco”  
SD 1; #“Sudan”  
TN 1; #“Tunisia”  
}

Would anybody kindly offer me an example of how to generate a variable I  
can use in the logging that would print “NorthAfica” if one of the  
countries in the map matched?

Thanks  
Alex

---

<div class="post-metadata">

**Author:** ![Alex\_Flex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@Alex\_Flex](https://www.ruby-forum.com/u/Alex_Flex)\
**Post date:** [August 29, 2013, 2:30am UTC](https://www.ruby-forum.com/t/add-country-region-in-logs/236354/2 "2013-08-29T02:30:04Z")

</div>

On Wed, Aug 28, 2013 at 12:03:48PM -0600, Alex Flex wrote:

Hi there,

I haven’t tested this, but…

> I already have the GeoIP db loaded, and an example map for a region as  
> follows:
> 
> map $geoip\_country\_code $north\_africa {  
> default “”;  
> ##Northern Africa  
> DZ 1; #“Algeria”

> **[Module ngx\_http\_map\_module](http://nginx.org/en/docs/http/ngx_http_map_module.html#map)**
>
> The ngx\_http\_map\_module module creates variables whose values depend on values of other variables.

The “value” does not have to just be “1”. It could be, for example,  
“NorthAfrica”.

> Would anybody kindly offer me an example of how to generate a variable I  
> can use in the logging that would print “NorthAfica” if one of the  
> countries in the map matched?

$north\_africa.

But it might make more sense to call it $continent\_region, and let it  
take values for the whole world.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
